Skip to content

Commit bd2e272

Browse files
committed
Enhancement: Extract SlowTestList
1 parent 1dc8da8 commit bd2e272

17 files changed

+749
-154
lines changed

phpstan-baseline.neon

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ parameters:
110110
count: 1
111111
path: test/Unit/Console/ColorTest.php
112112

113+
-
114+
message: "#^Method Ergebnis\\\\PHPUnit\\\\SlowTestDetector\\\\Test\\\\Unit\\\\CountTest\\:\\:testEqualsReturnsFalseWhenValueIsDifferent\\(\\) has no return type specified\\.$#"
115+
count: 1
116+
path: test/Unit/CountTest.php
117+
118+
-
119+
message: "#^Method Ergebnis\\\\PHPUnit\\\\SlowTestDetector\\\\Test\\\\Unit\\\\CountTest\\:\\:testEqualsReturnsTrueWhenValueIsSame\\(\\) has no return type specified\\.$#"
120+
count: 1
121+
path: test/Unit/CountTest.php
122+
113123
-
114124
message: "#^Method Ergebnis\\\\PHPUnit\\\\SlowTestDetector\\\\Test\\\\Unit\\\\CountTest\\:\\:testFromIntRejectsInvalidValue\\(\\) has no return type specified\\.$#"
115125
count: 1
@@ -265,6 +275,11 @@ parameters:
265275
count: 1
266276
path: test/Unit/Exception/PhaseNotStartedTest.php
267277

278+
-
279+
message: "#^Method Ergebnis\\\\PHPUnit\\\\SlowTestDetector\\\\Test\\\\Unit\\\\Exception\\\\SlowTestListIsEmptyTest\\:\\:testFromPhaseIdentifierReturnsException\\(\\) has no return type specified\\.$#"
280+
count: 1
281+
path: test/Unit/Exception/SlowTestListIsEmptyTest.php
282+
268283
-
269284
message: "#^Method Ergebnis\\\\PHPUnit\\\\SlowTestDetector\\\\Test\\\\Unit\\\\Formatter\\\\DefaultDurationFormatterTest\\:\\:testFormatFormats\\(\\) has no return type specified\\.$#"
270285
count: 1
@@ -316,15 +331,80 @@ parameters:
316331
path: test/Unit/PhaseTest.php
317332

318333
-
319-
message: "#^Method Ergebnis\\\\PHPUnit\\\\SlowTestDetector\\\\Test\\\\Unit\\\\Reporter\\\\DefaultReporterTest\\:\\:testReportReturnsEmptyStringWhenThereAreNoSlowTests\\(\\) has no return type specified\\.$#"
334+
message: "#^Method Ergebnis\\\\PHPUnit\\\\SlowTestDetector\\\\Test\\\\Unit\\\\Reporter\\\\DefaultReporterTest\\:\\:testReportReturnsEmptyStringWhenSlowTestListIsEmpty\\(\\) has no return type specified\\.$#"
320335
count: 1
321336
path: test/Unit/Reporter/DefaultReporterTest.php
322337

323338
-
324-
message: "#^Method Ergebnis\\\\PHPUnit\\\\SlowTestDetector\\\\Test\\\\Unit\\\\Reporter\\\\DefaultReporterTest\\:\\:testReportReturnsReportWhenThereAreFewerSlowTestsThanMaximumCount\\(\\) has no return type specified\\.$#"
339+
message: "#^Method Ergebnis\\\\PHPUnit\\\\SlowTestDetector\\\\Test\\\\Unit\\\\Reporter\\\\DefaultReporterTest\\:\\:testReportReturnsReportWhenSlowTestListHasFewerSlowTestsThanMaximumCount\\(\\) has no return type specified\\.$#"
325340
count: 1
326341
path: test/Unit/Reporter/DefaultReporterTest.php
327342

343+
-
344+
message: "#^Method SlowTestCountTest\\:\\:testEqualsReturnsFalseWhenValueIsDifferent\\(\\) has no return type specified\\.$#"
345+
count: 1
346+
path: test/Unit/SlowTestCountTest.php
347+
348+
-
349+
message: "#^Method SlowTestCountTest\\:\\:testEqualsReturnsFalseWhenValueIsSame\\(\\) has no return type specified\\.$#"
350+
count: 1
351+
path: test/Unit/SlowTestCountTest.php
352+
353+
-
354+
message: "#^Method SlowTestCountTest\\:\\:testFromCountReturnsMaximumCount\\(\\) has no return type specified\\.$#"
355+
count: 1
356+
path: test/Unit/SlowTestCountTest.php
357+
358+
-
359+
message: "#^Method Ergebnis\\\\PHPUnit\\\\SlowTestDetector\\\\Test\\\\Unit\\\\SlowTestListTest\\:\\:testCreateReturnsSlowTestList\\(\\) has no return type specified\\.$#"
360+
count: 1
361+
path: test/Unit/SlowTestListTest.php
362+
363+
-
364+
message: "#^Method Ergebnis\\\\PHPUnit\\\\SlowTestDetector\\\\Test\\\\Unit\\\\SlowTestListTest\\:\\:testFirstReturnsFirstSlowTestWhenSlowTestListIsNotEmpty\\(\\) has no return type specified\\.$#"
365+
count: 1
366+
path: test/Unit/SlowTestListTest.php
367+
368+
-
369+
message: "#^Method Ergebnis\\\\PHPUnit\\\\SlowTestDetector\\\\Test\\\\Unit\\\\SlowTestListTest\\:\\:testFirstThrowsExceptionWhenSlowTestListIsEmpty\\(\\) has no return type specified\\.$#"
370+
count: 1
371+
path: test/Unit/SlowTestListTest.php
372+
373+
-
374+
message: "#^Method Ergebnis\\\\PHPUnit\\\\SlowTestDetector\\\\Test\\\\Unit\\\\SlowTestListTest\\:\\:testIsEmptyReturnsFalseWhenSlowTestListIsNotEmpty\\(\\) has no return type specified\\.$#"
375+
count: 1
376+
path: test/Unit/SlowTestListTest.php
377+
378+
-
379+
message: "#^Method Ergebnis\\\\PHPUnit\\\\SlowTestDetector\\\\Test\\\\Unit\\\\SlowTestListTest\\:\\:testIsEmptyReturnsTrueWhenSlowTestListIsEmpty\\(\\) has no return type specified\\.$#"
380+
count: 1
381+
path: test/Unit/SlowTestListTest.php
382+
383+
-
384+
message: "#^Method Ergebnis\\\\PHPUnit\\\\SlowTestDetector\\\\Test\\\\Unit\\\\SlowTestListTest\\:\\:testLimitToReturnsSlowTestListLimitedToMaximumCountWhenSlowTestListHasFewerSlowTests\\(\\) has no return type specified\\.$#"
385+
count: 1
386+
path: test/Unit/SlowTestListTest.php
387+
388+
-
389+
message: "#^Method Ergebnis\\\\PHPUnit\\\\SlowTestDetector\\\\Test\\\\Unit\\\\SlowTestListTest\\:\\:testLimitToReturnsSlowTestListLimitedToMaximumCountWhenSlowTestListHasMoreSlowTests\\(\\) has no return type specified\\.$#"
390+
count: 1
391+
path: test/Unit/SlowTestListTest.php
392+
393+
-
394+
message: "#^Method Ergebnis\\\\PHPUnit\\\\SlowTestDetector\\\\Test\\\\Unit\\\\SlowTestListTest\\:\\:testSlowTestCountReturnsCountOfSlowTests\\(\\) has no return type specified\\.$#"
395+
count: 1
396+
path: test/Unit/SlowTestListTest.php
397+
398+
-
399+
message: "#^Method Ergebnis\\\\PHPUnit\\\\SlowTestDetector\\\\Test\\\\Unit\\\\SlowTestListTest\\:\\:testSortByMaximumDurationDescendingReturnsSlowTestListWhereSlowTestsAreSortedByMaximumDurationDescending\\(\\) has no return type specified\\.$#"
400+
count: 1
401+
path: test/Unit/SlowTestListTest.php
402+
403+
-
404+
message: "#^Method Ergebnis\\\\PHPUnit\\\\SlowTestDetector\\\\Test\\\\Unit\\\\SlowTestListTest\\:\\:testSortByTestDurationDescendingReturnsSlowTestListWhereSlowTestsAreSortedByTestDurationDescending\\(\\) has no return type specified\\.$#"
405+
count: 1
406+
path: test/Unit/SlowTestListTest.php
407+
328408
-
329409
message: "#^Method Ergebnis\\\\PHPUnit\\\\SlowTestDetector\\\\Test\\\\Unit\\\\SlowTestTest\\:\\:testCreateReturnsSlowTest\\(\\) has no return type specified\\.$#"
330410
count: 1

src/Collector/Collector.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace Ergebnis\PHPUnit\SlowTestDetector\Collector;
1515

1616
use Ergebnis\PHPUnit\SlowTestDetector\SlowTest;
17+
use Ergebnis\PHPUnit\SlowTestDetector\SlowTestList;
1718

1819
/**
1920
* @internal
@@ -22,10 +23,5 @@ interface Collector
2223
{
2324
public function collectSlowTest(SlowTest $slowTest);
2425

25-
/**
26-
* @phpstan-return list<SlowTest>
27-
*
28-
* @return list<SlowTest>
29-
*/
30-
public function collected(): array;
26+
public function slowTestList(): SlowTestList;
3127
}

src/Collector/DefaultCollector.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace Ergebnis\PHPUnit\SlowTestDetector\Collector;
1515

1616
use Ergebnis\PHPUnit\SlowTestDetector\SlowTest;
17+
use Ergebnis\PHPUnit\SlowTestDetector\SlowTestList;
1718

1819
/**
1920
* @internal
@@ -44,13 +45,8 @@ public function collectSlowTest(SlowTest $slowTest)
4445
$this->slowTests[$key] = $slowTest;
4546
}
4647

47-
/**
48-
* @phpstan-return list<SlowTest>
49-
*
50-
* @return list<SlowTest>
51-
*/
52-
public function collected(): array
48+
public function slowTestList(): SlowTestList
5349
{
54-
return \array_values($this->slowTests);
50+
return SlowTestList::create(...\array_values($this->slowTests));
5551
}
5652
}

src/Count.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public static function fromInt(int $value): self
4040
return new self($value);
4141
}
4242

43+
public function equals(self $other): bool
44+
{
45+
return $this->value === $other->value;
46+
}
47+
4348
public function toInt(): int
4449
{
4550
return $this->value;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* Copyright (c) 2021-2025 Andreas Möller
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE.md file that was distributed with this source code.
10+
*
11+
* @see https://github.com/ergebnis/phpunit-slow-test-detector
12+
*/
13+
14+
namespace Ergebnis\PHPUnit\SlowTestDetector\Exception;
15+
16+
/**
17+
* @internal
18+
*/
19+
final class SlowTestListIsEmpty extends \RuntimeException
20+
{
21+
public static function create(): self
22+
{
23+
return new self('Slow test list is empty.');
24+
}
25+
}

src/Extension.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ public function __construct(array $options = [])
6969
$this->collector = new Collector\DefaultCollector();
7070
$this->reporter = new Reporter\DefaultReporter(
7171
new Formatter\DefaultDurationFormatter(),
72-
$maximumDuration,
7372
$maximumCount
7473
);
7574
}
@@ -129,13 +128,13 @@ public function endTestSuite(Framework\TestSuite $suite)
129128
return;
130129
}
131130

132-
$slowTests = $this->collector->collected();
131+
$slowTestList = $this->collector->slowTestList();
133132

134-
if ([] === $slowTests) {
133+
if ($slowTestList->isEmpty()) {
135134
return;
136135
}
137136

138-
$report = $this->reporter->report(...$slowTests);
137+
$report = $this->reporter->report($slowTestList);
139138

140139
if ('' === $report) {
141140
return;
@@ -277,7 +276,6 @@ public function __construct(array $options = [])
277276
$this->collector = new Collector\DefaultCollector();
278277
$this->reporter = new Reporter\DefaultReporter(
279278
new Formatter\DefaultDurationFormatter(),
280-
$maximumDuration,
281279
$maximumCount
282280
);
283281
}
@@ -335,13 +333,13 @@ public function executeAfterLastTest(): void
335333
return;
336334
}
337335

338-
$slowTests = $this->collector->collected();
336+
$slowTestList = $this->collector->slowTestList();
339337

340-
if ([] === $slowTests) {
338+
if ($slowTestList->isEmpty()) {
341339
return;
342340
}
343341

344-
$report = $this->reporter->report(...$slowTests);
342+
$report = $this->reporter->report($slowTestList);
345343

346344
if ('' === $report) {
347345
return;
@@ -431,7 +429,6 @@ public function bootstrap(
431429
$collector = new Collector\DefaultCollector();
432430
$reporter = new Reporter\DefaultReporter(
433431
new Formatter\DefaultDurationFormatter(),
434-
$maximumDuration,
435432
$maximumCount
436433
);
437434

0 commit comments

Comments
 (0)