Skip to content

Commit

Permalink
Merge branch '10.5' into 11.5
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jan 28, 2025
2 parents c60d4ba + dc21e01 commit a04d910
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 11 deletions.
1 change: 1 addition & 0 deletions ChangeLog-11.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes of the PHPUnit 11.5 release series are documented in this fi
### Fixed

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

## [11.5.3] - 2025-01-13

Expand Down
26 changes: 15 additions & 11 deletions src/Logging/JUnit/JunitXmlLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ final class JunitXmlLogger
private ?HRTime $time = null;
private bool $prepared = false;
private bool $preparationFailed = false;
private ?string $unexpectedOutput = null;

/**
* @throws EventFacadeIsSealedException
Expand Down Expand Up @@ -197,14 +198,7 @@ public function testPrepared(): void

public function testPrintedUnexpectedOutput(PrintedUnexpectedOutput $event): void
{
assert($this->currentTestCase !== null);

$systemOut = $this->document->createElement(
'system-out',
Xml::prepareString($event->output()),
);

$this->currentTestCase->appendChild($systemOut);
$this->unexpectedOutput = $event->output();
}

/**
Expand Down Expand Up @@ -277,16 +271,26 @@ private function handleFinish(Info $telemetryInfo, int $numberOfAssertionsPerfor
sprintf('%F', $time),
);

if ($this->unexpectedOutput !== null) {
$systemOut = $this->document->createElement(
'system-out',
Xml::prepareString($this->unexpectedOutput),
);

$this->currentTestCase->appendChild($systemOut);
}

$this->testSuites[$this->testSuiteLevel]->appendChild(
$this->currentTestCase,
);

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

$this->currentTestCase = null;
$this->time = null;
$this->prepared = false;
$this->currentTestCase = null;
$this->time = null;
$this->prepared = false;
$this->unexpectedOutput = null;
}

/**
Expand Down
23 changes: 23 additions & 0 deletions tests/end-to-end/regression/6109.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/6109
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--no-output';
$_SERVER['argv'][] = '--log-junit';
$_SERVER['argv'][] = 'php://stdout';
$_SERVER['argv'][] = __DIR__ . '/6109/Issue6109Test.php';

require_once __DIR__ . '/../../bootstrap.php';

(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
--EXPECTF--
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="PHPUnit\TestFixture\Issue6109\Issue6109Test" file="%sIssue6109Test.php" tests="1" assertions="0" errors="0" failures="0" skipped="1" time="%s">
<testcase name="testOne" file="%sIssue6109Test.php" line="23" class="PHPUnit\TestFixture\Issue6109\Issue6109Test" classname="PHPUnit.TestFixture.Issue6109.Issue6109Test" assertions="0" time="%s">
<skipped/>
</testcase>
</testsuite>
</testsuites>
27 changes: 27 additions & 0 deletions tests/end-to-end/regression/6109/Issue6109Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TestFixture\Issue6109;

use PHPUnit\Framework\TestCase;

final class Issue6109Test extends TestCase
{
protected function setUp(): void
{
print '*';

$this->markTestSkipped('message');
}

public function testOne(): void
{
$this->assertTrue(true);
}
}

0 comments on commit a04d910

Please sign in to comment.