From 5ae5963acd0dcb8dfe0c6d8611f33d6e90b04c84 Mon Sep 17 00:00:00 2001 From: Fabian Grutschus Date: Mon, 14 Oct 2013 14:53:57 +0200 Subject: [PATCH] Fix for Preforce utility does not check if p4 command exists --- src/Composer/Util/Perforce.php | 4 ++-- tests/Composer/Test/Util/PerforceTest.php | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index 5237e3420..dc09a5066 100644 --- a/src/Composer/Util/Perforce.php +++ b/src/Composer/Util/Perforce.php @@ -368,9 +368,9 @@ class Perforce public static function checkServerExists($url, ProcessExecutor $processExecutor) { $result = ''; - $processExecutor->execute('p4 -p ' . $url . ' info -s', $result); + $exitCode = $processExecutor->execute('p4 -p ' . $url . ' info -s', $result); - return false === strpos($result, 'error'); + return false === strpos($result, 'error') && 127 != $exitCode; } public function getComposerInformation($identifier) diff --git a/tests/Composer/Test/Util/PerforceTest.php b/tests/Composer/Test/Util/PerforceTest.php index 6f72713bb..517c85a75 100644 --- a/tests/Composer/Test/Util/PerforceTest.php +++ b/tests/Composer/Test/Util/PerforceTest.php @@ -631,6 +631,27 @@ class PerforceTest extends \PHPUnit_Framework_TestCase $result = $this->perforce->checkServerExists('perforce.does.not.exist:port', $processExecutor); $this->assertTrue($result); } + + /** + * Test if "p4" command is missing. + * + * @covers \Composer\Util\Perforce::checkServerExists + * + * @return void + */ + public function testCheckServerExistsWithMissingPerforceClient() + { + $processExecutor = $this->getMock('Composer\Util\ProcessExecutor'); + + $expectedCommand = 'p4 -p perforce.does.exist:port info -s'; + $processExecutor->expects($this->at(0)) + ->method('execute') + //->with($this->equalTo($expectedCommand), $this->equalTo(null)) + ->will($this->returnValue(127)); + + $result = $this->perforce->checkServerExists('perforce.does.exist:port', $processExecutor); + $this->assertFalse($result); + } public static function getComposerJson() {