Skip to content

Commit

Permalink
- Merge [4616].
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Feb 7, 2009
1 parent a9b34ca commit 36b06f3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 70 deletions.
2 changes: 1 addition & 1 deletion PHPUnit/Framework/TestCase.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ protected function setUseOutputBufferingFromAnnotation()
$method = new ReflectionMethod($className, $this->name); $method = new ReflectionMethod($className, $this->name);
$methodDocComment = $method->getDocComment(); $methodDocComment = $method->getDocComment();


$useOutputBuffering = PHPUnit_Util_Test::getOutputBuffering( $useOutputBuffering = PHPUnit_Util_Test::getOutputBufferingSettings(
$classDocComment, $methodDocComment $classDocComment, $methodDocComment
); );


Expand Down
112 changes: 43 additions & 69 deletions PHPUnit/Util/Test.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -197,65 +197,6 @@ public static function getLinesToBeCovered($className, $methodName)
return $result; return $result;
} }


/**
* Returns the backup settings for a test.
*
* @param string $classDocComment
* @param string $methodDocComment
* @return array
* @since Method available since Release 3.4.0
*/
public static function getBackupSettings($classDocComment, $methodDocComment)
{
$backupGlobals = NULL;
$backupStaticAttributes = NULL;

if (preg_match(self::REGEX_BACKUP_GLOBALS, $classDocComment, $matches)) {
if ($matches[1] == 'enabled') {
$backupGlobals = TRUE;
}

else if ($matches[1] == 'disabled') {
$backupGlobals = FALSE;
}
}

if (preg_match(self::REGEX_BACKUP_GLOBALS, $methodDocComment, $matches)) {
if ($matches[1] == 'enabled') {
$backupGlobals = TRUE;
}

else if ($matches[1] == 'disabled') {
$backupGlobals = FALSE;
}
}

if (preg_match(self::REGEX_BACKUP_STATIC_ATTRIBUTES, $classDocComment, $matches)) {
if ($matches[1] == 'enabled') {
$backupStaticAttributes = TRUE;
}

else if ($matches[1] == 'disabled') {
$backupStaticAttributes = FALSE;
}
}

if (preg_match(self::REGEX_BACKUP_STATIC_ATTRIBUTES, $methodDocComment, $matches)) {
if ($matches[1] == 'enabled') {
$backupStaticAttributes = TRUE;
}

else if ($matches[1] == 'disabled') {
$backupStaticAttributes = FALSE;
}
}

return array(
'backupGlobals' => $backupGlobals,
'backupStaticAttributes' => $backupStaticAttributes
);
}

/** /**
* Returns the dependencies for a test class or method. * Returns the dependencies for a test class or method.
* *
Expand Down Expand Up @@ -373,38 +314,71 @@ public static function getProvidedData($className, $methodName, $docComment)
} }


/** /**
* Returns the output buffering settings for a test. * Returns the backup settings for a test.
* *
* @param string $classDocComment * @param string $classDocComment
* @param string $methodDocComment * @param string $methodDocComment
* @return array * @return array
* @since Method available since Release 3.4.0 * @since Method available since Release 3.4.0
*/ */
public static function getOutputBuffering($classDocComment, $methodDocComment) public static function getBackupSettings($classDocComment, $methodDocComment)
{
return array(
'backupGlobals' => self::getSettings(
$classDocComment, $methodDocComment, self::REGEX_BACKUP_GLOBALS
),
'backupStaticAttributes' => self::getSettings(
$classDocComment, $methodDocComment, self::REGEX_BACKUP_STATIC_ATTRIBUTES
)
);
}

/**
* Returns the output buffering settings for a test.
*
* @param string $classDocComment
* @param string $methodDocComment
* @return boolean
* @since Method available since Release 3.4.0
*/
public static function getOutputBufferingSettings($classDocComment, $methodDocComment)
{ {
$outputBuffering = NULL; return self::getSettings(
$classDocComment, $methodDocComment, self::REGEX_USE_OUTPUT_BUFFERING
);
}


if (preg_match(self::REGEX_USE_OUTPUT_BUFFERING, $classDocComment, $matches)) { /**
* @param string $classDocComment
* @param string $methodDocComment
* @return boolean
* @since Method available since Release 3.4.0
*/
private static function getSettings($classDocComment, $methodDocComment, $regex)
{
$result = NULL;

if (preg_match($regex, $classDocComment, $matches)) {
if ($matches[1] == 'enabled') { if ($matches[1] == 'enabled') {
$outputBuffering = TRUE; $result = TRUE;
} }


else if ($matches[1] == 'disabled') { else if ($matches[1] == 'disabled') {
$outputBuffering = FALSE; $result = FALSE;
} }
} }


if (preg_match(self::REGEX_USE_OUTPUT_BUFFERING, $methodDocComment, $matches)) { if (preg_match($regex, $methodDocComment, $matches)) {
if ($matches[1] == 'enabled') { if ($matches[1] == 'enabled') {
$outputBuffering = TRUE; $result = TRUE;
} }


else if ($matches[1] == 'disabled') { else if ($matches[1] == 'disabled') {
$outputBuffering = FALSE; $result = FALSE;
} }
} }


return $outputBuffering; return $result;
} }


/** /**
Expand Down

0 comments on commit 36b06f3

Please sign in to comment.