Skip to content

Commit 61037fc

Browse files
Closes #5561
1 parent 7fc1b6b commit 61037fc

File tree

5 files changed

+48
-4
lines changed

5 files changed

+48
-4
lines changed

ChangeLog-10.5.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ All notable changes of the PHPUnit 10.5 release series are documented in this fi
66

77
### Fixed
88

9+
* [#5561](https://github.com/sebastianbergmann/phpunit/issues/5561): JUnit XML logger does not handle assertion failures in before-test methods
910
* [#5567](https://github.com/sebastianbergmann/phpunit/issues/5567): Infinite recursion when recursive / self-referencing arrays are checked whether they contain only scalar values
1011

1112
## [10.5.1] - 2023-12-01

src/Logging/JUnit/JunitXmlLogger.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ final class JunitXmlLogger
8484
private ?DOMElement $currentTestCase = null;
8585
private ?HRTime $time = null;
8686
private bool $prepared = false;
87+
private bool $preparationFailed = false;
8788

8889
/**
8990
* @throws EventFacadeIsSealedException
@@ -186,7 +187,16 @@ public function testPreparationStarted(PreparationStarted $event): void
186187
* @throws InvalidArgumentException
187188
* @throws NoDataSetFromDataProviderException
188189
*/
189-
public function testPrepared(Prepared $event): void
190+
public function testPreparationFailed(): void
191+
{
192+
$this->preparationFailed = true;
193+
}
194+
195+
/**
196+
* @throws InvalidArgumentException
197+
* @throws NoDataSetFromDataProviderException
198+
*/
199+
public function testPrepared(): void
190200
{
191201
$this->prepared = true;
192202
}
@@ -196,6 +206,10 @@ public function testPrepared(Prepared $event): void
196206
*/
197207
public function testFinished(Finished $event): void
198208
{
209+
if ($this->preparationFailed) {
210+
return;
211+
}
212+
199213
$this->handleFinish($event->telemetryInfo(), $event->numberOfAssertionsPerformed());
200214
}
201215

@@ -283,6 +297,7 @@ private function registerSubscribers(Facade $facade): void
283297
new TestSuiteStartedSubscriber($this),
284298
new TestSuiteFinishedSubscriber($this),
285299
new TestPreparationStartedSubscriber($this),
300+
new TestPreparationFailedSubscriber($this),
286301
new TestPreparedSubscriber($this),
287302
new TestFinishedSubscriber($this),
288303
new TestErroredSubscriber($this),
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 <[email protected]>
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\Logging\JUnit;
11+
12+
use PHPUnit\Event\InvalidArgumentException;
13+
use PHPUnit\Event\Test\PreparationFailed;
14+
use PHPUnit\Event\Test\PreparationFailedSubscriber;
15+
use PHPUnit\Event\TestData\NoDataSetFromDataProviderException;
16+
17+
/**
18+
* @internal This class is not covered by the backward compatibility promise for PHPUnit
19+
*/
20+
final class TestPreparationFailedSubscriber extends Subscriber implements PreparationFailedSubscriber
21+
{
22+
/**
23+
* @throws InvalidArgumentException
24+
* @throws NoDataSetFromDataProviderException
25+
*/
26+
public function notify(PreparationFailed $event): void
27+
{
28+
$this->logger()->testPreparationFailed();
29+
}
30+
}

src/Logging/JUnit/Subscriber/TestPreparedSubscriber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ final class TestPreparedSubscriber extends Subscriber implements PreparedSubscri
2525
*/
2626
public function notify(Prepared $event): void
2727
{
28-
$this->logger()->testPrepared($event);
28+
$this->logger()->testPrepared();
2929
}
3030
}

tests/end-to-end/regression/5561.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
--TEST--
22
https://github.com/sebastianbergmann/phpunit/issues/5561
3-
--XFAIL--
4-
https://github.com/sebastianbergmann/phpunit/issues/5561
53
--FILE--
64
<?php declare(strict_types=1);
75
$_SERVER['argv'][] = '--do-not-cache-result';

0 commit comments

Comments
 (0)