Skip to content

Commit d7d4bd7

Browse files
magikidfabpot
authored andcommitted
[Bridge] Corrects bug in test listener trait
1 parent b893a71 commit d7d4bd7

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ public function endTest($test, $time)
271271
$assertions = \count(self::$expectedDeprecations) + $test->getNumAssertions();
272272
if ($test->doesNotPerformAssertions() && $assertions > 0) {
273273
$test->getTestResultObject()->addFailure($test, new RiskyTestError(sprintf('This test is annotated with "@doesNotPerformAssertions", but performed %s assertions', $assertions)), $time);
274-
} elseif ($assertions === 0 && $test->getTestResultObject()->noneSkipped()) {
274+
} elseif ($assertions === 0 && !$test->doesNotPerformAssertions() && $test->getTestResultObject()->noneSkipped()) {
275275
$test->getTestResultObject()->addFailure($test, new RiskyTestError('This test did not perform any assertions'), $time);
276276
}
277277

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\PhpUnit\Tests\FailTests;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
16+
17+
/**
18+
* This class is deliberately suffixed with *TestRisky.php so that it is ignored
19+
* by PHPUnit. This test is designed to fail. See ../expectnotrisky.phpt.
20+
*/
21+
final class NoAssertionsTestNotRisky extends TestCase
22+
{
23+
use ExpectDeprecationTrait;
24+
25+
/**
26+
* Do not remove this test in the next major version.
27+
*/
28+
public function testOne()
29+
{
30+
$this->expectNotToPerformAssertions();
31+
}
32+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Test NoAssertionsTestNotRisky not risky test
3+
--SKIPIF--
4+
<?php if ('\\' === DIRECTORY_SEPARATOR && !extension_loaded('mbstring')) die('Skipping on Windows without mbstring');
5+
--FILE--
6+
<?php
7+
$test = realpath(__DIR__.'/FailTests/NoAssertionsTestNotRisky.php');
8+
passthru('php '.getenv('SYMFONY_SIMPLE_PHPUNIT_BIN_DIR').'/simple-phpunit.php --fail-on-risky --colors=never '.$test);
9+
?>
10+
--EXPECTF--
11+
PHPUnit %s
12+
13+
%ATesting Symfony\Bridge\PhpUnit\Tests\FailTests\NoAssertionsTestNotRisky
14+
. 1 / 1 (100%)
15+
16+
Time: %s, Memory: %s
17+
18+
OK (1 test, 0 assertions)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy