Skip to content

[PhpUnitBridge] deprecate the testLegacy test name prefix #21140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 6, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this check here, we already typehint the parameter

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type hint is for \PHPUnit_Framework_Test, but not \PHPUnit_Framework_TestCase.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

damn, you are right 👍

$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();

Expand All @@ -188,15 +201,21 @@ 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);
}
if (in_array('dns-sensitive', $groups, true)) {
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)
Expand Down