Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 044cc8f

Browse files
committed
testing for deprecations is not risky
1 parent e7a9f03 commit 044cc8f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class SymfonyTestsListenerTrait
3838
private $gatheredDeprecations = array();
3939
private $previousErrorHandler;
4040
private $testsWithWarnings;
41+
private $reportUselessTests;
4142

4243
/**
4344
* @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)
172173
public function startTest($test)
173174
{
174175
if (-2 < $this->state && ($test instanceof \PHPUnit_Framework_TestCase || $test instanceof TestCase)) {
176+
if (null !== $test->getTestResultObject()) {
177+
$this->reportUselessTests = $test->getTestResultObject()->isStrictAboutTestsThatDoNotTestAnything();
178+
}
179+
175180
if (class_exists('PHPUnit_Util_Blacklist', false)) {
176181
$Test = 'PHPUnit_Util_Test';
177182
$AssertionFailedError = 'PHPUnit_Framework_AssertionFailedError';
@@ -197,7 +202,10 @@ public function startTest($test)
197202
if (isset($annotations['method']['expectedDeprecation'])) {
198203
if (!in_array('legacy', $groups, true)) {
199204
$test->getTestResultObject()->addError($test, new $AssertionFailedError('Only tests with the `@group legacy` annotation can have `@expectedDeprecation`.'), 0);
205+
} else {
206+
$test->getTestResultObject()->beStrictAboutTestsThatDoNotTestAnything(false);
200207
}
208+
201209
$this->expectedDeprecations = $annotations['method']['expectedDeprecation'];
202210
$this->previousErrorHandler = set_error_handler(array($this, 'handleError'));
203211
}
@@ -226,6 +234,11 @@ public function endTest($test, $time)
226234
$classGroups = $Test::getGroups($className);
227235
$groups = $Test::getGroups($className, $test->getName(false));
228236

237+
if (null !== $this->reportUselessTests) {
238+
$test->getTestResultObject()->beStrictAboutTestsThatDoNotTestAnything($this->reportUselessTests);
239+
$this->reportUselessTests = null;
240+
}
241+
229242
if ($this->expectedDeprecations) {
230243
restore_error_handler();
231244

0 commit comments

Comments
 (0)