From 044cc8f14e09399c96f3bd29ced9edfcd0880772 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 27 Feb 2017 15:03:09 +0100 Subject: [PATCH] testing for deprecations is not risky --- .../PhpUnit/Legacy/SymfonyTestsListenerTrait.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php b/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php index 4d64fdc87fb74..f663f19eb6613 100644 --- a/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php +++ b/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php @@ -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 @@ public function addSkippedTest($test, \Exception $e, $time) 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 @@ public function startTest($test) 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 @@ public function endTest($test, $time) $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();