Merge pull request #1341 from nuernbergerA/phpunit-overrides

chore: Sync overrides
This commit is contained in:
Nuno Maduro
2025-03-29 17:52:57 +00:00
committed by GitHub
2 changed files with 42 additions and 17 deletions

View File

@ -27,6 +27,7 @@ use PHPUnit\Event\Test\Finished;
use PHPUnit\Event\Test\MarkedIncomplete;
use PHPUnit\Event\Test\PreparationStarted;
use PHPUnit\Event\Test\Prepared;
use PHPUnit\Event\Test\PrintedUnexpectedOutput;
use PHPUnit\Event\Test\Skipped;
use PHPUnit\Event\TestSuite\Started;
use PHPUnit\Event\UnknownSubscriberTypeException;
@ -41,6 +42,8 @@ use function str_replace;
use function trim;
/**
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
*
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class JunitXmlLogger
@ -59,32 +62,32 @@ final class JunitXmlLogger
private array $testSuites = [];
/**
* @psalm-var array<int,int>
* @var array<int,int>
*/
private array $testSuiteTests = [0];
/**
* @psalm-var array<int,int>
* @var array<int,int>
*/
private array $testSuiteAssertions = [0];
/**
* @psalm-var array<int,int>
* @var array<int,int>
*/
private array $testSuiteErrors = [0];
/**
* @psalm-var array<int,int>
* @var array<int,int>
*/
private array $testSuiteFailures = [0];
/**
* @psalm-var array<int,int>
* @var array<int,int>
*/
private array $testSuiteSkipped = [0];
/**
* @psalm-var array<int,int>
* @var array<int,int>
*/
private array $testSuiteTimes = [0];
@ -113,7 +116,7 @@ final class JunitXmlLogger
public function flush(): void
{
$this->printer->print($this->document->saveXML());
$this->printer->print($this->document->saveXML() ?: '');
$this->printer->flush();
}
@ -195,28 +198,34 @@ final class JunitXmlLogger
$this->createTestCase($event);
}
/**
* @throws InvalidArgumentException
*/
public function testPreparationFailed(): void
{
$this->preparationFailed = true;
}
/**
* @throws InvalidArgumentException
*/
public function testPrepared(): void
{
$this->prepared = true;
}
public function testPrintedUnexpectedOutput(PrintedUnexpectedOutput $event): void
{
assert($this->currentTestCase !== null);
$systemOut = $this->document->createElement(
'system-out',
Xml::prepareString($event->output()),
);
$this->currentTestCase->appendChild($systemOut);
}
/**
* @throws InvalidArgumentException
*/
public function testFinished(Finished $event): void
{
if ($this->preparationFailed) {
if (! $this->prepared || $this->preparationFailed) {
return;
}
@ -305,9 +314,11 @@ final class JunitXmlLogger
new TestPreparationStartedSubscriber($this),
new TestPreparationFailedSubscriber($this),
new TestPreparedSubscriber($this),
new TestPrintedUnexpectedOutputSubscriber($this),
new TestFinishedSubscriber($this),
new TestErroredSubscriber($this),
new TestFailedSubscriber($this),
new TestMarkedIncompleteSubscriber($this),
new TestSkippedSubscriber($this),
new TestRunnerExecutionFinishedSubscriber($this),
);
@ -431,7 +442,7 @@ final class JunitXmlLogger
/**
* @throws InvalidArgumentException
*
* @psalm-assert !null $this->currentTestCase
* @phpstan-assert !null $this->currentTestCase
*/
private function createTestCase(Errored|Failed|MarkedIncomplete|PreparationStarted|Prepared|Skipped $event): void
{

View File

@ -46,6 +46,7 @@ declare(strict_types=1);
namespace PHPUnit\Runner\ResultCache;
use const DIRECTORY_SEPARATOR;
use const LOCK_EX;
use PHPUnit\Framework\TestStatus\TestStatus;
use PHPUnit\Runner\DirectoryCannotBeCreatedException;
@ -65,6 +66,8 @@ use function json_encode;
use function Pest\version;
/**
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
*
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class DefaultResultCache implements ResultCache
@ -77,12 +80,12 @@ final class DefaultResultCache implements ResultCache
private readonly string $cacheFilename;
/**
* @psalm-var array<string, TestStatus>
* @var array<string, TestStatus>
*/
private array $defects = [];
/**
* @psalm-var array<string, float>
* @var array<string, float>
*/
private array $times = [];
@ -119,6 +122,17 @@ final class DefaultResultCache implements ResultCache
return $this->times[$id] ?? 0.0;
}
public function mergeWith(self $other): void
{
foreach ($other->defects as $id => $defect) {
$this->defects[$id] = $defect;
}
foreach ($other->times as $id => $time) {
$this->times[$id] = $time;
}
}
public function load(): void
{
if (! is_file($this->cacheFilename)) {