-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathPhpunitScreen.php
More file actions
83 lines (70 loc) · 2.11 KB
/
PhpunitScreen.php
File metadata and controls
83 lines (70 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
namespace Spatie\PhpUnitWatcher\Screens;
use Symfony\Component\Process\Process;
class PhpunitScreen extends Screen
{
/** @var string */
protected $phpunitArguments;
public function __construct(string $phpunitArguments = '')
{
$this->phpunitArguments = $phpunitArguments;
}
public function draw()
{
$this->writeHeader();
$this->runTests();
$this->displayManual();
}
public function registerListeners()
{
$this->terminal->on('data', function ($line) {
$line = trim(strtolower($line));
switch ($line) {
case '':
$this->terminal->refreshScreen();
break;
case 'a':
$this->terminal->displayScreen(new PhpunitScreen());
break;
case 't':
$this->terminal->displayScreen(new FilterTestNameScreen());
break;
case 'p':
$this->terminal->displayScreen(new FilterFileNameScreen());
break;
case 'q':
die();
break;
}
});
return $this;
}
protected function writeHeader()
{
$title = 'Starting PHPUnit';
if (! empty($this->phpunitArguments)) {
$title .= " with arguments: `{$this->phpunitArguments}`";
}
$this->terminal
->comment($title)
->emptyLine();
}
protected function runTests()
{
(new Process("vendor/bin/phpunit {$this->phpunitArguments}"))
->setTty(true)
->run(function ($type, $line) {
echo $line;
});
}
protected function displayManual()
{
$this->terminal
->emptyLine()
->write('Press a to run all tests.')
->write('Press t to filter by a test name.')
->write('Press p to filter by a file name.')
->write('Press q to quit the watcher.')
->write('Press Enter to trigger a test run.');
}
}