Skip to content

Commit f51ca74

Browse files
committed
Skip tests when 'git' command is not available
This change is intended to be a quick-fix to allow the test suite to pass. A later enhancement would be to move this check to happen at runtime so that if a user attempts to use one of these affected filters, a suitable error message and exit code can be used. When that happens, the tests will need to be reworked to cover that functionality.
1 parent 038b4a1 commit f51ca74

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

tests/Core/Filters/AbstractFilterTestCase.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,4 +247,30 @@ protected static function mapPathsToRuntimeOs(array $paths)
247247
}//end mapPathsToRuntimeOs()
248248

249249

250+
/**
251+
* Mark the current test as 'skipped' if the 'git' command-line tool is not available.
252+
*
253+
* @return void
254+
*/
255+
protected function checkGitCommandAvailable()
256+
{
257+
static $result = null;
258+
259+
if (is_bool($result) === false) {
260+
if (strpos(PHP_OS, 'WIN') === 0) {
261+
$test = 'where';
262+
} else {
263+
$test = 'command -v';
264+
}
265+
266+
$result = is_executable(trim((string) shell_exec("$test git")));
267+
}
268+
269+
if ($result === false) {
270+
$this->markTestSkipped('git command not available');
271+
}
272+
273+
}//end checkGitCommandAvailable()
274+
275+
250276
}//end class

tests/Core/Filters/GitModifiedTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ public function testExecAlwaysReturnsArray($cmd, $expected)
219219
$this->markTestSkipped('Not a git repository');
220220
}
221221

222+
$this->checkGitCommandAvailable();
223+
222224
$fakeDI = new RecursiveArrayIterator(self::getFakeFileList());
223225
$filter = new GitModified($fakeDI, '/', self::$config, self::$ruleset);
224226

tests/Core/Filters/GitStagedTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ public function testExecAlwaysReturnsArray($cmd, $expected)
219219
$this->markTestSkipped('Not a git repository');
220220
}
221221

222+
$this->checkGitCommandAvailable();
223+
222224
$fakeDI = new RecursiveArrayIterator(self::getFakeFileList());
223225
$filter = new GitStaged($fakeDI, '/', self::$config, self::$ruleset);
224226

0 commit comments

Comments
 (0)