From c88d461efdf8d17479cbf41517d9a63b2032db43 Mon Sep 17 00:00:00 2001 From: Yuya Takeyama Date: Sun, 13 Oct 2013 18:52:28 +0900 Subject: [PATCH 1/6] Fix link to COMPOSER_HOME --- doc/03-cli.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 5ae5963acd0dcb8dfe0c6d8611f33d6e90b04c84 Mon Sep 17 00:00:00 2001 From: Fabian Grutschus Date: Mon, 14 Oct 2013 14:53:57 +0200 Subject: [PATCH 2/6] 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() { From 67083e436bb8924869039d7cbe2f5ba8a8ad5ebc Mon Sep 17 00:00:00 2001 From: Fabian Grutschus Date: Mon, 14 Oct 2013 15:07:35 +0200 Subject: [PATCH 3/6] Check for exit code is equal to 0 instead of 127 --- src/Composer/Util/Perforce.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index dc09a5066..663f58be3 100644 --- a/src/Composer/Util/Perforce.php +++ b/src/Composer/Util/Perforce.php @@ -370,7 +370,7 @@ class Perforce $result = ''; $exitCode = $processExecutor->execute('p4 -p ' . $url . ' info -s', $result); - return false === strpos($result, 'error') && 127 != $exitCode; + return false === strpos($result, 'error') && 0 == $exitCode; } public function getComposerInformation($identifier) From 0c5bd559f27a90facb077c849558a27f1f74d03f Mon Sep 17 00:00:00 2001 From: Fabian Grutschus Date: Mon, 14 Oct 2013 17:25:57 +0200 Subject: [PATCH 4/6] Changes comparsion to strict and removed a comment --- src/Composer/Util/Perforce.php | 2 +- tests/Composer/Test/Util/PerforceTest.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index 663f58be3..2ae771345 100644 --- a/src/Composer/Util/Perforce.php +++ b/src/Composer/Util/Perforce.php @@ -370,7 +370,7 @@ class Perforce $result = ''; $exitCode = $processExecutor->execute('p4 -p ' . $url . ' info -s', $result); - return false === strpos($result, 'error') && 0 == $exitCode; + return false === strpos($result, 'error') && 0 === $exitCode; } public function getComposerInformation($identifier) diff --git a/tests/Composer/Test/Util/PerforceTest.php b/tests/Composer/Test/Util/PerforceTest.php index 517c85a75..ffd0ab321 100644 --- a/tests/Composer/Test/Util/PerforceTest.php +++ b/tests/Composer/Test/Util/PerforceTest.php @@ -646,7 +646,6 @@ class PerforceTest extends \PHPUnit_Framework_TestCase $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); From 20854a50b4dd63191dc0d96a2ea84691b5507f1e Mon Sep 17 00:00:00 2001 From: Fabian Grutschus Date: Mon, 14 Oct 2013 18:04:09 +0200 Subject: [PATCH 5/6] Removed unnecessary test and just check for return code --- src/Composer/Util/Perforce.php | 5 +---- tests/Composer/Test/Util/PerforceTest.php | 17 ++--------------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index 2ae771345..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 = ''; - $exitCode = $processExecutor->execute('p4 -p ' . $url . ' info -s', $result); - - return false === strpos($result, 'error') && 0 === $exitCode; + return 0 === $processExecutor->execute('p4 -p ' . $url . ' info -s'); } public function getComposerInformation($identifier) diff --git a/tests/Composer/Test/Util/PerforceTest.php b/tests/Composer/Test/Util/PerforceTest.php index ffd0ab321..f2eeb1964 100644 --- a/tests/Composer/Test/Util/PerforceTest.php +++ b/tests/Composer/Test/Util/PerforceTest.php @@ -617,20 +617,6 @@ class PerforceTest extends \PHPUnit_Framework_TestCase $result = $this->perforce->checkServerExists('perforce.does.exist:port', $processExecutor); $this->assertTrue($result); } - - public function testCheckServerExistsWithFailure() - { - $processExecutor = $this->getMock('Composer\Util\ProcessExecutor'); - - $expectedCommand = 'p4 -p perforce.does.not.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); - } /** * Test if "p4" command is missing. @@ -639,13 +625,14 @@ class PerforceTest extends \PHPUnit_Framework_TestCase * * @return void */ - public function testCheckServerExistsWithMissingPerforceClient() + public function testCheckServerClientError() { $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); From a6823d2f9b62d4e2244eee6d12da1ef0fc44502b Mon Sep 17 00:00:00 2001 From: Fabian Grutschus Date: Wed, 16 Oct 2013 10:07:10 +0200 Subject: [PATCH 6/6] non-deep check returns allways false --- src/Composer/Repository/Vcs/PerforceDriver.php | 4 ++++ .../Test/Repository/Vcs/PerforceDriverTest.php | 13 +++++++++++++ 2 files changed, 17 insertions(+) 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/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')); + } }