1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\PhpUnitWatcher\Screens; |
4
|
|
|
|
5
|
|
|
use Spatie\PhpUnitWatcher\Screens\Completers\FilenameCompleter; |
6
|
|
|
|
7
|
|
|
class FilterFileName extends Screen |
8
|
|
|
{ |
9
|
|
|
public function draw() |
10
|
|
|
{ |
11
|
|
|
$this->terminal |
12
|
|
|
->comment('Pattern mode usage') |
13
|
|
|
->write('Type a pattern and press Enter to only run tests in the giving path or file.') |
14
|
|
|
->write('Press Enter with an empty pattern to execute all tests in all files.') |
15
|
|
|
->emptyLine() |
16
|
|
|
->comment('Start typing to filter by file name.') |
17
|
|
|
->prompt('pattern > '); |
18
|
|
|
|
19
|
|
|
return $this; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function registerListeners() |
23
|
|
|
{ |
24
|
|
|
$this->registerDataListener(); |
25
|
|
|
|
26
|
|
|
$this->registerAutocompleter(); |
27
|
|
|
|
28
|
|
|
return $this; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
protected function registerDataListener() |
32
|
|
|
{ |
33
|
|
|
$this->terminal->on('data', function ($line) { |
34
|
|
|
if ($line == '') { |
35
|
|
|
$this->terminal->goBack(); |
36
|
|
|
|
37
|
|
|
return; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$phpunitArguments = "{$line}"; |
41
|
|
|
|
42
|
|
|
$phpunitScreen = $this->terminal->getPreviousScreen(); |
43
|
|
|
|
44
|
|
|
$options = $phpunitScreen->options; |
|
|
|
|
45
|
|
|
|
46
|
|
|
$options['phpunit']['arguments'] = $phpunitArguments; |
47
|
|
|
|
48
|
|
|
$this->terminal->displayScreen(new Phpunit($options)); |
49
|
|
|
}); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
protected function registerAutocompleter() |
53
|
|
|
{ |
54
|
|
|
$readline = $this->terminal->getReadline(); |
55
|
|
|
|
56
|
|
|
$filenameAutocompleter = new FilenameCompleter($readline); |
57
|
|
|
|
58
|
|
|
$filenameAutocompleter->onSuggestions(function ($suggestions) { |
59
|
|
|
$this->refreshScreenWithSuggestions($suggestions, 10); |
60
|
|
|
}); |
61
|
|
|
|
62
|
|
|
$readline->setAutocomplete($filenameAutocompleter); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
protected function refreshScreenWithSuggestions($suggestions, $limit) |
66
|
|
|
{ |
67
|
|
|
$firstSuggestions = array_slice($suggestions, 0 , $limit); |
68
|
|
|
|
69
|
|
|
$this->terminal->refreshScreen(); |
70
|
|
|
|
71
|
|
|
$stdio = $this->terminal->getStdio(); |
72
|
|
|
|
73
|
|
|
$stdio->write("\n" . implode("\n", $firstSuggestions) . "\n"); |
74
|
|
|
|
75
|
|
|
$count = count($suggestions) - $limit; |
76
|
|
|
if ($count > 0) { |
77
|
|
|
$stdio->write("(+$count others)\n"); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$stdio->write("\n"); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.