Skip to content

Commit a04d910

Browse files
Merge branch '10.5' into 11.5
2 parents c60d4ba + dc21e01 commit a04d910

File tree

4 files changed

+66
-11
lines changed

4 files changed

+66
-11
lines changed

ChangeLog-11.5.md

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

99
* [#6103](https://github.com/sebastianbergmann/phpunit/issues/6103): Output from test run in separate process is printed twice
10+
* [#6109](https://github.com/sebastianbergmann/phpunit/issues/6109): Skipping a test in a before-class method crashes JUnit XML logger
1011

1112
## [11.5.3] - 2025-01-13
1213

src/Logging/JUnit/JunitXmlLogger.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ final class JunitXmlLogger
8888
private ?HRTime $time = null;
8989
private bool $prepared = false;
9090
private bool $preparationFailed = false;
91+
private ?string $unexpectedOutput = null;
9192

9293
/**
9394
* @throws EventFacadeIsSealedException
@@ -197,14 +198,7 @@ public function testPrepared(): void
197198

198199
public function testPrintedUnexpectedOutput(PrintedUnexpectedOutput $event): void
199200
{
200-
assert($this->currentTestCase !== null);
201-
202-
$systemOut = $this->document->createElement(
203-
'system-out',
204-
Xml::prepareString($event->output()),
205-
);
206-
207-
$this->currentTestCase->appendChild($systemOut);
201+
$this->unexpectedOutput = $event->output();
208202
}
209203

210204
/**
@@ -277,16 +271,26 @@ private function handleFinish(Info $telemetryInfo, int $numberOfAssertionsPerfor
277271
sprintf('%F', $time),
278272
);
279273

274+
if ($this->unexpectedOutput !== null) {
275+
$systemOut = $this->document->createElement(
276+
'system-out',
277+
Xml::prepareString($this->unexpectedOutput),
278+
);
279+
280+
$this->currentTestCase->appendChild($systemOut);
281+
}
282+
280283
$this->testSuites[$this->testSuiteLevel]->appendChild(
281284
$this->currentTestCase,
282285
);
283286

284287
$this->testSuiteTests[$this->testSuiteLevel]++;
285288
$this->testSuiteTimes[$this->testSuiteLevel] += $time;
286289

287-
$this->currentTestCase = null;
288-
$this->time = null;
289-
$this->prepared = false;
290+
$this->currentTestCase = null;
291+
$this->time = null;
292+
$this->prepared = false;
293+
$this->unexpectedOutput = null;
290294
}
291295

292296
/**

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
https://github.com/sebastianbergmann/phpunit/issues/6109
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = '--no-output';
8+
$_SERVER['argv'][] = '--log-junit';
9+
$_SERVER['argv'][] = 'php://stdout';
10+
$_SERVER['argv'][] = __DIR__ . '/6109/Issue6109Test.php';
11+
12+
require_once __DIR__ . '/../../bootstrap.php';
13+
14+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
15+
--EXPECTF--
16+
<?xml version="1.0" encoding="UTF-8"?>
17+
<testsuites>
18+
<testsuite name="PHPUnit\TestFixture\Issue6109\Issue6109Test" file="%sIssue6109Test.php" tests="1" assertions="0" errors="0" failures="0" skipped="1" time="%s">
19+
<testcase name="testOne" file="%sIssue6109Test.php" line="23" class="PHPUnit\TestFixture\Issue6109\Issue6109Test" classname="PHPUnit.TestFixture.Issue6109.Issue6109Test" assertions="0" time="%s">
20+
<skipped/>
21+
</testcase>
22+
</testsuite>
23+
</testsuites>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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\TestFixture\Issue6109;
11+
12+
use PHPUnit\Framework\TestCase;
13+
14+
final class Issue6109Test extends TestCase
15+
{
16+
protected function setUp(): void
17+
{
18+
print '*';
19+
20+
$this->markTestSkipped('message');
21+
}
22+
23+
public function testOne(): void
24+
{
25+
$this->assertTrue(true);
26+
}
27+
}

0 commit comments

Comments
 (0)