diff --git a/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php b/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php index c84ec1b66ddbd..0fc2f2d623358 100644 --- a/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php +++ b/src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php @@ -271,7 +271,7 @@ public function endTest($test, $time) $assertions = \count(self::$expectedDeprecations) + $test->getNumAssertions(); if ($test->doesNotPerformAssertions() && $assertions > 0) { $test->getTestResultObject()->addFailure($test, new RiskyTestError(sprintf('This test is annotated with "@doesNotPerformAssertions", but performed %s assertions', $assertions)), $time); - } elseif ($assertions === 0 && $test->getTestResultObject()->noneSkipped()) { + } elseif ($assertions === 0 && !$test->doesNotPerformAssertions() && $test->getTestResultObject()->noneSkipped()) { $test->getTestResultObject()->addFailure($test, new RiskyTestError('This test did not perform any assertions'), $time); } diff --git a/src/Symfony/Bridge/PhpUnit/Tests/FailTests/NoAssertionsTestNotRisky.php b/src/Symfony/Bridge/PhpUnit/Tests/FailTests/NoAssertionsTestNotRisky.php new file mode 100644 index 0000000000000..2c5832e4b55d7 --- /dev/null +++ b/src/Symfony/Bridge/PhpUnit/Tests/FailTests/NoAssertionsTestNotRisky.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\PhpUnit\Tests\FailTests; + +use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; + +/** + * This class is deliberately suffixed with *TestRisky.php so that it is ignored + * by PHPUnit. This test is designed to fail. See ../expectnotrisky.phpt. + */ +final class NoAssertionsTestNotRisky extends TestCase +{ + use ExpectDeprecationTrait; + + /** + * Do not remove this test in the next major version. + */ + public function testOne() + { + $this->expectNotToPerformAssertions(); + } +} diff --git a/src/Symfony/Bridge/PhpUnit/Tests/expectnotrisky.phpt b/src/Symfony/Bridge/PhpUnit/Tests/expectnotrisky.phpt new file mode 100644 index 0000000000000..2005adf2ec363 --- /dev/null +++ b/src/Symfony/Bridge/PhpUnit/Tests/expectnotrisky.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test NoAssertionsTestNotRisky not risky test +--SKIPIF-- + +--EXPECTF-- +PHPUnit %s + +%ATesting Symfony\Bridge\PhpUnit\Tests\FailTests\NoAssertionsTestNotRisky +. 1 / 1 (100%) + +Time: %s, Memory: %s + +OK (1 test, 0 assertions)