feature #21786 [PhpUnitBridge] testing for deprecations is not risky (xabbuh)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[PhpUnitBridge] testing for deprecations is not risky

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Commits
-------

044cc8f14e testing for deprecations is not risky
This commit is contained in:
Fabien Potencier 2017-02-28 07:34:28 -08:00
commit 0f4bc14797

View File

@ -38,6 +38,7 @@ class SymfonyTestsListenerTrait
private $gatheredDeprecations = array();
private $previousErrorHandler;
private $testsWithWarnings;
private $reportUselessTests;
/**
* @param array $mockedNamespaces List of namespaces, indexed by mocked features (time-sensitive or dns-sensitive)
@ -172,6 +173,10 @@ class SymfonyTestsListenerTrait
public function startTest($test)
{
if (-2 < $this->state && ($test instanceof \PHPUnit_Framework_TestCase || $test instanceof TestCase)) {
if (null !== $test->getTestResultObject()) {
$this->reportUselessTests = $test->getTestResultObject()->isStrictAboutTestsThatDoNotTestAnything();
}
if (class_exists('PHPUnit_Util_Blacklist', false)) {
$Test = 'PHPUnit_Util_Test';
$AssertionFailedError = 'PHPUnit_Framework_AssertionFailedError';
@ -197,7 +202,10 @@ class SymfonyTestsListenerTrait
if (isset($annotations['method']['expectedDeprecation'])) {
if (!in_array('legacy', $groups, true)) {
$test->getTestResultObject()->addError($test, new $AssertionFailedError('Only tests with the `@group legacy` annotation can have `@expectedDeprecation`.'), 0);
} else {
$test->getTestResultObject()->beStrictAboutTestsThatDoNotTestAnything(false);
}
$this->expectedDeprecations = $annotations['method']['expectedDeprecation'];
$this->previousErrorHandler = set_error_handler(array($this, 'handleError'));
}
@ -226,6 +234,11 @@ class SymfonyTestsListenerTrait
$classGroups = $Test::getGroups($className);
$groups = $Test::getGroups($className, $test->getName(false));
if (null !== $this->reportUselessTests) {
$test->getTestResultObject()->beStrictAboutTestsThatDoNotTestAnything($this->reportUselessTests);
$this->reportUselessTests = null;
}
if ($this->expectedDeprecations) {
restore_error_handler();