Browse Source

Merge remote-tracking branch 'fabiang/preforce'

Jordi Boggiano 11 years ago
parent
commit
a3e304028c

+ 1 - 1
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

+ 4 - 0
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);
     }
 

+ 1 - 4
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)

+ 13 - 0
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'));
+    }
 }

+ 14 - 7
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()