8000 deprecate the Legacy/testLegacy test name prefix · symfony/symfony@2448fbc · GitHub
[go: up one dir, main page]

Skip to content

Commit 2448fbc

Browse files
committed
deprecate the Legacy/testLegacy test name prefix
1 parent 1099f6b commit 2448fbc

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class SymfonyTestsListener extends \PHPUnit_Framework_BaseTestListener
2828
private $expectedDeprecations = array();
2929
private $gatheredDeprecations = array();
3030
private $previousErrorHandler;
31+
private $testsWithWarnings;
3132

3233
/**
3334
* @param array $mockedNamespaces List of namespaces, indexed by mocked features (time-sensitive or dns-sensitive)
@@ -75,6 +76,7 @@ public function __destruct()
7576
public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
7677
{
7778
$suiteName = $suite->getName();
79+
$this->testsWithWarnings = array();
7880

7981
if (-1 === $this->state) {
8082
echo "Testing $suiteName\n";
@@ -170,8 +172,19 @@ public function startTest(\PHPUnit_Framework_Test $test)
170172
}
171173
}
172174

175+
public function addWarning(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_Warning $e, $time)
176+
{
177+
if ($test instanceof \PHPUnit_Framework_TestCase) {
178+
$this->testsWithWarnings[$test->getName()] = true;
179+
}
180+
}
181+
173182
public function endTest(\PHPUnit_Framework_Test $test, $time)
174183
{
184+
$className = get_class($test);
185+
$classGroups = \PHPUnit_Util_Test::getGroups($className);
186+
$groups = \PHPUnit_Util_Test::getGroups($className, $test->getName(false));
187+
175188
if ($this->expectedDeprecations) {
176189
restore_error_handler();
177190

@@ -188,15 +201,21 @@ public function endTest(\PHPUnit_Framework_Test $test, $time)
188201
$this->previousErrorHandler = null;
189202
}
190203
if (-2 < $this->state && $test instanceof \PHPUnit_Framework_TestCase) {
191-
$groups = \PHPUnit_Util_Test::getGroups(get_class($test), $test->getName(false));
192-
193204
if (in_array('time-sensitive', $groups, true)) {
194205
ClockMock::withClockMock(false);
195206
}
196207
if (in_array('dns-sensitive', $groups, true)) {
197208
DnsMock::withMockedHosts(array());
198209
}
199210
}
211+
212+
if ($test instanceof \PHPUnit_Framework_TestCase && 0 === strpos($test->getName(), 'testLegacy') && !isset($this->testsWithWarnings[$test->getName()]) && !in_array('legacy', $groups, true)) {
213+
$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);
214+
}
215+
216+
if ($test instanceof \PHPUnit_Framework_TestCase && strpos($className, '\Legacy') && !isset($this->testsWithWarnings[$test->getName()]) && !in_array('legacy', $classGroups, true)) {
217+
$test->getTestResultObject()->addWarning($test, ne 4E72 w \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);
218+
}
200219
}
201220

202221
public function handleError($type, $msg, $file, $line, $context)

0 commit comments

Comments
 (0)
0