diff --git a/src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php b/src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php index 1420deab45b5d..18eb092b3f72d 100644 --- a/src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php +++ b/src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php @@ -28,6 +28,7 @@ class SymfonyTestsListener extends \PHPUnit_Framework_BaseTestListener private $expectedDeprecations = array(); private $gatheredDeprecations = array(); private $previousErrorHandler; + private $testsWithWarnings; /** * @param array $mockedNamespaces List of namespaces, indexed by mocked features (time-sensitive or dns-sensitive) @@ -75,6 +76,7 @@ public function __destruct() public function startTestSuite(\PHPUnit_Framework_TestSuite $suite) { $suiteName = $suite->getName(); + $this->testsWithWarnings = array(); if (-1 === $this->state) { echo "Testing $suiteName\n"; @@ -170,8 +172,19 @@ public function startTest(\PHPUnit_Framework_Test $test) } } + public function addWarning(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_Warning $e, $time) + { + if ($test instanceof \PHPUnit_Framework_TestCase) { + $this->testsWithWarnings[$test->getName()] = true; + } + } + public function endTest(\PHPUnit_Framework_Test $test, $time) { + $className = get_class($test); + $classGroups = \PHPUnit_Util_Test::getGroups($className); + $groups = \PHPUnit_Util_Test::getGroups($className, $test->getName(false)); + if ($this->expectedDeprecations) { restore_error_handler(); @@ -188,8 +201,6 @@ public function endTest(\PHPUnit_Framework_Test $test, $time) $this->previousErrorHandler = null; } if (-2 < $this->state && $test instanceof \PHPUnit_Framework_TestCase) { - $groups = \PHPUnit_Util_Test::getGroups(get_class($test), $test->getName(false)); - if (in_array('time-sensitive', $groups, true)) { ClockMock::withClockMock(false); } @@ -197,6 +208,14 @@ public function endTest(\PHPUnit_Framework_Test $test, $time) DnsMock::withMockedHosts(array()); } } + + if ($test instanceof \PHPUnit_Framework_TestCase && 0 === strpos($test->getName(), 'testLegacy') && !isset($this->testsWithWarnings[$test->getName()]) && !in_array('legacy', $groups, true)) { + $test->getTestResultObject()->addWarning($test, new \PHPUnit_Framework_Warning('Using the "testLegacy" prefix to mark tests as legacy is deprecated since version 3.3 and will be removed in 4.0. Use the "@group legacy" notation instead to add the test to the legacy group.'), $time); + } + + if ($test instanceof \PHPUnit_Framework_TestCase && strpos($className, '\Legacy') && !isset($this->testsWithWarnings[$test->getName()]) && !in_array('legacy', $classGroups, true)) { + $test->getTestResultObject()->addWarning($test, new \PHPUnit_Framework_Warning('Using the "Legacy" prefix to mark all tests of a class as legacy is deprecated since version 3.3 and will be removed in 4.0. Use the "@group legacy" notation instead to add the test to the legacy group.'), $time); + } } public function handleError($type, $msg, $file, $line, $context)