Skip to content

Commit

Permalink
Add RandomSeed Screen (#95)
Browse files Browse the repository at this point in the history
New feature to run phpunit-watcher with a random seed.
  • Loading branch information
obstschale authored and freekmurze committed Sep 9, 2019
1 parent c50b121 commit a56d37e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

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

## Unreleased

- new random seed feature. Run tests in random order.

## 1.11.2 - 2019-09-09

- Remove `deleteChar` call
Expand Down
4 changes: 4 additions & 0 deletions src/Screens/Phpunit.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public function registerListeners()
case 'p':
$this->terminal->displayScreen(new FilterFileName());
break;
case 'r':
$this->terminal->displayScreen(new RandomSeed());
break;
case 'q':
die();
break;
Expand Down Expand Up @@ -114,6 +117,7 @@ protected function displayManual()
->write('<dim>Press </dim>p<dim> to filter by file name.</dim>')
->write('<dim>Press </dim>g<dim> to filter by group name.</dim>')
->write('<dim>Press </dim>s<dim> to filter by test suite name.</dim>')
->write('<dim>Press </dim>r<dim> to run tests with a random seed.</dim>')
->write('<dim>Press </dim>q<dim> to quit the watcher.</dim>')
->write('<dim>Press </dim>Enter<dim> to trigger a test run.</dim>');

Expand Down
39 changes: 39 additions & 0 deletions src/Screens/RandomSeed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Spatie\PhpUnitWatcher\Screens;

class RandomSeed extends Screen
{
public function draw()
{
$this->terminal
->comment('Random seed usage')
->write('Type a seed and press Enter to run tests in random order but with a specific seed.')
->write('Press Enter with an empty pattern to execute all tests in random order.')
->emptyLine()
->comment('Start typing to add a random seed')
->prompt('seed > ');

return $this;
}

public function registerListeners()
{
$this->terminal->on('data', function ($line) {
$phpunitArguments = '--order-by=random';
if ($line !== '') {
$phpunitArguments .= " --random-order-seed={$line}";
}

$phpunitScreen = $this->terminal->getPreviousScreen();

$options = $phpunitScreen->options;

$options['phpunit']['arguments'] = $phpunitArguments;

$this->terminal->displayScreen(new Phpunit($options));
});

return $this;
}
}

0 comments on commit a56d37e

Please sign in to comment.