1
0
Fork 0

Skip git-related tests if no git found.

pull/5990/head
AnrDaemon 2016-12-22 20:14:57 +03:00
parent 324c31f4a7
commit ab70601700
4 changed files with 33 additions and 23 deletions

View File

@ -25,6 +25,17 @@ class GitDownloaderTest extends TestCase
/** @var string */ /** @var string */
private $workingDir; 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() protected function setUp()
{ {
$this->fs = new Filesystem; $this->fs = new Filesystem;

View File

@ -16,7 +16,6 @@ use Composer\Package\Archiver\ArchivableFilesFinder;
use Composer\TestCase; use Composer\TestCase;
use Composer\Util\Filesystem; use Composer\Util\Filesystem;
use Symfony\Component\Process\Process; use Symfony\Component\Process\Process;
use Symfony\Component\Process\ExecutableFinder;
class ArchivableFilesFinderTest extends TestCase class ArchivableFilesFinderTest extends TestCase
{ {
@ -146,10 +145,7 @@ class ArchivableFilesFinderTest extends TestCase
public function testGitExcludes() public function testGitExcludes()
{ {
// Ensure that git is available for testing. $this->skipIfNotExecutable('git');
if (!$this->isProcessAvailable('git')) {
return $this->markTestSkipped('git is not available.');
}
file_put_contents($this->sources.'/.gitignore', implode("\n", array( file_put_contents($this->sources.'/.gitignore', implode("\n", array(
'# gitignore rules with comments and blank lines', '# gitignore rules with comments and blank lines',
@ -202,10 +198,7 @@ class ArchivableFilesFinderTest extends TestCase
public function testHgExcludes() public function testHgExcludes()
{ {
// Ensure that Mercurial is available for testing. $this->skipIfNotExecutable('hg');
if (!$this->isProcessAvailable('hg')) {
return $this->markTestSkipped('Mercurial is not available.');
}
file_put_contents($this->sources.'/.hgignore', implode("\n", array( file_put_contents($this->sources.'/.hgignore', implode("\n", array(
'# hgignore rules with comments, blank lines and syntax changes', '# hgignore rules with comments, blank lines and syntax changes',
@ -281,18 +274,4 @@ class ArchivableFilesFinderTest extends TestCase
$this->assertEquals($expectedFiles, $actualFiles); $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);
}
} }

View File

@ -45,6 +45,8 @@ class ArchiveManagerTest extends ArchiverTest
public function testArchiveTar() public function testArchiveTar()
{ {
$this->skipIfNotExecutable('git');
$this->setupGitRepo(); $this->setupGitRepo();
$package = $this->setupPackage(); $package = $this->setupPackage();
@ -62,6 +64,8 @@ class ArchiveManagerTest extends ArchiverTest
public function testArchiveCustomFileName() public function testArchiveCustomFileName()
{ {
$this->skipIfNotExecutable('git');
$this->setupGitRepo(); $this->setupGitRepo();
$package = $this->setupPackage(); $package = $this->setupPackage();

View File

@ -17,6 +17,7 @@ use Composer\Package\AliasPackage;
use Composer\Semver\Constraint\Constraint; use Composer\Semver\Constraint\Constraint;
use Composer\Util\Filesystem; use Composer\Util\Filesystem;
use Composer\Util\Silencer; use Composer\Util\Silencer;
use Symfony\Component\Process\ExecutableFinder;
abstract class TestCase extends \PHPUnit_Framework_TestCase abstract class TestCase extends \PHPUnit_Framework_TestCase
{ {
@ -83,4 +84,19 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
mkdir($directory, 0777, true); 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)
{
$finder = new ExecutableFinder();
if (!$finder->find($executableName))
$this->markTestSkipped($executableName . ' is not found or not executable.');
}
} }