Permalink
Browse files

- Merge [4618] and [4619].

  • Loading branch information...
1 parent 36b06f3 commit 8ce569df172b6b2e188f728a65b8b88efac426a2 @sebastianbergmann committed Feb 10, 2009
@@ -182,6 +182,11 @@
/**
* @var boolean
*/
+ protected $useErrorHandler = NULL;
+
+ /**
+ * @var boolean
+ */
protected $useOutputBuffering = NULL;
/**
@@ -401,6 +406,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
*/
@@ -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 &&
@@ -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;
@@ -750,6 +750,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.
*
* @param boolean $flag
@@ -218,6 +218,9 @@ public function testWrongException()
$this->assertEquals(1, count($result));
}
+ /**
+ * @backupGlobals enabled
+ */
public function testGlobalsBackupPre()
{
global $a;
@@ -280,6 +283,10 @@ public function testGlobalsBackupPost()
$this->assertArrayNotHasKey('foo', $GLOBALS);
}
+ /**
+ * @backupGlobals enabled
+ * @backupStaticAttributes enabled
+ */
public function testStaticAttributesBackupPre()
{
$GLOBALS['singleton'] = Singleton::getInstance();
@@ -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"/>
View
@@ -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._-]+)/';
@@ -334,6 +335,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.
*
* @param string $classDocComment

0 comments on commit 8ce569d

Please sign in to comment.