Merge pull request #5990 from AnrDaemon/fix-git-skips
Skip git-related tests if no git found.pull/5991/head
commit
4896d16817
|
@ -25,6 +25,17 @@ class GitDownloaderTest extends TestCase
|
|||
/** @var string */
|
||||
private $workingDir;
|
||||
|
||||
private $skipped;
|
||||
|
||||
protected function initialize()
|
||||
{
|
||||
try {
|
||||
$this->skipIfNotExecutable('git');
|
||||
} catch (\PHPUnit_Framework_SkippedTestError $e) {
|
||||
$this->skipped = 'This test needs a git binary in the PATH to be able to run';
|
||||
}
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->fs = new Filesystem;
|
||||
|
|
|
@ -16,7 +16,6 @@ use Composer\Package\Archiver\ArchivableFilesFinder;
|
|||
use Composer\TestCase;
|
||||
use Composer\Util\Filesystem;
|
||||
use Symfony\Component\Process\Process;
|
||||
use Symfony\Component\Process\ExecutableFinder;
|
||||
|
||||
class ArchivableFilesFinderTest extends TestCase
|
||||
{
|
||||
|
@ -146,10 +145,7 @@ class ArchivableFilesFinderTest extends TestCase
|
|||
|
||||
public function testGitExcludes()
|
||||
{
|
||||
// Ensure that git is available for testing.
|
||||
if (!$this->isProcessAvailable('git')) {
|
||||
return $this->markTestSkipped('git is not available.');
|
||||
}
|
||||
$this->skipIfNotExecutable('git');
|
||||
|
||||
file_put_contents($this->sources.'/.gitignore', implode("\n", array(
|
||||
'# gitignore rules with comments and blank lines',
|
||||
|
@ -202,10 +198,7 @@ class ArchivableFilesFinderTest extends TestCase
|
|||
|
||||
public function testHgExcludes()
|
||||
{
|
||||
// Ensure that Mercurial is available for testing.
|
||||
if (!$this->isProcessAvailable('hg')) {
|
||||
return $this->markTestSkipped('Mercurial is not available.');
|
||||
}
|
||||
$this->skipIfNotExecutable('hg');
|
||||
|
||||
file_put_contents($this->sources.'/.hgignore', implode("\n", array(
|
||||
'# hgignore rules with comments, blank lines and syntax changes',
|
||||
|
@ -281,18 +274,4 @@ class ArchivableFilesFinderTest extends TestCase
|
|||
|
||||
$this->assertEquals($expectedFiles, $actualFiles);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether or not the given process is available.
|
||||
*
|
||||
* @param string $process The name of the binary to test.
|
||||
*
|
||||
* @return bool True if the process is available, false otherwise.
|
||||
*/
|
||||
protected function isProcessAvailable($process)
|
||||
{
|
||||
$finder = new ExecutableFinder();
|
||||
|
||||
return (bool) $finder->find($process);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,6 +45,8 @@ class ArchiveManagerTest extends ArchiverTest
|
|||
|
||||
public function testArchiveTar()
|
||||
{
|
||||
$this->skipIfNotExecutable('git');
|
||||
|
||||
$this->setupGitRepo();
|
||||
|
||||
$package = $this->setupPackage();
|
||||
|
@ -62,6 +64,8 @@ class ArchiveManagerTest extends ArchiverTest
|
|||
|
||||
public function testArchiveCustomFileName()
|
||||
{
|
||||
$this->skipIfNotExecutable('git');
|
||||
|
||||
$this->setupGitRepo();
|
||||
|
||||
$package = $this->setupPackage();
|
||||
|
|
|
@ -17,10 +17,12 @@ use Composer\Package\AliasPackage;
|
|||
use Composer\Semver\Constraint\Constraint;
|
||||
use Composer\Util\Filesystem;
|
||||
use Composer\Util\Silencer;
|
||||
use Symfony\Component\Process\ExecutableFinder;
|
||||
|
||||
abstract class TestCase extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private static $parser;
|
||||
private static $executableCache = array();
|
||||
|
||||
public static function getUniqueTmpDirectory()
|
||||
{
|
||||
|
@ -83,4 +85,23 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
|
|||
|
||||
mkdir($directory, 0777, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether or not the given name is an available executable.
|
||||
*
|
||||
* @param string $executableName The name of the binary to test.
|
||||
*
|
||||
* @throws PHPUnit_Framework_SkippedTestError
|
||||
*/
|
||||
protected function skipIfNotExecutable($executableName)
|
||||
{
|
||||
if (!isset(self::$executableCache[$executableName])) {
|
||||
$finder = new ExecutableFinder();
|
||||
self::$executableCache[$executableName] = (bool) $finder->find($executableName);
|
||||
}
|
||||
|
||||
if (false === self::$executableCache[$executableName]) {
|
||||
$this->markTestSkipped($executableName . ' is not found or not executable.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue