1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\PhpUnitWatcher\Screens; |
4
|
|
|
|
5
|
|
|
class FilterFileName extends Screen |
6
|
|
|
{ |
7
|
|
|
public function draw() |
8
|
|
|
{ |
9
|
|
|
$this->terminal |
10
|
|
|
->comment('Pattern mode usage') |
11
|
|
|
->write('Type a pattern and press Enter to only run tests in the giving path or file.') |
12
|
|
|
->write('Press Enter with an empty pattern to execute all tests in all files.') |
13
|
|
|
->emptyLine() |
14
|
|
|
->comment('Start typing to filter by a test name.') |
15
|
|
|
->prompt('pattern > '); |
16
|
|
|
|
17
|
|
|
return $this; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function registerListeners() |
21
|
|
|
{ |
22
|
|
|
$readline = $this->terminal->getReadline(); |
23
|
|
|
|
24
|
|
|
$this->terminal->on('data', function ($line) { |
25
|
|
|
if ($line == '') { |
26
|
|
|
$this->terminal->goBack(); |
27
|
|
|
|
28
|
|
|
return; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$phpunitArguments = "{$line}"; |
32
|
|
|
|
33
|
|
|
$phpunitScreen = $this->terminal->getPreviousScreen(); |
34
|
|
|
|
35
|
|
|
$options = $phpunitScreen->options; |
|
|
|
|
36
|
|
|
|
37
|
|
|
$options['phpunit']['arguments'] = $phpunitArguments; |
38
|
|
|
|
39
|
|
|
$this->terminal->displayScreen(new Phpunit($options)); |
40
|
|
|
}); |
41
|
|
|
|
42
|
|
|
$this->registerAutocompleter($readline); |
43
|
|
|
|
44
|
|
|
return $this; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
protected function registerAutocompleter($readline) |
48
|
|
|
{ |
49
|
|
|
$readline->setAutocomplete(function ($word, $startOffset, $endOffset) use ($readline) { |
50
|
|
|
$input = $readline->getInput(); |
51
|
|
|
|
52
|
|
|
$paths = glob("$word*", GLOB_MARK); |
53
|
|
|
|
54
|
|
|
if (empty($paths)) { |
55
|
|
|
return; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
if (count($paths) > 1) { |
59
|
|
|
$this->terminal->getStdio()->write(implode(' ', $paths)."\n"); |
60
|
|
|
|
61
|
|
|
return; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$path = $paths[0]; |
65
|
|
|
|
66
|
|
|
$lineStart = mb_substr($input, 0, $startOffset); |
67
|
|
|
$lineEnd = mb_substr($input, $endOffset); |
68
|
|
|
|
69
|
|
|
$path = $this->sanitzeOffset($startOffset, $path, $input); |
70
|
|
|
|
71
|
|
|
$newInput = $lineStart.$path.$lineEnd; |
72
|
|
|
|
73
|
|
|
$readline->setInput($newInput); |
74
|
|
|
|
75
|
|
|
$readline->moveCursorTo($startOffset + mb_strlen($path)); |
76
|
|
|
}); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
protected function sanitzeOffset($startOffset, $path, $input): string |
80
|
|
|
{ |
81
|
|
|
if ($startOffset > 0 && mb_strlen($path) > 1 && mb_substr($path, -1) != DIRECTORY_SEPARATOR) { |
82
|
|
|
$previousChar = mb_substr($input, $startOffset - 1, 1); |
83
|
|
|
if ($previousChar === '"' || $previousChar === '\'') { |
84
|
|
|
$path .= $previousChar; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $path; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
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.