Skip to content

Commit

Permalink
Merge pull request #6 from robiningelbrecht/add-runtime-info
Browse files Browse the repository at this point in the history
Add runtime info to output
  • Loading branch information
robiningelbrecht committed Sep 8, 2023
2 parents b8a4c72 + d6e10a3 commit 5d42dbf
Show file tree
Hide file tree
Showing 11 changed files with 304 additions and 385 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor
.phpunit.cache
.phpunit.result.cache
.php-cs-fixer.cache
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
],
"require": {
"php": "^8.1",
"nunomaduro/collision": "^7.5",
"phpunit/phpunit": "^10.1"
"nunomaduro/collision": "^7.8",
"phpunit/phpunit": "^10.3"
},
"autoload": {
"psr-4": {
Expand All @@ -30,7 +30,6 @@
}
},
"require-dev": {
"dg/bypass-finals": "^1.4",
"friendsofphp/php-cs-fixer": "^3.15",
"phpstan/phpstan": "^1.10",
"spatie/phpunit-snapshot-assertions": "^5.0"
Expand All @@ -40,6 +39,6 @@
},
"scripts": {
"lint:fix": " ./vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php",
"phpunit:test": "vendor/bin/phpunit --configuration=tests/phpunit.test.xml --no-output"
"phpunit:test": "vendor/bin/phpunit --configuration=tests/phpunit.test.xml"
}
}
390 changes: 166 additions & 224 deletions composer.lock

Large diffs are not rendered by default.

8 changes: 1 addition & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
colors="true"
defaultTestSuite="unit"
cacheDirectory=".phpunit.cache"
displayDetailsOnTestsThatTriggerWarnings="true"
bootstrap="tests/bootstrap.php">
<extensions>
<bootstrap class="RobinIngelbrecht\PHPUnitPrettyPrint\PhpUnitExtension">

</bootstrap>
</extensions>
displayDetailsOnTestsThatTriggerWarnings="true">
<testsuites>
<testsuite name="unit">
<file>tests/OutputTest.php</file>
Expand Down
2 changes: 2 additions & 0 deletions src/PhpUnitExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PHPUnit\Runner\Extension\ParameterCollection;
use PHPUnit\TextUI\Configuration\Configuration as PHPUnitConfiguration;
use RobinIngelbrecht\PHPUnitPrettyPrint\Subscriber\Application\ApplicationFinishedSubscriber;
use RobinIngelbrecht\PHPUnitPrettyPrint\Subscriber\Application\ApplicationStartedSubscriber;

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

EnsurePrinterIsRegisteredSubscriber::register();

$facade->registerSubscriber(new ApplicationStartedSubscriber());
if (!$configuration->displayQuote()) {
return;
}
Expand Down
20 changes: 20 additions & 0 deletions src/Subscriber/Application/ApplicationStartedSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace RobinIngelbrecht\PHPUnitPrettyPrint\Subscriber\Application;

use PHPUnit\Event\Application\Started;
use PHPUnit\Event\Application\StartedSubscriber;

use function Termwind\render;

class ApplicationStartedSubscriber implements StartedSubscriber
{
public function notify(Started $event): void
{
render('<br />');
render(sprintf(
'<div>&nbsp;&nbsp;Runtime: %s</div>',
$event->runtime()->asString()
));
}
}
12 changes: 12 additions & 0 deletions tests/OutputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public function testWithProfiling(): void

exec(implode(' ', $command), $out);
$output = implode(PHP_EOL, $out);

$this->assertMatchesRegularExpression('/Runtime: PHPUnit [\s\S]+ using PHP [\s\S]+ on [\s\S]+/', $output);
$this->assertStringContainsString('Tests: 2 passed (4 assertions)', $output);
$this->assertStringContainsString('Top 10 slowest tests', $output);
}
Expand All @@ -44,6 +46,8 @@ public function testWithProfilingAtRunTime(): void
];
exec(implode(' ', $command), $out);
$output = implode(PHP_EOL, $out);

$this->assertMatchesRegularExpression('/Runtime: PHPUnit [\s\S]+ using PHP [\s\S]+ on [\s\S]+/', $output);
$this->assertStringContainsString('Tests: 2 passed (4 assertions)', $output);
$this->assertStringContainsString('Top 10 slowest tests', $output);
}
Expand All @@ -57,6 +61,8 @@ public function testPrintCompactMode(): void

exec(implode(' ', $command), $out);
$output = implode(PHP_EOL, $out);

$this->assertMatchesRegularExpression('/Runtime: PHPUnit [\s\S]+ using PHP [\s\S]+ on [\s\S]+/', $output);
$this->assertStringContainsString('.⨯⨯⨯!si..', $output);
$this->assertStringContainsString('Tests: 3 failed, 1 risky, 1 incomplete, 1 skipped, 3 passed (7 assertions)', $output);
}
Expand All @@ -70,6 +76,8 @@ public function testPrintCompactModeAtRunTime(): void
];
exec(implode(' ', $command), $out);
$output = implode(PHP_EOL, $out);

$this->assertMatchesRegularExpression('/Runtime: PHPUnit [\s\S]+ using PHP [\s\S]+ on [\s\S]+/', $output);
$this->assertStringContainsString('.⨯⨯⨯!si..', $output);
$this->assertStringContainsString('Tests: 3 failed, 1 risky, 1 incomplete, 1 skipped, 3 passed (7 assertions)', $output);
}
Expand Down Expand Up @@ -137,6 +145,8 @@ public function testItShouldBeEnabled(): void
];
exec(implode(' ', $command), $out);
$output = implode(PHP_EOL, $out);

$this->assertMatchesRegularExpression('/Runtime: PHPUnit [\s\S]+ using PHP [\s\S]+ on [\s\S]+/', $output);
$this->assertStringContainsString('Tests: 2 passed (4 assertions)', $output);
}

Expand All @@ -149,6 +159,8 @@ public function testItShouldBeDisabled(): void
];
exec(implode(' ', $command), $out);
$output = implode(PHP_EOL, $out);

$this->assertDoesNotMatchRegularExpression('/Runtime: PHPUnit [\s\S]+ using PHP [\s\S]+ on [\s\S]+/', $output);
$this->assertStringContainsString('OK (2 tests, 4 assertions)', $output);
}
}
Loading

0 comments on commit 5d42dbf

Please sign in to comment.