Skip to content

Commit 79516d2

Browse files
Merge branch '13.1'
* 13.1: Fix crash when before-class or after-class method fails with assertion failure
2 parents 3b825eb + 27110b8 commit 79516d2

4 files changed

Lines changed: 108 additions & 0 deletions

File tree

src/Runner/TestResult/Collector.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,10 @@ public function testSuiteFinished(TestSuiteFinished $event): void
336336
assert($test instanceof TestMethod);
337337

338338
foreach ($this->testFailedEvents as $testFailedEvent) {
339+
if ($testFailedEvent instanceof AfterLastTestMethodFailed || $testFailedEvent instanceof BeforeFirstTestMethodFailed) {
340+
continue;
341+
}
342+
339343
if ($testFailedEvent->test()->isTestMethod() && $testFailedEvent->test()->methodName() === $test->methodName()) {
340344
return;
341345
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
https://github.com/sebastianbergmann/phpunit/issues/6595 (assertion failure in setUpBeforeClass with directory containing data provider test)
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = __DIR__ . '/6595';
8+
9+
require_once __DIR__ . '/../../bootstrap.php';
10+
11+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
12+
--EXPECTF--
13+
PHPUnit %s by Sebastian Bergmann and contributors.
14+
15+
Runtime: %s
16+
17+
...
18+
19+
Time: %s, Memory: %s
20+
21+
There were 3 failures:
22+
23+
1) PHPUnit\TestFixture\Issue6595\FailureInSetUpBeforeClassTest
24+
failure in setUpBeforeClass
25+
26+
%sFailureInSetUpBeforeClassTest.php:%d
27+
28+
2) PHPUnit\TestFixture\Issue6595\FailureInSetUpBeforeClassWithDataProviderTest
29+
failure in setUpBeforeClass
30+
31+
%sFailureInSetUpBeforeClassWithDataProviderTest.php:%d
32+
33+
3) PHPUnit\TestFixture\Issue6595\FailureInTearDownAfterClassTest
34+
failure in tearDownAfterClass
35+
36+
%sFailureInTearDownAfterClassTest.php:%d
37+
38+
FAILURES!
39+
Tests: 5, Assertions: 3, Failures: 3.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <sebastian@phpunit.de>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TestFixture\Issue6595;
11+
12+
use PHPUnit\Framework\Attributes\DataProvider;
13+
use PHPUnit\Framework\TestCase;
14+
15+
final class FailureInSetUpBeforeClassWithDataProviderTest extends TestCase
16+
{
17+
public static function provider(): array
18+
{
19+
return [
20+
[1],
21+
[2],
22+
];
23+
}
24+
25+
public static function setUpBeforeClass(): void
26+
{
27+
self::fail('failure in setUpBeforeClass');
28+
}
29+
30+
#[DataProvider('provider')]
31+
public function testOne(int $value): void
32+
{
33+
$this->assertGreaterThan(0, $value);
34+
}
35+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <sebastian@phpunit.de>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TestFixture\Issue6595;
11+
12+
use PHPUnit\Framework\Attributes\DataProvider;
13+
use PHPUnit\Framework\TestCase;
14+
15+
final class PassingWithDataProviderTest extends TestCase
16+
{
17+
public static function provider(): array
18+
{
19+
return [
20+
[1],
21+
[2],
22+
];
23+
}
24+
25+
#[DataProvider('provider')]
26+
public function testOne(int $value): void
27+
{
28+
$this->assertGreaterThan(0, $value);
29+
}
30+
}

0 commit comments

Comments
 (0)