Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not crash when test run in child process ends unexpectedly and --log-junit is used #5825

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Logging/JUnit/JunitXmlLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public function testPrepared(): void
*/
public function testFinished(Finished $event): void
{
if ($this->preparationFailed) {
if (!$this->prepared || $this->preparationFailed) {
return;
}

Expand Down
28 changes: 28 additions & 0 deletions tests/end-to-end/regression/5771.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/5771
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = __DIR__ . '/5771/Issue5771Test.php';
$_SERVER['argv'][] = '--log-junit';
$_SERVER['argv'][] = tempnam(sys_get_temp_dir(), __FILE__);

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

(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Runtime: %s

E 1 / 1 (100%)

Time: %s, Memory: %s

There was 1 error:

1) PHPUnit\TestFixture\Issue5771\Issue5771Test::test
Test was run in child process and ended unexpectedly

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
22 changes: 22 additions & 0 deletions tests/end-to-end/regression/5771/Issue5771Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TestFixture\Issue5771;

use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\TestCase;

final class Issue5771Test extends TestCase
{
#[RunInSeparateProcess]
public function test(): void
{
exit;
}
}