Skip to content

Commit

Permalink
- Merge [4618] and [4619].
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Feb 10, 2009
1 parent 36b06f3 commit 8ce569d
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 1 deletion.
49 changes: 49 additions & 0 deletions PHPUnit/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ abstract class PHPUnit_Framework_TestCase extends PHPUnit_Framework_Assert imple
*/
protected $dataName = '';

/**
* @var boolean
*/
protected $useErrorHandler = NULL;

/**
* @var boolean
*/
Expand Down Expand Up @@ -400,6 +405,40 @@ protected function setExpectedExceptionFromAnnotation()
}
}

/**
* @param boolean $useErrorHandler
* @since Method available since Release 3.4.0
*/
public function setUseErrorHandler($useErrorHandler)
{
$this->useErrorHandler = $useErrorHandler;
}

/**
* @since Method available since Release 3.4.0
*/
protected function setUseErrorHandlerFromAnnotation()
{
try {
$className = get_class($this);
$class = new ReflectionClass($className);
$classDocComment = $class->getDocComment();
$method = new ReflectionMethod($className, $this->name);
$methodDocComment = $method->getDocComment();

$useErrorHandler = PHPUnit_Util_Test::getErrorHandlerSettings(
$classDocComment, $methodDocComment
);

if ($useErrorHandler !== NULL) {
$this->setUseErrorHandler($useErrorHandler);
}
}

catch (ReflectionException $e) {
}
}

/**
* @param boolean $useOutputBuffering
* @since Method available since Release 3.4.0
Expand Down Expand Up @@ -485,8 +524,14 @@ public function run(PHPUnit_Framework_TestResult $result = NULL)
}

$this->setExpectedExceptionFromAnnotation();
$this->setUseErrorHandlerFromAnnotation();
$this->setUseOutputBufferingFromAnnotation();

if ($this->useErrorHandler !== NULL) {
$oldErrorHandlerSetting = $result->getConvertErrorsToExceptions();
$result->convertErrorsToExceptions($this->useErrorHandler);
}

$this->result = $result;

if ($this->runTestInSeparateProcess === TRUE &&
Expand Down Expand Up @@ -575,6 +620,10 @@ public function run(PHPUnit_Framework_TestResult $result = NULL)
$result->run($this);
}

if ($this->useErrorHandler !== NULL) {
$result->convertErrorsToExceptions($oldErrorHandlerSetting);
}

$this->result = NULL;

return $result;
Expand Down
11 changes: 11 additions & 0 deletions PHPUnit/Framework/TestResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,17 @@ public function convertErrorsToExceptions($flag)
}
}

/**
* Returns the error-to-exception conversion setting.
*
* @return boolean
* @since Method available since Release 3.4.0
*/
public function getConvertErrorsToExceptions()
{
return $this->convertErrorsToExceptions;
}

/**
* Enables or disables the stopping when a failure or error occurs.
*
Expand Down
7 changes: 7 additions & 0 deletions PHPUnit/Tests/Framework/TestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ public function testWrongException()
$this->assertEquals(1, count($result));
}

/**
* @backupGlobals enabled
*/
public function testGlobalsBackupPre()
{
global $a;
Expand Down Expand Up @@ -280,6 +283,10 @@ public function testGlobalsBackupPost()
$this->assertArrayNotHasKey('foo', $GLOBALS);
}

/**
* @backupGlobals enabled
* @backupStaticAttributes enabled
*/
public function testStaticAttributesBackupPre()
{
$GLOBALS['singleton'] = Singleton::getInstance();
Expand Down
4 changes: 3 additions & 1 deletion PHPUnit/Tests/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
syntaxCheck="false">
<php>
<var name="PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_ENABLED"
value="false"/>
Expand Down
16 changes: 16 additions & 0 deletions PHPUnit/Util/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class PHPUnit_Util_Test
const REGEX_COVERS = '/@covers[\s]+([\!<>\:\.\w]+)([\s]+<extended>)?/';
const REGEX_DATA_PROVIDER = '/@dataProvider\s+([a-zA-Z0-9._:-\\\]+)/';
const REGEX_DEPENDS = '/@depends\s+([a-zA-Z0-9._:-\\\]+)/';
const REGEX_USE_ERROR_HANDLER = '/@errorHandler\s+([a-zA-Z0-9._-]+)/';
const REGEX_EXPECTED_EXCEPTION = '(@expectedException\s+([:.\w\\\]+)(?:[\t ]+(\S*))?(?:[\t ]+(\S*))?\s*$)m';
const REGEX_GROUP = '/@group\s+([a-zA-Z0-9._-]+)/';
const REGEX_USE_OUTPUT_BUFFERING = '/@outputBuffering\s+([a-zA-Z0-9._-]+)/';
Expand Down Expand Up @@ -333,6 +334,21 @@ public static function getBackupSettings($classDocComment, $methodDocComment)
);
}

/**
* Returns the error handler settings for a test.
*
* @param string $classDocComment
* @param string $methodDocComment
* @return boolean
* @since Method available since Release 3.4.0
*/
public static function getErrorHandlerSettings($classDocComment, $methodDocComment)
{
return self::getSettings(
$classDocComment, $methodDocComment, self::REGEX_USE_ERROR_HANDLER
);
}

/**
* Returns the output buffering settings for a test.
*
Expand Down

0 comments on commit 8ce569d

Please sign in to comment.