Skip to content

Commit 5d42dbf

Browse files
Merge pull request #6 from robiningelbrecht/add-runtime-info
Add runtime info to output
2 parents b8a4c72 + d6e10a3 commit 5d42dbf

11 files changed

+304
-385
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
vendor
22
.phpunit.cache
3+
.phpunit.result.cache
34
.php-cs-fixer.cache

composer.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
],
1717
"require": {
1818
"php": "^8.1",
19-
"nunomaduro/collision": "^7.5",
20-
"phpunit/phpunit": "^10.1"
19+
"nunomaduro/collision": "^7.8",
20+
"phpunit/phpunit": "^10.3"
2121
},
2222
"autoload": {
2323
"psr-4": {
@@ -30,7 +30,6 @@
3030
}
3131
},
3232
"require-dev": {
33-
"dg/bypass-finals": "^1.4",
3433
"friendsofphp/php-cs-fixer": "^3.15",
3534
"phpstan/phpstan": "^1.10",
3635
"spatie/phpunit-snapshot-assertions": "^5.0"
@@ -40,6 +39,6 @@
4039
},
4140
"scripts": {
4241
"lint:fix": " ./vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php",
43-
"phpunit:test": "vendor/bin/phpunit --configuration=tests/phpunit.test.xml --no-output"
42+
"phpunit:test": "vendor/bin/phpunit --configuration=tests/phpunit.test.xml"
4443
}
4544
}

composer.lock

+166-224
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpunit.xml.dist

+1-7
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,7 @@
66
colors="true"
77
defaultTestSuite="unit"
88
cacheDirectory=".phpunit.cache"
9-
displayDetailsOnTestsThatTriggerWarnings="true"
10-
bootstrap="tests/bootstrap.php">
11-
<extensions>
12-
<bootstrap class="RobinIngelbrecht\PHPUnitPrettyPrint\PhpUnitExtension">
13-
14-
</bootstrap>
15-
</extensions>
9+
displayDetailsOnTestsThatTriggerWarnings="true">
1610
<testsuites>
1711
<testsuite name="unit">
1812
<file>tests/OutputTest.php</file>

src/PhpUnitExtension.php

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PHPUnit\Runner\Extension\ParameterCollection;
99
use PHPUnit\TextUI\Configuration\Configuration as PHPUnitConfiguration;
1010
use RobinIngelbrecht\PHPUnitPrettyPrint\Subscriber\Application\ApplicationFinishedSubscriber;
11+
use RobinIngelbrecht\PHPUnitPrettyPrint\Subscriber\Application\ApplicationStartedSubscriber;
1112

1213
final class PhpUnitExtension implements Extension
1314
{
@@ -33,6 +34,7 @@ public function bootstrap(PHPUnitConfiguration $configuration, Facade $facade, P
3334

3435
EnsurePrinterIsRegisteredSubscriber::register();
3536

37+
$facade->registerSubscriber(new ApplicationStartedSubscriber());
3638
if (!$configuration->displayQuote()) {
3739
return;
3840
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace RobinIngelbrecht\PHPUnitPrettyPrint\Subscriber\Application;
4+
5+
use PHPUnit\Event\Application\Started;
6+
use PHPUnit\Event\Application\StartedSubscriber;
7+
8+
use function Termwind\render;
9+
10+
class ApplicationStartedSubscriber implements StartedSubscriber
11+
{
12+
public function notify(Started $event): void
13+
{
14+
render('<br />');
15+
render(sprintf(
16+
'<div>&nbsp;&nbsp;Runtime: %s</div>',
17+
$event->runtime()->asString()
18+
));
19+
}
20+
}

tests/OutputTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public function testWithProfiling(): void
3030

3131
exec(implode(' ', $command), $out);
3232
$output = implode(PHP_EOL, $out);
33+
34+
$this->assertMatchesRegularExpression('/Runtime: PHPUnit [\s\S]+ using PHP [\s\S]+ on [\s\S]+/', $output);
3335
$this->assertStringContainsString('Tests: 2 passed (4 assertions)', $output);
3436
$this->assertStringContainsString('Top 10 slowest tests', $output);
3537
}
@@ -44,6 +46,8 @@ public function testWithProfilingAtRunTime(): void
4446
];
4547
exec(implode(' ', $command), $out);
4648
$output = implode(PHP_EOL, $out);
49+
50+
$this->assertMatchesRegularExpression('/Runtime: PHPUnit [\s\S]+ using PHP [\s\S]+ on [\s\S]+/', $output);
4751
$this->assertStringContainsString('Tests: 2 passed (4 assertions)', $output);
4852
$this->assertStringContainsString('Top 10 slowest tests', $output);
4953
}
@@ -57,6 +61,8 @@ public function testPrintCompactMode(): void
5761

5862
exec(implode(' ', $command), $out);
5963
$output = implode(PHP_EOL, $out);
64+
65+
$this->assertMatchesRegularExpression('/Runtime: PHPUnit [\s\S]+ using PHP [\s\S]+ on [\s\S]+/', $output);
6066
$this->assertStringContainsString('.⨯⨯⨯!si..', $output);
6167
$this->assertStringContainsString('Tests: 3 failed, 1 risky, 1 incomplete, 1 skipped, 3 passed (7 assertions)', $output);
6268
}
@@ -70,6 +76,8 @@ public function testPrintCompactModeAtRunTime(): void
7076
];
7177
exec(implode(' ', $command), $out);
7278
$output = implode(PHP_EOL, $out);
79+
80+
$this->assertMatchesRegularExpression('/Runtime: PHPUnit [\s\S]+ using PHP [\s\S]+ on [\s\S]+/', $output);
7381
$this->assertStringContainsString('.⨯⨯⨯!si..', $output);
7482
$this->assertStringContainsString('Tests: 3 failed, 1 risky, 1 incomplete, 1 skipped, 3 passed (7 assertions)', $output);
7583
}
@@ -137,6 +145,8 @@ public function testItShouldBeEnabled(): void
137145
];
138146
exec(implode(' ', $command), $out);
139147
$output = implode(PHP_EOL, $out);
148+
149+
$this->assertMatchesRegularExpression('/Runtime: PHPUnit [\s\S]+ using PHP [\s\S]+ on [\s\S]+/', $output);
140150
$this->assertStringContainsString('Tests: 2 passed (4 assertions)', $output);
141151
}
142152

@@ -149,6 +159,8 @@ public function testItShouldBeDisabled(): void
149159
];
150160
exec(implode(' ', $command), $out);
151161
$output = implode(PHP_EOL, $out);
162+
163+
$this->assertDoesNotMatchRegularExpression('/Runtime: PHPUnit [\s\S]+ using PHP [\s\S]+ on [\s\S]+/', $output);
152164
$this->assertStringContainsString('OK (2 tests, 4 assertions)', $output);
153165
}
154166
}

0 commit comments

Comments
 (0)