Skip to content

Commit a56d37e

Browse files
obstschalefreekmurze
authored andcommitted
Add RandomSeed Screen (#95)
New feature to run phpunit-watcher with a random seed.
1 parent c50b121 commit a56d37e

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to `phpunit-watcher` will be documented in this file
44

5+
## Unreleased
6+
7+
- new random seed feature. Run tests in random order.
8+
59
## 1.11.2 - 2019-09-09
610

711
- Remove `deleteChar` call

src/Screens/Phpunit.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public function registerListeners()
6161
case 'p':
6262
$this->terminal->displayScreen(new FilterFileName());
6363
break;
64+
case 'r':
65+
$this->terminal->displayScreen(new RandomSeed());
66+
break;
6467
case 'q':
6568
die();
6669
break;
@@ -114,6 +117,7 @@ protected function displayManual()
114117
->write('<dim>Press </dim>p<dim> to filter by file name.</dim>')
115118
->write('<dim>Press </dim>g<dim> to filter by group name.</dim>')
116119
->write('<dim>Press </dim>s<dim> to filter by test suite name.</dim>')
120+
->write('<dim>Press </dim>r<dim> to run tests with a random seed.</dim>')
117121
->write('<dim>Press </dim>q<dim> to quit the watcher.</dim>')
118122
->write('<dim>Press </dim>Enter<dim> to trigger a test run.</dim>');
119123

src/Screens/RandomSeed.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Spatie\PhpUnitWatcher\Screens;
4+
5+
class RandomSeed extends Screen
6+
{
7+
public function draw()
8+
{
9+
$this->terminal
10+
->comment('Random seed usage')
11+
->write('Type a seed and press Enter to run tests in random order but with a specific seed.')
12+
->write('Press Enter with an empty pattern to execute all tests in random order.')
13+
->emptyLine()
14+
->comment('Start typing to add a random seed')
15+
->prompt('seed > ');
16+
17+
return $this;
18+
}
19+
20+
public function registerListeners()
21+
{
22+
$this->terminal->on('data', function ($line) {
23+
$phpunitArguments = '--order-by=random';
24+
if ($line !== '') {
25+
$phpunitArguments .= " --random-order-seed={$line}";
26+
}
27+
28+
$phpunitScreen = $this->terminal->getPreviousScreen();
29+
30+
$options = $phpunitScreen->options;
31+
32+
$options['phpunit']['arguments'] = $phpunitArguments;
33+
34+
$this->terminal->displayScreen(new Phpunit($options));
35+
});
36+
37+
return $this;
38+
}
39+
}

0 commit comments

Comments
 (0)