Skip to content

Commit 1faaf1b

Browse files
Merge pull request #13 from robiningelbrecht/ISSUE-12
ISSUE #12: Display random seed
2 parents e32ca0f + dd90e0d commit 1faaf1b

File tree

5 files changed

+63
-5
lines changed

5 files changed

+63
-5
lines changed

Makefile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
compose=docker compose
2+
3+
dc:
4+
@${compose} -f docker-compose.yml $(cmd)
5+
6+
dcr:
7+
@make dc cmd="run --rm php-cli $(cmd)"
8+
9+
stop:
10+
@make dc cmd="stop"
11+
12+
up:
13+
@make dc cmd="up -d"
14+
15+
build-containers:
16+
@make dc cmd="up -d --build"
17+
18+
down:
19+
@make dc cmd="down"
20+
21+
composer:
22+
@make dcr cmd="composer $(arg)"
23+
24+
# Code quality tools.
25+
phpunit:
26+
@make dcr cmd="vendor/bin/phpunit -d --enable-pretty-print -d --compact $(arg)"
27+
28+
phpunit-with-coverage-report:
29+
@make phpunit arg="--coverage-clover=clover.xml -d --min-coverage=min-coverage-rules.php"
30+
31+
phpstan:
32+
@make dcr cmd="vendor/bin/phpstan --memory-limit=1G $(arg)"
33+
34+
csfix:
35+
@make dcr cmd="vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php"
36+
37+
delete-snapshots:
38+
find . -name __snapshots__ -type d -prune -exec rm -rf {} \;

composer.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,5 @@
3636
},
3737
"config": {
3838
"sort-packages": true
39-
},
40-
"scripts": {
41-
"lint:fix": " ./vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php",
42-
"phpunit:test": "vendor/bin/phpunit --configuration=tests/phpunit.test.xml"
4339
}
4440
}

src/PhpUnitExtension.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use PHPUnit\Runner\Extension\Extension;
77
use PHPUnit\Runner\Extension\Facade;
88
use PHPUnit\Runner\Extension\ParameterCollection;
9+
use PHPUnit\Runner\TestSuiteSorter;
910
use PHPUnit\TextUI\Configuration\Configuration as PHPUnitConfiguration;
1011
use RobinIngelbrecht\PHPUnitPrettyPrint\Subscriber\Application\ApplicationFinishedSubscriber;
1112
use RobinIngelbrecht\PHPUnitPrettyPrint\Subscriber\Application\ApplicationStartedSubscriber;
@@ -18,6 +19,7 @@ public function bootstrap(PHPUnitConfiguration $configuration, Facade $facade, P
1819
return;
1920
}
2021

22+
$_SERVER['PHPUNIT_RANDOM_ORDER_SEED'] = TestSuiteSorter::ORDER_RANDOMIZED === $configuration->executionOrder() ? $configuration->randomOrderSeed() : null;
2123
$configuration = Configuration::fromParameterCollection($parameters);
2224

2325
$facade->replaceOutput();

src/Subscriber/Application/ApplicationStartedSubscriber.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,11 @@ public function notify(Started $event): void
1616
'<div>&nbsp;&nbsp;Runtime: %s</div>',
1717
$event->runtime()->asString()
1818
));
19+
if (!empty($_SERVER['PHPUNIT_RANDOM_ORDER_SEED'])) {
20+
render(sprintf(
21+
'<div>&nbsp;&nbsp;Random Seed: %s</div>',
22+
$_SERVER['PHPUNIT_RANDOM_ORDER_SEED']
23+
));
24+
}
1925
}
2026
}

tests/OutputTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ public function testPrintWithoutConfig(): void
1818
];
1919

2020
exec(implode(' ', $command), $out);
21-
$this->assertStringContainsString('Tests: 3 failed, 1 risky, 1 incomplete, 1 skipped, 3 passed (7 assertions)', implode(PHP_EOL, $out));
21+
$output = implode(PHP_EOL, $out);
22+
$this->assertStringContainsString('Tests: 3 failed, 1 risky, 1 incomplete, 1 skipped, 3 passed (7 assertions)', $output);
23+
$this->assertStringNotContainsString('Random Seed:', $output);
2224
}
2325

2426
public function testWithProfiling(): void
@@ -135,6 +137,20 @@ public function testPrintWithQuoteAtRuntime(): void
135137
}
136138
}
137139

140+
public function testPrintWithRandomSeed(): void
141+
{
142+
$command = [
143+
'vendor/bin/phpunit',
144+
'--configuration=tests/phpunit.test.xml',
145+
'--order-by=random',
146+
];
147+
148+
exec(implode(' ', $command), $out);
149+
$output = implode(PHP_EOL, $out);
150+
$this->assertStringContainsString('Tests: 3 failed, 1 risky, 1 incomplete, 1 skipped, 3 passed (7 assertions)', $output);
151+
$this->assertStringContainsString('Random Seed:', $output);
152+
}
153+
138154
public function testItShouldBeEnabled(): void
139155
{
140156
$command = [

0 commit comments

Comments
 (0)