Skip to content

Commit 353bfde

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 c9858b6 commit 353bfde

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

tests/Core/Filters/GitModifiedTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace PHP_CodeSniffer\Tests\Core\Filters;
1111

12+
use PHP_CodeSniffer\Config;
1213
use PHP_CodeSniffer\Filters\GitModified;
1314
use PHP_CodeSniffer\Tests\Core\Filters\AbstractFilterTestCase;
1415
use RecursiveArrayIterator;
@@ -219,6 +220,10 @@ public function testExecAlwaysReturnsArray($cmd, $expected)
219220
$this->markTestSkipped('Not a git repository');
220221
}
221222

223+
if (Config::getExecutablePath('git') === null) {
224+
$this->markTestSkipped('git command not available');
225+
}
226+
222227
$fakeDI = new RecursiveArrayIterator(self::getFakeFileList());
223228
$filter = new GitModified($fakeDI, '/', self::$config, self::$ruleset);
224229

tests/Core/Filters/GitStagedTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace PHP_CodeSniffer\Tests\Core\Filters;
1111

12+
use PHP_CodeSniffer\Config;
1213
use PHP_CodeSniffer\Filters\GitStaged;
1314
use PHP_CodeSniffer\Tests\Core\Filters\AbstractFilterTestCase;
1415
use RecursiveArrayIterator;
@@ -219,6 +220,10 @@ public function testExecAlwaysReturnsArray($cmd, $expected)
219220
$this->markTestSkipped('Not a git repository');
220221
}
221222

223+
if (Config::getExecutablePath('git') === null) {
224+
$this->markTestSkipped('git command not available');
225+
}
226+
222227
$fakeDI = new RecursiveArrayIterator(self::getFakeFileList());
223228
$filter = new GitStaged($fakeDI, '/', self::$config, self::$ruleset);
224229

0 commit comments

Comments
 (0)