From 692c63cdd2c314db8eaf6bbfab742f5d730b4ae9 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Thu, 25 Apr 2013 14:57:58 -0400 Subject: [PATCH] Fix for tests when Mercurial or git are not available --- .../Archiver/ArchivableFilesFinderTest.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/Composer/Test/Package/Archiver/ArchivableFilesFinderTest.php b/tests/Composer/Test/Package/Archiver/ArchivableFilesFinderTest.php index a621e71ee..2e5b9c415 100644 --- a/tests/Composer/Test/Package/Archiver/ArchivableFilesFinderTest.php +++ b/tests/Composer/Test/Package/Archiver/ArchivableFilesFinderTest.php @@ -101,6 +101,11 @@ class ArchivableFilesFinderTest extends \PHPUnit_Framework_TestCase public function testGitExcludes() { + // Ensure that git is available for testing. + if (!$this->getProcessAvailable('git')) { + return $this->markTestSkipped('git is not available.'); + } + file_put_contents($this->sources.'/.gitignore', implode("\n", array( '# gitignore rules with comments and blank lines', '', @@ -140,6 +145,10 @@ class ArchivableFilesFinderTest extends \PHPUnit_Framework_TestCase public function testHgExcludes() { + // Ensure that Mercurial is available for testing. + if (!$this->getProcessAvailable('hg')) { + return $this->markTestSkipped('Mercurial is not available.'); + } file_put_contents($this->sources.'/.hgignore', implode("\n", array( '# hgignore rules with comments, blank lines and syntax changes', '', @@ -206,4 +215,20 @@ class ArchivableFilesFinderTest extends \PHPUnit_Framework_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 boolean True if the process is available, false otherwise. + */ + protected function getProcessAvailable($process) + { + // Check if the command is found. The 127 exit code is returned when the + // command is not found. + $process = new Process($process); + + return $process->run() !== 127; + } }