diff --git a/doc/03-cli.md b/doc/03-cli.md index 4202c75eb..267d19893 100644 --- a/doc/03-cli.md +++ b/doc/03-cli.md @@ -151,7 +151,7 @@ to the command. ## global The global command allows you to run other commands like `install`, `require` -or `update` as if you were running them from the [COMPOSER_HOME](#COMPOSER_HOME) +or `update` as if you were running them from the [COMPOSER_HOME](#composer-home) directory. This can be used to install CLI utilities globally and if you add diff --git a/src/Composer/Repository/Vcs/PerforceDriver.php b/src/Composer/Repository/Vcs/PerforceDriver.php index a6d52bfb6..af20c4667 100644 --- a/src/Composer/Repository/Vcs/PerforceDriver.php +++ b/src/Composer/Repository/Vcs/PerforceDriver.php @@ -160,6 +160,10 @@ class PerforceDriver extends VcsDriver */ public static function supports(IOInterface $io, $url, $deep = false) { + if (false === $deep) { + return false; + } + return Perforce::checkServerExists($url, new ProcessExecutor); } diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index 5237e3420..5bb368575 100644 --- a/src/Composer/Util/Perforce.php +++ b/src/Composer/Util/Perforce.php @@ -367,10 +367,7 @@ class Perforce public static function checkServerExists($url, ProcessExecutor $processExecutor) { - $result = ''; - $processExecutor->execute('p4 -p ' . $url . ' info -s', $result); - - return false === strpos($result, 'error'); + return 0 === $processExecutor->execute('p4 -p ' . $url . ' info -s'); } public function getComposerInformation($identifier) diff --git a/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php b/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php index 277550e64..d2c8167b9 100644 --- a/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php @@ -131,4 +131,17 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase $result = $driver->hasComposerFile($identifier); $this->assertTrue($result); } + + /** + * Test that supports() simply return false. + * + * @covers \Composer\Repository\Vcs\PerforceDriver::supports + * + * @return void + */ + public function testSupportsReturnsFalseNoDeepCheck() + { + $this->expectOutputString(''); + $this->assertFalse(PerforceDriver::supports($this->io, 'existing.url')); + } } diff --git a/tests/Composer/Test/Util/PerforceTest.php b/tests/Composer/Test/Util/PerforceTest.php index 6f72713bb..f2eeb1964 100644 --- a/tests/Composer/Test/Util/PerforceTest.php +++ b/tests/Composer/Test/Util/PerforceTest.php @@ -617,19 +617,26 @@ class PerforceTest extends \PHPUnit_Framework_TestCase $result = $this->perforce->checkServerExists('perforce.does.exist:port', $processExecutor); $this->assertTrue($result); } - - public function testCheckServerExistsWithFailure() + + /** + * Test if "p4" command is missing. + * + * @covers \Composer\Util\Perforce::checkServerExists + * + * @return void + */ + public function testCheckServerClientError() { $processExecutor = $this->getMock('Composer\Util\ProcessExecutor'); - $expectedCommand = 'p4 -p perforce.does.not.exist:port info -s'; + $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('Perforce client error:')); - - $result = $this->perforce->checkServerExists('perforce.does.not.exist:port', $processExecutor); - $this->assertTrue($result); + ->will($this->returnValue(127)); + + $result = $this->perforce->checkServerExists('perforce.does.exist:port', $processExecutor); + $this->assertFalse($result); } public static function getComposerJson()