Skip to content

Commit d7b1c36

Browse files
authored
Merge pull request #1341 from nuernbergerA/phpunit-overrides
chore: Sync overrides
2 parents 003fc96 + c4c9e91 commit d7b1c36

File tree

2 files changed

+42
-17
lines changed

2 files changed

+42
-17
lines changed

overrides/Logging/JUnit/JunitXmlLogger.php

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use PHPUnit\Event\Test\MarkedIncomplete;
2828
use PHPUnit\Event\Test\PreparationStarted;
2929
use PHPUnit\Event\Test\Prepared;
30+
use PHPUnit\Event\Test\PrintedUnexpectedOutput;
3031
use PHPUnit\Event\Test\Skipped;
3132
use PHPUnit\Event\TestSuite\Started;
3233
use PHPUnit\Event\UnknownSubscriberTypeException;
@@ -41,6 +42,8 @@
4142
use function trim;
4243

4344
/**
45+
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
46+
*
4447
* @internal This class is not covered by the backward compatibility promise for PHPUnit
4548
*/
4649
final class JunitXmlLogger
@@ -59,32 +62,32 @@ final class JunitXmlLogger
5962
private array $testSuites = [];
6063

6164
/**
62-
* @psalm-var array<int,int>
65+
* @var array<int,int>
6366
*/
6467
private array $testSuiteTests = [0];
6568

6669
/**
67-
* @psalm-var array<int,int>
70+
* @var array<int,int>
6871
*/
6972
private array $testSuiteAssertions = [0];
7073

7174
/**
72-
* @psalm-var array<int,int>
75+
* @var array<int,int>
7376
*/
7477
private array $testSuiteErrors = [0];
7578

7679
/**
77-
* @psalm-var array<int,int>
80+
* @var array<int,int>
7881
*/
7982
private array $testSuiteFailures = [0];
8083

8184
/**
82-
* @psalm-var array<int,int>
85+
* @var array<int,int>
8386
*/
8487
private array $testSuiteSkipped = [0];
8588

8689
/**
87-
* @psalm-var array<int,int>
90+
* @var array<int,int>
8891
*/
8992
private array $testSuiteTimes = [0];
9093

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

114117
public function flush(): void
115118
{
116-
$this->printer->print($this->document->saveXML());
119+
$this->printer->print($this->document->saveXML() ?: '');
117120

118121
$this->printer->flush();
119122
}
@@ -195,28 +198,34 @@ public function testPreparationStarted(PreparationStarted $event): void
195198
$this->createTestCase($event);
196199
}
197200

198-
/**
199-
* @throws InvalidArgumentException
200-
*/
201201
public function testPreparationFailed(): void
202202
{
203203
$this->preparationFailed = true;
204204
}
205205

206-
/**
207-
* @throws InvalidArgumentException
208-
*/
209206
public function testPrepared(): void
210207
{
211208
$this->prepared = true;
212209
}
213210

211+
public function testPrintedUnexpectedOutput(PrintedUnexpectedOutput $event): void
212+
{
213+
assert($this->currentTestCase !== null);
214+
215+
$systemOut = $this->document->createElement(
216+
'system-out',
217+
Xml::prepareString($event->output()),
218+
);
219+
220+
$this->currentTestCase->appendChild($systemOut);
221+
}
222+
214223
/**
215224
* @throws InvalidArgumentException
216225
*/
217226
public function testFinished(Finished $event): void
218227
{
219-
if ($this->preparationFailed) {
228+
if (! $this->prepared || $this->preparationFailed) {
220229
return;
221230
}
222231

@@ -305,9 +314,11 @@ private function registerSubscribers(Facade $facade): void
305314
new TestPreparationStartedSubscriber($this),
306315
new TestPreparationFailedSubscriber($this),
307316
new TestPreparedSubscriber($this),
317+
new TestPrintedUnexpectedOutputSubscriber($this),
308318
new TestFinishedSubscriber($this),
309319
new TestErroredSubscriber($this),
310320
new TestFailedSubscriber($this),
321+
new TestMarkedIncompleteSubscriber($this),
311322
new TestSkippedSubscriber($this),
312323
new TestRunnerExecutionFinishedSubscriber($this),
313324
);
@@ -431,7 +442,7 @@ private function name(Test $test): string
431442
/**
432443
* @throws InvalidArgumentException
433444
*
434-
* @psalm-assert !null $this->currentTestCase
445+
* @phpstan-assert !null $this->currentTestCase
435446
*/
436447
private function createTestCase(Errored|Failed|MarkedIncomplete|PreparationStarted|Prepared|Skipped $event): void
437448
{

overrides/Runner/ResultCache/DefaultResultCache.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
namespace PHPUnit\Runner\ResultCache;
4747

4848
use const DIRECTORY_SEPARATOR;
49+
use const LOCK_EX;
4950

5051
use PHPUnit\Framework\TestStatus\TestStatus;
5152
use PHPUnit\Runner\DirectoryCannotBeCreatedException;
@@ -65,6 +66,8 @@
6566
use function Pest\version;
6667

6768
/**
69+
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
70+
*
6871
* @internal This class is not covered by the backward compatibility promise for PHPUnit
6972
*/
7073
final class DefaultResultCache implements ResultCache
@@ -77,12 +80,12 @@ final class DefaultResultCache implements ResultCache
7780
private readonly string $cacheFilename;
7881

7982
/**
80-
* @psalm-var array<string, TestStatus>
83+
* @var array<string, TestStatus>
8184
*/
8285
private array $defects = [];
8386

8487
/**
85-
* @psalm-var array<string, float>
88+
* @var array<string, float>
8689
*/
8790
private array $times = [];
8891

@@ -119,6 +122,17 @@ public function time(string $id): float
119122
return $this->times[$id] ?? 0.0;
120123
}
121124

125+
public function mergeWith(self $other): void
126+
{
127+
foreach ($other->defects as $id => $defect) {
128+
$this->defects[$id] = $defect;
129+
}
130+
131+
foreach ($other->times as $id => $time) {
132+
$this->times[$id] = $time;
133+
}
134+
}
135+
122136
public function load(): void
123137
{
124138
if (! is_file($this->cacheFilename)) {

0 commit comments

Comments
 (0)