Skip to content

Commit e631086

Browse files
Do not use subscriber when no need to
1 parent a3e70c0 commit e631086

File tree

5 files changed

+23
-29
lines changed

5 files changed

+23
-29
lines changed

src/PhpUnitExtension.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ public function bootstrap(PHPUnitConfiguration $configuration, Facade $facade, P
2828
}
2929

3030
EnsurePrinterIsRegisteredSubscriber::register();
31-
$facade->registerSubscriber(new ApplicationFinishedSubscriber($configuration));
31+
32+
if (!$configuration->displayQuote()) {
33+
return;
34+
}
35+
$facade->registerSubscriber(new ApplicationFinishedSubscriber());
3236
}
3337
}

src/Subscriber/Application/ApplicationFinishedSubscriber.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,14 @@
44

55
use PHPUnit\Event\Application\Finished;
66
use PHPUnit\Event\Application\FinishedSubscriber;
7-
use RobinIngelbrecht\PHPUnitPrettyPrint\Configuration;
87
use RobinIngelbrecht\PHPUnitPrettyPrint\Quotes;
98

109
use function Termwind\render;
1110

1211
final class ApplicationFinishedSubscriber implements FinishedSubscriber
1312
{
14-
public function __construct(
15-
private readonly Configuration $configuration
16-
) {
17-
}
18-
1913
public function notify(Finished $event): void
2014
{
21-
if (!$this->configuration->displayQuote()) {
22-
return;
23-
}
24-
2515
render(sprintf('<div class="bg-green p-2">%s</div>', Quotes::getRandom()));
2616
}
2717
}

tests/__snapshots__/OutputTest__testPrintCompactModeAtRunTime__1.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@
2828
)
2929

3030

31-
at tests/ExampleTests/TestThatHasAllStatusesTest.php:31
31+
at tests/ExampleTests/TestThatHasAllStatusesTest.php:29
32+
25▕
33+
26▕ public function testFailWithDiff(): void
3234
27▕ {
3335
28▕ usleep(self::SLEEP_IN_MICRO_SECONDS);
34-
29▕ $this->assertEquals(
36+
29▕ $this->assertEquals(
3537
30▕ ['one', 'two'],
36-
31▕ ['two', 'one']
38+
31▕ ['two', 'one']
3739
32▕ );
3840
33▕ }
39-
34▕
40-
35▕ public function testError(): void
4141

42-
1 tests/ExampleTests/TestThatHasAllStatusesTest.php:31
42+
1 tests/ExampleTests/TestThatHasAllStatusesTest.php:29
4343

4444
───────────────────
4545
FAILED Tests\ExampleTests\TestThatHasAllStatusesTest > error Exception

tests/__snapshots__/OutputTest__testPrintCompactMode__1.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@
2828
)
2929

3030

31-
at tests/ExampleTests/TestThatHasAllStatusesTest.php:31
31+
at tests/ExampleTests/TestThatHasAllStatusesTest.php:29
32+
25▕
33+
26▕ public function testFailWithDiff(): void
3234
27▕ {
3335
28▕ usleep(self::SLEEP_IN_MICRO_SECONDS);
34-
29▕ $this->assertEquals(
36+
29▕ $this->assertEquals(
3537
30▕ ['one', 'two'],
36-
31▕ ['two', 'one']
38+
31▕ ['two', 'one']
3739
32▕ );
3840
33▕ }
39-
34▕
40-
35▕ public function testError(): void
4141

42-
1 tests/ExampleTests/TestThatHasAllStatusesTest.php:31
42+
1 tests/ExampleTests/TestThatHasAllStatusesTest.php:29
4343

4444
───────────────────
4545
FAILED Tests\ExampleTests\TestThatHasAllStatusesTest > error Exception

tests/__snapshots__/OutputTest__testPrintWithoutConfig__1.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@
3939
)
4040

4141

42-
at tests/ExampleTests/TestThatHasAllStatusesTest.php:31
42+
at tests/ExampleTests/TestThatHasAllStatusesTest.php:29
43+
25▕
44+
26▕ public function testFailWithDiff(): void
4345
27▕ {
4446
28▕ usleep(self::SLEEP_IN_MICRO_SECONDS);
45-
29▕ $this->assertEquals(
47+
29▕ $this->assertEquals(
4648
30▕ ['one', 'two'],
47-
31▕ ['two', 'one']
49+
31▕ ['two', 'one']
4850
32▕ );
4951
33▕ }
50-
34▕
51-
35▕ public function testError(): void
5252

53-
1 tests/ExampleTests/TestThatHasAllStatusesTest.php:31
53+
1 tests/ExampleTests/TestThatHasAllStatusesTest.php:29
5454

5555
───────────────────
5656
FAILED Tests\ExampleTests\TestThatHasAllStatusesTest > error Exception

0 commit comments

Comments
 (0)