Skip to content

Commit

Permalink
Closes #5561
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Dec 5, 2023
1 parent 7fc1b6b commit 61037fc
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
1 change: 1 addition & 0 deletions ChangeLog-10.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes of the PHPUnit 10.5 release series are documented in this fi

### Fixed

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

## [10.5.1] - 2023-12-01
Expand Down
17 changes: 16 additions & 1 deletion src/Logging/JUnit/JunitXmlLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ final class JunitXmlLogger
private ?DOMElement $currentTestCase = null;
private ?HRTime $time = null;
private bool $prepared = false;
private bool $preparationFailed = false;

/**
* @throws EventFacadeIsSealedException
Expand Down Expand Up @@ -186,7 +187,16 @@ public function testPreparationStarted(PreparationStarted $event): void
* @throws InvalidArgumentException
* @throws NoDataSetFromDataProviderException
*/
public function testPrepared(Prepared $event): void
public function testPreparationFailed(): void
{
$this->preparationFailed = true;
}

/**
* @throws InvalidArgumentException
* @throws NoDataSetFromDataProviderException
*/
public function testPrepared(): void
{
$this->prepared = true;
}
Expand All @@ -196,6 +206,10 @@ public function testPrepared(Prepared $event): void
*/
public function testFinished(Finished $event): void
{
if ($this->preparationFailed) {
return;
}

$this->handleFinish($event->telemetryInfo(), $event->numberOfAssertionsPerformed());
}

Expand Down Expand Up @@ -283,6 +297,7 @@ private function registerSubscribers(Facade $facade): void
new TestSuiteStartedSubscriber($this),
new TestSuiteFinishedSubscriber($this),
new TestPreparationStartedSubscriber($this),
new TestPreparationFailedSubscriber($this),
new TestPreparedSubscriber($this),
new TestFinishedSubscriber($this),
new TestErroredSubscriber($this),
Expand Down
30 changes: 30 additions & 0 deletions src/Logging/JUnit/Subscriber/TestPreparationFailedSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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\Logging\JUnit;

use PHPUnit\Event\InvalidArgumentException;
use PHPUnit\Event\Test\PreparationFailed;
use PHPUnit\Event\Test\PreparationFailedSubscriber;
use PHPUnit\Event\TestData\NoDataSetFromDataProviderException;

/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class TestPreparationFailedSubscriber extends Subscriber implements PreparationFailedSubscriber
{
/**
* @throws InvalidArgumentException
* @throws NoDataSetFromDataProviderException
*/
public function notify(PreparationFailed $event): void
{
$this->logger()->testPreparationFailed();
}
}
2 changes: 1 addition & 1 deletion src/Logging/JUnit/Subscriber/TestPreparedSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ final class TestPreparedSubscriber extends Subscriber implements PreparedSubscri
*/
public function notify(Prepared $event): void
{
$this->logger()->testPrepared($event);
$this->logger()->testPrepared();
}
}
2 changes: 0 additions & 2 deletions tests/end-to-end/regression/5561.phpt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/5561
--XFAIL--
https://github.com/sebastianbergmann/phpunit/issues/5561
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
Expand Down

0 comments on commit 61037fc

Please sign in to comment.