1 | <?php |
||
8 | class Phpunit extends Screen |
||
9 | { |
||
10 | const DEFAULT_BINARY_PATH = 'vendor/bin/phpunit'; |
||
11 | |||
12 | /** @var array */ |
||
13 | public $options; |
||
14 | |||
15 | /** @var string */ |
||
16 | protected $phpunitArguments; |
||
17 | |||
18 | /** @var string */ |
||
19 | private $phpunitBinaryPath; |
||
20 | |||
21 | public function __construct(array $options) |
||
29 | |||
30 | public function draw(array $changedFilePaths = []) |
||
45 | |||
46 | public function registerListeners() |
||
87 | |||
88 | protected function writeHeader() |
||
102 | |||
103 | protected function runTests() |
||
115 | |||
116 | protected function displayManual() |
||
134 | |||
135 | protected function sendDesktopNotification(int $result) |
||
145 | |||
146 | public function determineAutoFilter(array $changedFilePaths = []) |
||
147 | { |
||
148 | $autoFilterOption = null; |
||
149 | $this->phpunitArguments = isset($this->options['phpunit']['arguments']) ? $this->options['phpunit']['arguments'] : ''; |
||
150 | |||
151 | // Apply a filter based on the changed files |
||
152 | if (!empty($changedFilePaths)) { |
||
153 | |||
154 | $testNames = array_map(function($filePath) { |
||
155 | |||
156 | $filePathParts = explode('/', $filePath); |
||
157 | $fileName = end($filePathParts); |
||
158 | $fileNameParts = explode('.', $fileName); |
||
159 | |||
160 | $testName = current($fileNameParts); |
||
161 | |||
162 | // Suffix with "Test" if it's not already a test |
||
163 | $strlen = strlen($testName); |
||
164 | if ($strlen < 4 || !(substr_compare(strtolower($testName), 'test', $strlen - 4, 4) === 0)) { |
||
165 | $testName .= 'Test'; |
||
166 | } |
||
167 | |||
168 | return $testName; |
||
169 | }, $changedFilePaths); |
||
170 | |||
171 | $testFilterPattern = '/(' . implode('|', $testNames) . ')/'; |
||
172 | $autoFilterOption = " --filter=\"$testFilterPattern\""; |
||
173 | |||
174 | $this->phpunitArguments .= $autoFilterOption; |
||
175 | } |
||
176 | |||
177 | return $this; |
||
178 | } |
||
179 | |||
180 | public function getPhpunitArguments() |
||
184 | } |
||
185 |
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.