Skip to content

Commit

Permalink
Neither the @errorhandler annotation nor the setUseErrorHandler() met…
Browse files Browse the repository at this point in the history
…hod {are|were} documented. They also did not (not really, at least) work.

This commit removes support for the @errorhandler annotation and makes setUseErrorHandler() a no-op while deprecating it for removal in PHPUnit 9.
  • Loading branch information
sebastianbergmann committed Jun 21, 2019
1 parent 07a4e0b commit 3426cfd
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 59 deletions.
31 changes: 3 additions & 28 deletions src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ abstract class TestCase extends Assert implements SelfDescribing, Test
*/
private $dataName;

/**
* @var bool
*/
private $useErrorHandler;

/**
* @var null|string
*/
Expand Down Expand Up @@ -645,9 +640,11 @@ public function setRegisterMockObjectsFromTestArgumentsRecursively(bool $flag):
$this->registerMockObjectsFromTestArgumentsRecursively = $flag;
}

/**
* @deprecated Invoking this method has no effect; it will be removed in PHPUnit 9
*/
public function setUseErrorHandler(bool $useErrorHandler): void
{
$this->useErrorHandler = $useErrorHandler;
}

public function getStatus(): int
Expand Down Expand Up @@ -693,12 +690,6 @@ public function run(TestResult $result = null): TestResult

if (!$this instanceof WarningTestCase) {
$this->setTestResultObject($result);
$this->setUseErrorHandlerFromAnnotation();
}

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

if (!$this instanceof WarningTestCase &&
Expand Down Expand Up @@ -823,10 +814,6 @@ public function run(TestResult $result = null): TestResult
$result->run($this);
}

if (isset($oldErrorHandlerSetting)) {
$result->convertErrorsToExceptions($oldErrorHandlerSetting);
}

$this->result = null;

return $result;
Expand Down Expand Up @@ -1763,18 +1750,6 @@ private function setExpectedExceptionFromAnnotation(): void
}
}

private function setUseErrorHandlerFromAnnotation(): void
{
$useErrorHandler = TestUtil::getErrorHandlerSettings(
\get_class($this),
$this->name
);

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

/**
* @throws Warning
* @throws SkippedTestError
Expand Down
23 changes: 1 addition & 22 deletions src/Framework/TestResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@ final class TestResult implements Countable
*/
private $codeCoverage;

/**
* @var bool
*/
private $registerErrorHandler = true;

/**
* @var bool
*/
Expand Down Expand Up @@ -632,7 +627,7 @@ public function run(Test $test): void

$this->startTest($test);

if ($this->registerErrorHandler && ($this->convertDeprecationsToExceptions || $this->convertErrorsToExceptions || $this->convertNoticesToExceptions || $this->convertWarningsToExceptions)) {
if ($this->convertDeprecationsToExceptions || $this->convertErrorsToExceptions || $this->convertNoticesToExceptions || $this->convertWarningsToExceptions) {
$errorHandler = new ErrorHandler(
$this->convertDeprecationsToExceptions,
$this->convertErrorsToExceptions,
Expand Down Expand Up @@ -978,22 +973,6 @@ public function setCodeCoverage(CodeCoverage $codeCoverage): void
$this->codeCoverage = $codeCoverage;
}

/**
* Enables or disables the registration of PHPUnit's error handler.
*/
public function registerErrorHandler(bool $flag): void
{
$this->registerErrorHandler = $flag;
}

/**
* Returns whether PHPUnit's error handler is to be registered.
*/
public function getRegisterErrorHandler(): bool
{
return $this->registerErrorHandler;
}

/**
* Enables or disables the deprecation-to-exception conversion.
*/
Expand Down
9 changes: 0 additions & 9 deletions src/Util/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -699,15 +699,6 @@ public static function getDependencies(string $className, string $methodName): a
return \array_unique($dependencies);
}

public static function getErrorHandlerSettings(string $className, ?string $methodName): ?bool
{
return self::getBooleanAnnotationSetting(
$className,
$methodName,
'errorHandler'
);
}

public static function getGroups(string $className, ?string $methodName = ''): array
{
$annotations = self::parseTestMethodAnnotations(
Expand Down

0 comments on commit 3426cfd

Please sign in to comment.