Skip to content

Commit 98c4e50

Browse files
feature symfony#21140 [PhpUnitBridge] deprecate the testLegacy test name prefix (xabbuh)
This PR was merged into the 3.3-dev branch. Discussion ---------- [PhpUnitBridge] deprecate the testLegacy test name prefix | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | symfony#18755 | License | MIT | Doc PR | Commits ------- 21b72dd deprecate the Legacy/testLegacy test name prefix
2 parents 924469c + 21b72dd commit 98c4e50

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)
@@ -77,6 +78,7 @@ public function __destruct()
7778
public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
7879
{
7980
$suiteName = $suite->getName();
81+
$this->testsWithWarnings = array();
8082

8183
if (-1 === $this->state) {
8284
echo "Testing $suiteName\n";
@@ -172,8 +174,19 @@ public function startTest(\PHPUnit_Framework_Test $test)
172174
}
173175
}
174176

177+
public function addWarning(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_Warning $e, $time)
178+
{
179+
if ($test instanceof \PHPUnit_Framework_TestCase) {
180+
$this->testsWithWarnings[$test->getName()] = true;
181+
}
182+
}
183+
175184
public function endTest(\PHPUnit_Framework_Test $test, $time)
176185
{
186+
$className = get_class($test);
187+
$classGroups = \PHPUnit_Util_Test::getGroups($className);
188+
$groups = \PHPUnit_Util_Test::getGroups($className, $test->getName(false));
189+
177190
if ($this->expectedDeprecations) {
178191
restore_error_handler();
179192

@@ -190,15 +203,21 @@ public function endTest(\PHPUnit_Framework_Test $test, $time)
190203
$this->previousErrorHandler = null;
191204
}
192205
if (-2 < $this->state && $test instanceof \PHPUnit_Framework_TestCase) {
193-
$groups = \PHPUnit_Util_Test::getGroups(get_class($test), $test->getName(false));
194-
195206
if (in_array('time-sensitive', $groups, true)) {
196207
ClockMock::withClockMock(false);
197208
}
198209
if (in_array('dns-sensitive', $groups, true)) {
199210
DnsMock::withMockedHosts(array());
200211
}
201212
}
213+
214+
if ($test instanceof \PHPUnit_Framework_TestCase && 0 === strpos($test->getName(), 'testLegacy') && !isset($this->testsWithWarnings[$test->getName()]) && !in_array('legacy', $groups, true)) {
215+
$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);
216+
}
217+
218+
if ($test instanceof \PHPUnit_Framework_TestCase && strpos($className, '\Legacy') && !isset($this->testsWithWarnings[$test->getName()]) && !in_array('legacy', $classGroups, true)) {
219+
$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);
220+
}
202221
}
203222

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

0 commit comments

Comments
 (0)