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

chore: Sync overrides #1341

Open
wants to merge 7 commits into
base: 3.x
Choose a base branch
from
Open
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
41 changes: 26 additions & 15 deletions overrides/Logging/JUnit/JunitXmlLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;
Expand All @@ -41,6 +42,8 @@
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
Expand All @@ -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];

Expand Down Expand Up @@ -113,7 +116,7 @@ public function __construct(Printer $printer, Facade $facade)

public function flush(): void
{
$this->printer->print($this->document->saveXML());
$this->printer->print($this->document->saveXML() ?: '');

$this->printer->flush();
}
Expand Down Expand Up @@ -195,28 +198,34 @@ public function testPreparationStarted(PreparationStarted $event): void
$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;
}

Expand Down Expand Up @@ -305,9 +314,11 @@ private function registerSubscribers(Facade $facade): void
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),
);
Expand Down Expand Up @@ -431,7 +442,7 @@ private function name(Test $test): string
/**
* @throws InvalidArgumentException
*
* @psalm-assert !null $this->currentTestCase
* @phpstan-assert !null $this->currentTestCase
*/
private function createTestCase(Errored|Failed|MarkedIncomplete|PreparationStarted|Prepared|Skipped $event): void
{
Expand Down
18 changes: 16 additions & 2 deletions overrides/Runner/ResultCache/DefaultResultCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
namespace PHPUnit\Runner\ResultCache;

use const DIRECTORY_SEPARATOR;
use const LOCK_EX;

use PHPUnit\Framework\TestStatus\TestStatus;
use PHPUnit\Runner\DirectoryCannotBeCreatedException;
Expand All @@ -65,6 +66,8 @@
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
Expand All @@ -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 = [];

Expand Down Expand Up @@ -119,6 +122,17 @@ public function time(string $id): float
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)) {
Expand Down
Loading