From 454c6eca81d818b51bb58ceb4c03f10c403630e5 Mon Sep 17 00:00:00 2001 From: Clark Stuth Date: Fri, 14 Mar 2014 14:45:31 -0500 Subject: [PATCH 01/16] added new dependency to Perforce object, updating some tests. --- .../Downloader/PerforceDownloader.php | 4 +- .../Repository/Vcs/PerforceDriver.php | 2 +- src/Composer/Util/Perforce.php | 21 ++- .../Downloader/PerforceDownloaderTest.php | 160 +++++++++++------- tests/Composer/Test/Util/PerforceTest.php | 11 +- 5 files changed, 122 insertions(+), 76 deletions(-) diff --git a/src/Composer/Downloader/PerforceDownloader.php b/src/Composer/Downloader/PerforceDownloader.php index 2bb1ba619..632ac648c 100644 --- a/src/Composer/Downloader/PerforceDownloader.php +++ b/src/Composer/Downloader/PerforceDownloader.php @@ -22,7 +22,7 @@ use Composer\Util\Perforce; class PerforceDownloader extends VcsDownloader { protected $perforce; - protected $perforceInjected = false; +// protected $perforceInjected = false; /** * {@inheritDoc} @@ -54,7 +54,7 @@ class PerforceDownloader extends VcsDownloader if ($repository instanceof VcsRepository) { $repoConfig = $this->getRepoConfig($repository); } - $this->perforce = Perforce::create($repoConfig, $package->getSourceUrl(), $path); + $this->perforce = Perforce::create($repoConfig, $package->getSourceUrl(), $path, $this->process, $this->io); } private function getRepoConfig(VcsRepository $repository) diff --git a/src/Composer/Repository/Vcs/PerforceDriver.php b/src/Composer/Repository/Vcs/PerforceDriver.php index 79500f1d6..8a1b40623 100644 --- a/src/Composer/Repository/Vcs/PerforceDriver.php +++ b/src/Composer/Repository/Vcs/PerforceDriver.php @@ -56,7 +56,7 @@ class PerforceDriver extends VcsDriver } $repoDir = $this->config->get('cache-vcs-dir') . '/' . $this->depot; - $this->perforce = Perforce::create($repoConfig, $this->getUrl(), $repoDir, $this->process); + $this->perforce = Perforce::create($repoConfig, $this->getUrl(), $repoDir, $this->process, $this->io); } /** diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index 94b9730eb..c3b66329f 100644 --- a/src/Composer/Util/Perforce.php +++ b/src/Composer/Util/Perforce.php @@ -35,27 +35,36 @@ class Perforce protected $windowsFlag; protected $commandResult; - public function __construct($repoConfig, $port, $path, ProcessExecutor $process, $isWindows) + protected $io; + + public function __construct($repoConfig, $port, $path, ProcessExecutor $process, $isWindows, IOInterface $io) { $this->windowsFlag = $isWindows; $this->p4Port = $port; $this->initializePath($path); $this->process = $process; $this->initialize($repoConfig); + $this->io = $io; } - public static function create($repoConfig, $port, $path, ProcessExecutor $process = null) + public static function create($repoConfig, $port, $path, ProcessExecutor $process = null, IOInterface $io) { if (!isset($process)) { $process = new ProcessExecutor; } $isWindows = defined('PHP_WINDOWS_VERSION_BUILD'); - $perforce = new Perforce($repoConfig, $port, $path, $process, $isWindows); + $perforce = new Perforce($repoConfig, $port, $path, $process, $isWindows, $io); return $perforce; } + public static function checkServerExists($url, ProcessExecutor $processExecutor) + { + $output = null; + return 0 === $processExecutor->execute('p4 -p ' . $url . ' info -s', $output); + } + public function initialize($repoConfig) { $this->uniquePerforceClientName = $this->generateUniquePerforceClientName(); @@ -382,12 +391,6 @@ class Perforce } } - public static function checkServerExists($url, ProcessExecutor $processExecutor) - { - $output = null; - return 0 === $processExecutor->execute('p4 -p ' . $url . ' info -s', $output); - } - public function getComposerInformation($identifier) { $index = strpos($identifier, '@'); diff --git a/tests/Composer/Test/Downloader/PerforceDownloaderTest.php b/tests/Composer/Test/Downloader/PerforceDownloaderTest.php index 8a20f67cc..0eb981362 100644 --- a/tests/Composer/Test/Downloader/PerforceDownloaderTest.php +++ b/tests/Composer/Test/Downloader/PerforceDownloaderTest.php @@ -15,86 +15,120 @@ namespace Composer\Test\Downloader; use Composer\Downloader\PerforceDownloader; use Composer\Config; use Composer\Repository\VcsRepository; +use Composer\IO\IOInterface; /** * @author Matt Whittom */ class PerforceDownloaderTest extends \PHPUnit_Framework_TestCase { - private $io; - private $config; - private $testPath; - public static $repository; + + protected $config; + protected $downloader; + protected $io; + protected $package; + protected $processExecutor; + protected $repoConfig; + protected $repository; + protected $testPath; - protected function setUp() + public function setUp() { - $this->testPath = sys_get_temp_dir() . '/composer-test'; - $this->config = new Config(); - $this->config->merge( - array( - 'config' => array( - 'home' => $this->testPath, - ), - ) - ); - $this->io = $this->getMock('Composer\IO\IOInterface'); + $this->testPath = sys_get_temp_dir() . '/composer-test'; + $this->repoConfig = $this->getRepoConfig(); + $this->config = $this->getConfig(); + $this->io = $this->getMockIoInterface(); + $this->processExecutor = $this->getMockProcessExecutor(); + $this->repository = $this->getMockRepository($this->repoConfig, $this->io, $this->config); + $this->package = $this->getMockPackageInterface($this->repository); + $this->downloader = new PerforceDownloader($this->io, $this->config, $this->processExecutor); } - public function testInitPerforceGetRepoConfig() + public function tearDown() + { + $this->downloader = null; + $this->package = null; + $this->repository = null; + $this->io = null; + $this->config = null; + $this->repoConfig = null; + $this->testPath = null; + } + + protected function getMockProcessExecutor() + { + return $this->getMock('Composer\Util\ProcessExecutor'); + } + + protected function getConfig() + { + $config = new Config(); + $settings = array('config' => array('home' => $this->testPath)); + $config->merge($settings); + return $config; + } + + protected function getMockIoInterface() + { + return $this->getMock('Composer\IO\IOInterface'); + } + + protected function getMockPackageInterface(VcsRepository $repository) { - $downloader = new PerforceDownloader($this->io, $this->config); $package = $this->getMock('Composer\Package\PackageInterface'); - $repoConfig = array('url' => 'TEST_URL', 'p4user' => 'TEST_USER'); - $repository = $this->getMock( - 'Composer\Repository\VcsRepository', - array('getRepoConfig'), - array($repoConfig, $this->io, $this->config) - ); - $package->expects($this->at(0)) - ->method('getRepository') - ->will($this->returnValue($repository)); - $repository->expects($this->at(0)) - ->method('getRepoConfig'); - $path = $this->testPath; - $downloader->initPerforce($package, $path, 'SOURCE_REF'); + $package->expects($this->any())->method('getRepository')->will($this->returnValue($repository)); + return $package; } + protected function getRepoConfig() + { + return array('url' => 'TEST_URL', 'p4user' => 'TEST_USER'); + } + + protected function getMockRepository(array $repoConfig, IOInterface $io, Config $config) + { + $class = 'Composer\Repository\VcsRepository'; + $methods = array('getRepoConfig'); + $args = array($repoConfig, $io, $config); + $repository = $this->getMock($class, $methods, $args); + $repository->expects($this->any())->method('getRepoConfig')->will($this->returnValue($repoConfig)); + return $repository; + } + + public function testInitPerforceInstantiatesANewPerforceObject() + { + $this->downloader->initPerforce($this->package, $this->testPath, 'SOURCE_REF'); + } + + public function testInitPerforceDoesNothingIfPerforceAlreadySet() + { + $perforce = $this->getMockBuilder('Composer\Util\Perforce')->disableOriginalConstructor()->getMock(); + $this->downloader->setPerforce($perforce); + $this->repository->expects($this->never())->method('getRepoConfig'); + $this->downloader->initPerforce($this->package, $this->testPath, 'SOURCE_REF'); + } + + /** + * @depends testInitPerforceInstantiatesANewPerforceObject + * @depends testInitPerforceDoesNothingIfPerforceAlreadySet + */ public function testDoDownload() { - $downloader = new PerforceDownloader($this->io, $this->config); - $repoConfig = array('depot' => 'TEST_DEPOT', 'branch' => 'TEST_BRANCH', 'p4user' => 'TEST_USER'); - $port = 'TEST_PORT'; - $path = 'TEST_PATH'; - $process = $this->getmock('Composer\Util\ProcessExecutor'); - $perforce = $this->getMock( - 'Composer\Util\Perforce', - array('setStream', 'queryP4User', 'writeP4ClientSpec', 'connectClient', 'syncCodeBase'), - array($repoConfig, $port, $path, $process, true, 'TEST') - ); + //I really don't like this test but the logic of each Perforce method is tested in the Perforce class. Really I am just enforcing workflow. $ref = 'SOURCE_REF'; $label = 'LABEL'; - $perforce->expects($this->at(0)) - ->method('setStream') - ->with($this->equalTo($ref)); - $perforce->expects($this->at(1)) - ->method('queryP4User') - ->with($this->io); - $perforce->expects($this->at(2)) - ->method('writeP4ClientSpec'); - $perforce->expects($this->at(3)) - ->method('connectClient'); - $perforce->expects($this->at(4)) - ->method('syncCodeBase') - ->with($this->equalTo($label)); - $downloader->setPerforce($perforce); - $package = $this->getMock('Composer\Package\PackageInterface'); - $package->expects($this->at(0)) - ->method('getSourceReference') - ->will($this->returnValue($ref)); - $package->expects($this->at(1)) - ->method('getPrettyVersion') - ->will($this->returnValue($label)); - $path = $this->testPath; - $downloader->doDownload($package, $path); + $this->package->expects($this->once())->method('getSourceReference')->will($this->returnValue($ref)); + $this->package->expects($this->once())->method('getPrettyVersion')->will($this->returnValue($label)); + $this->io->expects($this->once())->method('write')->with($this->stringContains('Cloning '.$ref)); + $perforceMethods = array('setStream', 'p4Login', 'writeP4ClientSpec', 'connectClient', 'syncCodeBase', 'cleanupClientSpec'); + $perforce = $this->getMockBuilder('Composer\Util\Perforce', $perforceMethods)->disableOriginalConstructor()->getMock(); + $perforce->expects($this->at(0))->method('setStream')->with($this->equalTo($ref)); + $perforce->expects($this->at(1))->method('p4Login')->with($this->identicalTo($this->io)); + $perforce->expects($this->at(2))->method('writeP4ClientSpec'); + $perforce->expects($this->at(3))->method('connectClient'); + $perforce->expects($this->at(4))->method('syncCodeBase'); + $perforce->expects($this->at(5))->method('cleanupClientSpec'); + $this->downloader->setPerforce($perforce); + $this->downloader->doDownload($this->package, $this->testPath); } } diff --git a/tests/Composer/Test/Util/PerforceTest.php b/tests/Composer/Test/Util/PerforceTest.php index f2eeb1964..56a234536 100644 --- a/tests/Composer/Test/Util/PerforceTest.php +++ b/tests/Composer/Test/Util/PerforceTest.php @@ -22,6 +22,7 @@ class PerforceTest extends \PHPUnit_Framework_TestCase { protected $perforce; protected $processExecutor; + protected $io; public function setUp() { @@ -32,7 +33,15 @@ class PerforceTest extends \PHPUnit_Framework_TestCase 'p4user' => 'user', 'unique_perforce_client_name' => 'TEST' ); - $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, true); + $io = $this->getMock('Composer\IO\IOInterface'); + $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, true, $io); + } + + public function tearDown() + { + $this->perforce = null; + $this->io = null; + $this->processExecutor = null; } public function testGetClientWithoutStream() From 34a68f4020e0b7cc3317c0f747c7738acd4d27e9 Mon Sep 17 00:00:00 2001 From: Clark Stuth Date: Mon, 17 Mar 2014 16:06:19 -0500 Subject: [PATCH 02/16] almost all unit tests passing after IOInterface dependency refactor. no longer passing IOInterface into any Perforce methods --- .../Downloader/PerforceDownloader.php | 2 +- .../Repository/Vcs/PerforceDriver.php | 8 +- src/Composer/Util/Perforce.php | 29 ++- .../Downloader/PerforceDownloaderTest.php | 13 +- .../Repository/Vcs/PerforceDriverTest.php | 186 +++++++------- tests/Composer/Test/Util/PerforceTest.php | 230 ++++++++---------- 6 files changed, 239 insertions(+), 229 deletions(-) diff --git a/src/Composer/Downloader/PerforceDownloader.php b/src/Composer/Downloader/PerforceDownloader.php index 632ac648c..da70c3469 100644 --- a/src/Composer/Downloader/PerforceDownloader.php +++ b/src/Composer/Downloader/PerforceDownloader.php @@ -44,7 +44,7 @@ class PerforceDownloader extends VcsDownloader public function initPerforce($package, $path) { - if ($this->perforce) { + if (!empty($this->perforce)) { $this->perforce->initializePath($path); return; } diff --git a/src/Composer/Repository/Vcs/PerforceDriver.php b/src/Composer/Repository/Vcs/PerforceDriver.php index 8a1b40623..6a55033a1 100644 --- a/src/Composer/Repository/Vcs/PerforceDriver.php +++ b/src/Composer/Repository/Vcs/PerforceDriver.php @@ -35,7 +35,7 @@ class PerforceDriver extends VcsDriver { $this->depot = $this->repoConfig['depot']; $this->branch = ''; - if (isset($this->repoConfig['branch'])) { + if (!empty($this->repoConfig['branch'])) { $this->branch = $this->repoConfig['branch']; } @@ -51,7 +51,7 @@ class PerforceDriver extends VcsDriver private function initPerforce($repoConfig) { - if (isset($this->perforce)) { + if (!empty($this->perforce)) { return; } @@ -64,7 +64,7 @@ class PerforceDriver extends VcsDriver */ public function getComposerInformation($identifier) { - if (isset($this->composerInfoIdentifier)) { + if (!empty($this->composerInfoIdentifier)) { if (strcmp($identifier, $this->composerInfoIdentifier) === 0) { return $this->composerInfo; } @@ -141,7 +141,7 @@ class PerforceDriver extends VcsDriver $this->composerInfo = $this->perforce->getComposerInformation('//' . $this->depot . '/' . $identifier); $this->composerInfoIdentifier = $identifier; $result = false; - if (isset($this->composerInfo)) { + if (!empty($this->composerInfo)) { $result = count($this->composerInfo) > 0; } diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index c3b66329f..2a1094e59 100644 --- a/src/Composer/Util/Perforce.php +++ b/src/Composer/Util/Perforce.php @@ -200,7 +200,12 @@ class Perforce return $this->p4User; } - public function queryP4User(IOInterface $io) + public function setUser($user) + { + $this->p4User = $user; + } + + public function queryP4User() { $this->getUser(); if (strlen($this->p4User) > 0) { @@ -210,7 +215,7 @@ class Perforce if (strlen($this->p4User) > 0) { return; } - $this->p4User = $io->ask('Enter P4 User:'); + $this->p4User = $this->io->ask('Enter P4 User:'); if ($this->windowsFlag) { $command = 'p4 set P4USER=' . $this->p4User; } else { @@ -248,14 +253,14 @@ class Perforce } } - public function queryP4Password(IOInterface $io) + public function queryP4Password() { if (isset($this->p4Password)) { return $this->p4Password; } $password = $this->getP4variable('P4PASSWD'); if (strlen($password) <= 0) { - $password = $io->askAndHideAnswer('Enter password for Perforce user ' . $this->getUser() . ': '); + $password = $this->io->askAndHideAnswer('Enter password for Perforce user ' . $this->getUser() . ': '); } $this->p4Password = $password; @@ -365,6 +370,16 @@ class Perforce return; } + public function getWindowsFlag() + { + return $this->windowsFlag; + } + + public function setWindowsFlag($flag) + { + $this->windowsFlag = $flag; + } + public function windowsLogin($password) { $command = $this->generateP4Command(' login -a'); @@ -373,11 +388,11 @@ class Perforce return $process->run(); } - public function p4Login(IOInterface $io) + public function p4Login() { - $this->queryP4User($io); + $this->queryP4User(); if (!$this->isLoggedIn()) { - $password = $this->queryP4Password($io); + $password = $this->queryP4Password(); if ($this->windowsFlag) { $this->windowsLogin($password); } else { diff --git a/tests/Composer/Test/Downloader/PerforceDownloaderTest.php b/tests/Composer/Test/Downloader/PerforceDownloaderTest.php index 0eb981362..c78f1ed13 100644 --- a/tests/Composer/Test/Downloader/PerforceDownloaderTest.php +++ b/tests/Composer/Test/Downloader/PerforceDownloaderTest.php @@ -122,12 +122,13 @@ class PerforceDownloaderTest extends \PHPUnit_Framework_TestCase $this->io->expects($this->once())->method('write')->with($this->stringContains('Cloning '.$ref)); $perforceMethods = array('setStream', 'p4Login', 'writeP4ClientSpec', 'connectClient', 'syncCodeBase', 'cleanupClientSpec'); $perforce = $this->getMockBuilder('Composer\Util\Perforce', $perforceMethods)->disableOriginalConstructor()->getMock(); - $perforce->expects($this->at(0))->method('setStream')->with($this->equalTo($ref)); - $perforce->expects($this->at(1))->method('p4Login')->with($this->identicalTo($this->io)); - $perforce->expects($this->at(2))->method('writeP4ClientSpec'); - $perforce->expects($this->at(3))->method('connectClient'); - $perforce->expects($this->at(4))->method('syncCodeBase'); - $perforce->expects($this->at(5))->method('cleanupClientSpec'); + $perforce->expects($this->at(0))->method('initializePath')->with($this->equalTo($this->testPath)); + $perforce->expects($this->at(1))->method('setStream')->with($this->equalTo($ref)); + $perforce->expects($this->at(2))->method('p4Login')->with($this->identicalTo($this->io)); + $perforce->expects($this->at(3))->method('writeP4ClientSpec'); + $perforce->expects($this->at(4))->method('connectClient'); + $perforce->expects($this->at(5))->method('syncCodeBase'); + $perforce->expects($this->at(6))->method('cleanupClientSpec'); $this->downloader->setPerforce($perforce); $this->downloader->doDownload($this->package, $this->testPath); } diff --git a/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php b/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php index 36cd69ebc..bc228de7e 100644 --- a/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php @@ -21,113 +21,129 @@ use Composer\Config; */ class PerforceDriverTest extends \PHPUnit_Framework_TestCase { - private $config; - private $io; - private $process; - private $remoteFileSystem; - private $testPath; + protected $config; + protected $io; + protected $process; + protected $remoteFileSystem; + protected $testPath; + protected $driver; + protected $repoConfig; + + const TEST_URL = 'TEST_PERFORCE_URL'; + const TEST_DEPOT = 'TEST_DEPOT_CONFIG'; + const TEST_BRANCH = 'TEST_BRANCH_CONFIG'; public function setUp() { - $this->testPath = sys_get_temp_dir() . '/composer-test'; - $this->config = new Config(); - $this->config->merge( - array( - 'config' => array( - 'home' => $this->testPath, - ), - ) - ); - - $this->io = $this->getMock('Composer\IO\IOInterface'); - $this->process = $this->getMock('Composer\Util\ProcessExecutor'); - $this->remoteFileSystem = $this->getMockBuilder('Composer\Util\RemoteFilesystem')->disableOriginalConstructor() - ->getMock(); + $this->testPath = sys_get_temp_dir() . '/composer-test'; + $this->config = $this->getTestConfig($this->testPath); + $this->repoConfig = $this->getTestRepoConfig(); + $this->io = $this->getMockIOInterface(); + $this->process = $this->getMockProcessExecutor(); + $this->remoteFileSystem = $this->getMockRemoteFilesystem(); + $this->perforce = $this->getMockPerforce(); + $this->driver = new PerforceDriver($this->repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem); } public function tearDown() { + //cleanup directory under test path $fs = new Filesystem; $fs->removeDirectory($this->testPath); + $this->driver = null; + $this->perforce = null; + $this->remoteFileSystem = null; + $this->process = null; + $this->io = null; + $this->repoConfig = null; + $this->config = null; + $this->testPath = null; + } + + protected function getTestConfig($testPath) + { + $config = new Config(); + $config->merge(array('config'=>array('home'=>$testPath))); + return $config; + } + + protected function getTestRepoConfig() + { + return array( + 'url' => self::TEST_URL, + 'depot' => self::TEST_DEPOT, + 'branch' => self::TEST_BRANCH, + ); + } + + protected function getMockIOInterface() + { + return $this->getMock('Composer\IO\IOInterface'); + } + + protected function getMockProcessExecutor() + { + return $this->getMock('Composer\Util\ProcessExecutor'); + } + + protected function getMockRemoteFilesystem() + { + return $this->getMockBuilder('Composer\Util\RemoteFilesystem')->disableOriginalConstructor()->getMock(); + } + + protected function getMockPerforce() + { + $methods = array('p4login', 'checkStream', 'writeP4ClientSpec', 'connectClient', 'getComposerInformation'); + return $this->getMockBuilder('Composer\Util\Perforce', $methods)->disableOriginalConstructor()->getMock(); } public function testInitializeCapturesVariablesFromRepoConfig() { - $this->setUp(); - $repoConfig = array( - 'url' => 'TEST_PERFORCE_URL', - 'depot' => 'TEST_DEPOT_CONFIG', - 'branch' => 'TEST_BRANCH_CONFIG' - ); - $driver = new PerforceDriver($repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem); - $process = $this->getMock('Composer\Util\ProcessExecutor'); - $arguments = array( - array('depot' => 'TEST_DEPOT', 'branch' => 'TEST_BRANCH'), - 'port' => 'TEST_PORT', - 'path' => $this->testPath, - $process, - true, - 'TEST' - ); - $perforce = $this->getMock('Composer\Util\Perforce', null, $arguments); - $driver->setPerforce($perforce); + $driver = new PerforceDriver($this->repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem); + $driver->setPerforce($this->perforce); $driver->initialize(); - $this->assertEquals('TEST_PERFORCE_URL', $driver->getUrl()); - $this->assertEquals('TEST_DEPOT_CONFIG', $driver->getDepot()); - $this->assertEquals('TEST_BRANCH_CONFIG', $driver->getBranch()); + $this->assertEquals(self::TEST_URL, $driver->getUrl()); + $this->assertEquals(self::TEST_DEPOT, $driver->getDepot()); + $this->assertEquals(self::TEST_BRANCH, $driver->getBranch()); } public function testInitializeLogsInAndConnectsClient() { - $this->setUp(); - $repoConfig = array( - 'url' => 'TEST_PERFORCE_URL', - 'depot' => 'TEST_DEPOT_CONFIG', - 'branch' => 'TEST_BRANCH_CONFIG' - ); - $driver = new PerforceDriver($repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem); - $perforce = $this->getMockBuilder('Composer\Util\Perforce')->disableOriginalConstructor()->getMock(); - $perforce->expects($this->at(0)) - ->method('p4Login') - ->with($this->io); - $perforce->expects($this->at(1)) - ->method('checkStream') - ->with($this->equalTo('TEST_DEPOT_CONFIG')); - $perforce->expects($this->at(2)) - ->method('writeP4ClientSpec'); - $perforce->expects($this->at(3)) - ->method('connectClient'); - - $driver->setPerforce($perforce); - $driver->initialize(); + $this->driver->setPerforce($this->perforce); + $this->perforce->expects($this->at(0))->method('p4Login')->with($this->identicalTo($this->io)); + $this->perforce->expects($this->at(1))->method('checkStream')->with($this->equalTo(self::TEST_DEPOT)); + $this->perforce->expects($this->at(2))->method('writeP4ClientSpec'); + $this->perforce->expects($this->at(3))->method('connectClient'); + $this->driver->initialize(); } - public function testHasComposerFile() + /** + * @depends testInitializeCapturesVariablesFromRepoConfig + * @depends testInitializeLogsInAndConnectsClient + */ + public function testHasComposerFileReturnsFalseOnNoComposerFile() { - $repoConfig = array( - 'url' => 'TEST_PERFORCE_URL', - 'depot' => 'TEST_DEPOT_CONFIG', - 'branch' => 'TEST_BRANCH_CONFIG' - ); - $driver = new PerforceDriver($repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem); - $process = $this->getMock('Composer\Util\ProcessExecutor'); - $arguments = array( - array('depot' => 'TEST_DEPOT', 'branch' => 'TEST_BRANCH'), - 'port' => 'TEST_PORT', - 'path' => $this->testPath, - $process, - true, - 'TEST' - ); - $perforce = $this->getMock('Composer\Util\Perforce', array('getComposerInformation'), $arguments); - $perforce->expects($this->at(0)) - ->method('getComposerInformation') - ->with($this->equalTo('//TEST_DEPOT_CONFIG/TEST_IDENTIFIER')) - ->will($this->returnValue('Some json stuff')); - $driver->setPerforce($perforce); - $driver->initialize(); $identifier = 'TEST_IDENTIFIER'; - $result = $driver->hasComposerFile($identifier); + $formatted_depot_path = '//' . self::TEST_DEPOT . '/' . $identifier; + $this->driver->setPerforce($this->perforce); + $this->perforce->expects($this->at(0))->method('getComposerInformation')->with($this->equalTo($formatted_depot_path))->will($this->returnValue(array())); + $this->driver->initialize(); + $result = $this->driver->hasComposerFile($identifier); + $this->assertFalse($result); + } + + /** + * @depends testInitializeCapturesVariablesFromRepoConfig + * @depends testInitializeLogsInAndConnectsClient + */ + public function testHasComposerFileReturnsTrueWithOneOrMoreComposerFiles() + { + $identifier = 'TEST_IDENTIFIER'; + $formatted_depot_path = '//' . self::TEST_DEPOT . '/' . $identifier; + $this->driver->setPerforce($this->perforce); + $this->perforce->expects($this->at(0))->method('getComposerInformation')->with($this->equalTo($formatted_depot_path))->will($this->returnValue(array(''))); + $this->driver->initialize(); + $result = $this->driver->hasComposerFile($identifier); $this->assertTrue($result); } diff --git a/tests/Composer/Test/Util/PerforceTest.php b/tests/Composer/Test/Util/PerforceTest.php index 56a234536..b7865d5e6 100644 --- a/tests/Composer/Test/Util/PerforceTest.php +++ b/tests/Composer/Test/Util/PerforceTest.php @@ -24,26 +24,44 @@ class PerforceTest extends \PHPUnit_Framework_TestCase protected $processExecutor; protected $io; + const TEST_DEPOT = 'depot'; + const TEST_BRANCH = 'branch'; + const TEST_P4USER = 'user'; + const TEST_CLIENT_NAME = 'TEST'; + const TEST_PORT = 'port'; + const TEST_PATH = 'path'; + public function setUp() { $this->processExecutor = $this->getMock('Composer\Util\ProcessExecutor'); - $repoConfig = array( - 'depot' => 'depot', - 'branch' => 'branch', - 'p4user' => 'user', - 'unique_perforce_client_name' => 'TEST' - ); - $io = $this->getMock('Composer\IO\IOInterface'); - $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, true, $io); + $this->repoConfig = $this->getTestRepoConfig(); + $this->io = $this->getMockIOInterface(); + $this->perforce = new Perforce($this->repoConfig, self::TEST_PORT, self::TEST_PATH, $this->processExecutor, true, $this->io); } public function tearDown() { - $this->perforce = null; - $this->io = null; + $this->perforce = null; + $this->io = null; + $this->repoConfig = null; $this->processExecutor = null; } + public function getTestRepoConfig() + { + return array( + 'depot' => self::TEST_DEPOT, + 'branch' => self::TEST_BRANCH, + 'p4user' => self::TEST_P4USER, + 'unique_perforce_client_name' => self::TEST_CLIENT_NAME + ); + } + + public function getMockIOInterface() + { + return $this->getMock('Composer\IO\IOInterface'); + } + public function testGetClientWithoutStream() { $client = $this->perforce->getClient(); @@ -107,116 +125,90 @@ class PerforceTest extends \PHPUnit_Framework_TestCase public function testQueryP4UserWithUserAlreadySet() { - $io = $this->getMock('Composer\IO\IOInterface'); - - $repoConfig = array('depot' => 'depot', 'branch' => 'branch', 'p4user' => 'TEST_USER'); - $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, true, 'TEST'); - - $this->perforce->queryP4user($io); - $this->assertEquals('TEST_USER', $this->perforce->getUser()); + $this->perforce->queryP4user(); + $this->assertEquals(self::TEST_P4USER, $this->perforce->getUser()); } public function testQueryP4UserWithUserSetInP4VariablesWithWindowsOS() { - $repoConfig = array('depot' => 'depot', 'branch' => 'branch'); - $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, true, 'TEST'); - - $io = $this->getMock('Composer\IO\IOInterface'); + $this->perforce->setUser(null); + $this->perforce->setWindowsFlag(true); $expectedCommand = 'p4 set'; + $callback = function($command, &$output) + { + $output = 'P4USER=TEST_P4VARIABLE_USER' . PHP_EOL; + return true; + }; $this->processExecutor->expects($this->at(0)) - ->method('execute') - ->with($this->equalTo($expectedCommand)) - ->will( - $this->returnCallback( - function ($command, &$output) { - $output = 'P4USER=TEST_P4VARIABLE_USER' . PHP_EOL ; - - return true; - } - ) - ); - - $this->perforce->queryP4user($io); + ->method('execute') + ->with($this->equalTo($expectedCommand)) + ->will($this->returnCallback($callback)); + $this->perforce->queryP4user(); $this->assertEquals('TEST_P4VARIABLE_USER', $this->perforce->getUser()); } public function testQueryP4UserWithUserSetInP4VariablesNotWindowsOS() { - $repoConfig = array('depot' => 'depot', 'branch' => 'branch'); - $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, false, 'TEST'); - - $io = $this->getMock('Composer\IO\IOInterface'); + $this->perforce->setUser(null); + $this->perforce->setWindowsFlag(false); $expectedCommand = 'echo $P4USER'; + $callback = function($command, &$output) + { + $output = 'TEST_P4VARIABLE_USER' . PHP_EOL; + return true; + }; $this->processExecutor->expects($this->at(0)) - ->method('execute') - ->with($this->equalTo($expectedCommand)) - ->will( - $this->returnCallback( - function ($command, &$output) { - $output = 'TEST_P4VARIABLE_USER' . PHP_EOL; - - return true; - } - ) - ); - - $this->perforce->queryP4user($io); + ->method('execute') + ->with($this->equalTo($expectedCommand)) + ->will($this->returnCallback($callback)); + $this->perforce->queryP4user(); $this->assertEquals('TEST_P4VARIABLE_USER', $this->perforce->getUser()); } public function testQueryP4UserQueriesForUser() { - $repoConfig = array('depot' => 'depot', 'branch' => 'branch'); - $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, false, 'TEST'); - $io = $this->getMock('Composer\IO\IOInterface'); + $this->perforce->setUser(null); $expectedQuestion = 'Enter P4 User:'; - $io->expects($this->at(0)) - ->method('ask') - ->with($this->equalTo($expectedQuestion)) - ->will($this->returnValue('TEST_QUERY_USER')); - - $this->perforce->queryP4user($io); + $this->io->expects($this->at(0)) + ->method('ask') + ->with($this->equalTo($expectedQuestion)) + ->will($this->returnValue('TEST_QUERY_USER')); + $this->perforce->queryP4user(); $this->assertEquals('TEST_QUERY_USER', $this->perforce->getUser()); } public function testQueryP4UserStoresResponseToQueryForUserWithWindows() { - $repoConfig = array('depot' => 'depot', 'branch' => 'branch'); - $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, true, 'TEST'); - - $io = $this->getMock('Composer\IO\IOInterface'); + $this->perforce->setUser(null); + $this->perforce->setWindowsFlag(true); $expectedQuestion = 'Enter P4 User:'; - $io->expects($this->at(0)) - ->method('ask') - ->with($this->equalTo($expectedQuestion)) - ->will($this->returnValue('TEST_QUERY_USER')); - $expectedCommand = 'p4 set P4USER=TEST_QUERY_USER'; + $expectedCommand = 'p4 set P4USER=TEST_QUERY_USER'; + $this->io->expects($this->at(0)) + ->method('ask') + ->with($this->equalTo($expectedQuestion)) + ->will($this->returnValue('TEST_QUERY_USER')); $this->processExecutor->expects($this->at(1)) - ->method('execute') - ->with($this->equalTo($expectedCommand)) - ->will($this->returnValue(0)); - - $this->perforce->queryP4user($io); + ->method('execute') + ->with($this->equalTo($expectedCommand)) + ->will($this->returnValue(0)); + $this->perforce->queryP4user(); } public function testQueryP4UserStoresResponseToQueryForUserWithoutWindows() { - $repoConfig = array('depot' => 'depot', 'branch' => 'branch'); - $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, false, 'TEST'); - - $io = $this->getMock('Composer\IO\IOInterface'); + $this->perforce->setUser(null); + $this->perforce->setWindowsFlag(false); $expectedQuestion = 'Enter P4 User:'; - $io->expects($this->at(0)) - ->method('ask') - ->with($this->equalTo($expectedQuestion)) - ->will($this->returnValue('TEST_QUERY_USER')); - $expectedCommand = 'export P4USER=TEST_QUERY_USER'; + $expectedCommand = 'export P4USER=TEST_QUERY_USER'; + $this->io->expects($this->at(0)) + ->method('ask') + ->with($this->equalTo($expectedQuestion)) + ->will($this->returnValue('TEST_QUERY_USER')); $this->processExecutor->expects($this->at(1)) - ->method('execute') - ->with($this->equalTo($expectedCommand)) - ->will($this->returnValue(0)); - - $this->perforce->queryP4user($io); + ->method('execute') + ->with($this->equalTo($expectedCommand)) + ->will($this->returnValue(0)); + $this->perforce->queryP4user(); } public function testQueryP4PasswordWithPasswordAlreadySet() @@ -227,69 +219,55 @@ class PerforceTest extends \PHPUnit_Framework_TestCase 'p4user' => 'user', 'p4password' => 'TEST_PASSWORD' ); - $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, false, 'TEST'); - $io = $this->getMock('Composer\IO\IOInterface'); - - $password = $this->perforce->queryP4Password($io); + $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, false, $this->getMockIOInterface(), 'TEST'); + $password = $this->perforce->queryP4Password(); $this->assertEquals('TEST_PASSWORD', $password); } public function testQueryP4PasswordWithPasswordSetInP4VariablesWithWindowsOS() { - $io = $this->getMock('Composer\IO\IOInterface'); - + $this->perforce->setWindowsFlag(true); $expectedCommand = 'p4 set'; + $callback = function($command, &$output) + { + $output = 'P4PASSWD=TEST_P4VARIABLE_PASSWORD' . PHP_EOL; + return true; + }; $this->processExecutor->expects($this->at(0)) - ->method('execute') - ->with($this->equalTo($expectedCommand)) - ->will( - $this->returnCallback( - function ($command, &$output) { - $output = 'P4PASSWD=TEST_P4VARIABLE_PASSWORD' . PHP_EOL; - - return true; - } - ) - ); - - $password = $this->perforce->queryP4Password($io); + ->method('execute') + ->with($this->equalTo($expectedCommand)) + ->will($this->returnCallback($callback)); + $password = $this->perforce->queryP4Password(); $this->assertEquals('TEST_P4VARIABLE_PASSWORD', $password); } public function testQueryP4PasswordWithPasswordSetInP4VariablesNotWindowsOS() { - $repoConfig = array('depot' => 'depot', 'branch' => 'branch', 'p4user' => 'user'); - $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, false, 'TEST'); - - $io = $this->getMock('Composer\IO\IOInterface'); + $this->perforce->setWindowsFlag(false); $expectedCommand = 'echo $P4PASSWD'; + $callback = function($command, &$output) + { + $output = 'TEST_P4VARIABLE_PASSWORD' . PHP_EOL; + return true; + }; $this->processExecutor->expects($this->at(0)) - ->method('execute') - ->with($this->equalTo($expectedCommand)) - ->will( - $this->returnCallback( - function ($command, &$output) { - $output = 'TEST_P4VARIABLE_PASSWORD' . PHP_EOL; + ->method('execute') + ->with($this->equalTo($expectedCommand)) + ->will($this->returnCallback($callback)); - return true; - } - ) - ); - - $password = $this->perforce->queryP4Password($io); + $password = $this->perforce->queryP4Password(); $this->assertEquals('TEST_P4VARIABLE_PASSWORD', $password); } public function testQueryP4PasswordQueriesForPassword() { - $io = $this->getMock('Composer\IO\IOInterface'); $expectedQuestion = 'Enter password for Perforce user user: '; - $io->expects($this->at(0)) + $this->io->expects($this->at(0)) ->method('askAndHideAnswer') ->with($this->equalTo($expectedQuestion)) ->will($this->returnValue('TEST_QUERY_PASSWORD')); - $password = $this->perforce->queryP4Password($io); + $password = $this->perforce->queryP4Password(); $this->assertEquals('TEST_QUERY_PASSWORD', $password); } From c6133050b32e983a0bdfe5ea3ff396f6d761fa42 Mon Sep 17 00:00:00 2001 From: Clark Stuth Date: Tue, 18 Mar 2014 13:52:54 -0500 Subject: [PATCH 03/16] got all unit tests passing --- src/Composer/Repository/Vcs/PerforceDriver.php | 2 ++ src/Composer/Util/Perforce.php | 2 +- tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Composer/Repository/Vcs/PerforceDriver.php b/src/Composer/Repository/Vcs/PerforceDriver.php index 6a55033a1..535a79516 100644 --- a/src/Composer/Repository/Vcs/PerforceDriver.php +++ b/src/Composer/Repository/Vcs/PerforceDriver.php @@ -141,6 +141,8 @@ class PerforceDriver extends VcsDriver $this->composerInfo = $this->perforce->getComposerInformation('//' . $this->depot . '/' . $identifier); $this->composerInfoIdentifier = $identifier; $result = false; + return !empty($this->composerInfo); + if (!empty($this->composerInfo)) { $result = count($this->composerInfo) > 0; } diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index 2a1094e59..ecafaf6f0 100644 --- a/src/Composer/Util/Perforce.php +++ b/src/Composer/Util/Perforce.php @@ -47,7 +47,7 @@ class Perforce $this->io = $io; } - public static function create($repoConfig, $port, $path, ProcessExecutor $process = null, IOInterface $io) + public static function create($repoConfig, $port, $path, ProcessExecutor $process, IOInterface $io) { if (!isset($process)) { $process = new ProcessExecutor; diff --git a/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php b/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php index bc228de7e..7666efebc 100644 --- a/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php @@ -126,7 +126,7 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase $identifier = 'TEST_IDENTIFIER'; $formatted_depot_path = '//' . self::TEST_DEPOT . '/' . $identifier; $this->driver->setPerforce($this->perforce); - $this->perforce->expects($this->at(0))->method('getComposerInformation')->with($this->equalTo($formatted_depot_path))->will($this->returnValue(array())); + $this->perforce->expects($this->any())->method('getComposerInformation')->with($this->equalTo($formatted_depot_path))->will($this->returnValue(array())); $this->driver->initialize(); $result = $this->driver->hasComposerFile($identifier); $this->assertFalse($result); @@ -141,7 +141,7 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase $identifier = 'TEST_IDENTIFIER'; $formatted_depot_path = '//' . self::TEST_DEPOT . '/' . $identifier; $this->driver->setPerforce($this->perforce); - $this->perforce->expects($this->at(0))->method('getComposerInformation')->with($this->equalTo($formatted_depot_path))->will($this->returnValue(array(''))); + $this->perforce->expects($this->any())->method('getComposerInformation')->with($this->equalTo($formatted_depot_path))->will($this->returnValue(array(''))); $this->driver->initialize(); $result = $this->driver->hasComposerFile($identifier); $this->assertTrue($result); From 14a6406f9b0a61bbbaeb6b25ada865e06be03f34 Mon Sep 17 00:00:00 2001 From: Clark Stuth Date: Tue, 18 Mar 2014 14:39:47 -0500 Subject: [PATCH 04/16] Fixing bug not cleaning up workspaces. --- .../Repository/Vcs/PerforceDriver.php | 6 +++++ src/Composer/Util/Perforce.php | 24 ++++++++++++++++--- .../Repository/Vcs/PerforceDriverTest.php | 11 ++++++++- tests/Composer/Test/Util/PerforceTest.php | 15 ++++++++++++ 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/Composer/Repository/Vcs/PerforceDriver.php b/src/Composer/Repository/Vcs/PerforceDriver.php index 535a79516..090de1bb8 100644 --- a/src/Composer/Repository/Vcs/PerforceDriver.php +++ b/src/Composer/Repository/Vcs/PerforceDriver.php @@ -193,4 +193,10 @@ class PerforceDriver extends VcsDriver { $this->perforce = $perforce; } + + public function getPerforce() + { + return $this->perforce; + } + } diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index ecafaf6f0..659cbfc67 100644 --- a/src/Composer/Util/Perforce.php +++ b/src/Composer/Util/Perforce.php @@ -37,6 +37,8 @@ class Perforce protected $io; + protected $filesystem; + public function __construct($repoConfig, $port, $path, ProcessExecutor $process, $isWindows, IOInterface $io) { $this->windowsFlag = $isWindows; @@ -109,10 +111,10 @@ class Perforce public function cleanupClientSpec() { $client = $this->getClient(); - $command = 'p4 client -d $client'; + $command = 'p4 client -d ' . $client; $this->executeCommand($command); $clientSpec = $this->getP4ClientSpec(); - $fileSystem = new FileSystem($this->process); + $fileSystem = $this->getFilesystem(); $fileSystem->remove($clientSpec); } @@ -141,7 +143,7 @@ class Perforce public function initializePath($path) { $this->path = $path; - $fs = new Filesystem(); + $fs = $this->getFilesystem(); $fs->ensureDirectoryExists($path); } @@ -559,4 +561,20 @@ class Perforce return $result; } + + public function getFilesystem() + { + if (empty($this->filesystem)) + { + $this->filesystem = new Filesystem($this->process); + } + return $this->filesystem; + } + + + public function setFilesystem(Filesystem $fs) + { + $this->filesystem = $fs; + } + } diff --git a/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php b/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php index 7666efebc..9afc57d30 100644 --- a/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php @@ -93,7 +93,7 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase protected function getMockPerforce() { - $methods = array('p4login', 'checkStream', 'writeP4ClientSpec', 'connectClient', 'getComposerInformation'); + $methods = array('p4login', 'checkStream', 'writeP4ClientSpec', 'connectClient', 'getComposerInformation', 'cleanupClientSpec'); return $this->getMockBuilder('Composer\Util\Perforce', $methods)->disableOriginalConstructor()->getMock(); } @@ -159,4 +159,13 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase $this->expectOutputString(''); $this->assertFalse(PerforceDriver::supports($this->io, $this->config, 'existing.url')); } + + public function testCleanup() + { + $this->perforce->expects($this->once())->method('cleanupClientSpec'); + $this->driver->setPerforce($this->perforce); + $this->driver->cleanup(); + $this->assertNull($this->driver->getPerforce()); + } + } diff --git a/tests/Composer/Test/Util/PerforceTest.php b/tests/Composer/Test/Util/PerforceTest.php index b7865d5e6..65857343b 100644 --- a/tests/Composer/Test/Util/PerforceTest.php +++ b/tests/Composer/Test/Util/PerforceTest.php @@ -679,4 +679,19 @@ class PerforceTest extends \PHPUnit_Framework_TestCase { $this->perforce->setStream('//depot/branch'); } + + public function testCleanupClientSpecShouldDeleteClient() + { + $fs = $this->getMock('Composer\Util\Filesystem'); + $this->perforce->setFilesystem($fs); + + $testClient = $this->perforce->getClient(); + $expectedCommand = 'p4 client -d ' . $testClient; + $this->processExecutor->expects($this->once())->method('execute')->with($this->equalTo($expectedCommand)); + + $fs->expects($this->once())->method('remove')->with($this->perforce->getP4ClientSpec()); + + $this->perforce->cleanupClientSpec(); + } + } From c1a8b4645cc9178ed99b645b1fc9069d7659b525 Mon Sep 17 00:00:00 2001 From: Clark Stuth Date: Wed, 19 Mar 2014 13:58:41 -0500 Subject: [PATCH 05/16] Fixing delete client workspace bug. --- src/Composer/Util/Perforce.php | 4 +++- tests/Composer/Test/Util/PerforceTest.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index 659cbfc67..f3e9d2023 100644 --- a/src/Composer/Util/Perforce.php +++ b/src/Composer/Util/Perforce.php @@ -111,7 +111,9 @@ class Perforce public function cleanupClientSpec() { $client = $this->getClient(); - $command = 'p4 client -d ' . $client; + $task = 'client -d ' . $client; + $useP4Client = false; + $command = $this->generateP4Command($task, $useP4Client); $this->executeCommand($command); $clientSpec = $this->getP4ClientSpec(); $fileSystem = $this->getFilesystem(); diff --git a/tests/Composer/Test/Util/PerforceTest.php b/tests/Composer/Test/Util/PerforceTest.php index 65857343b..06e3cce8b 100644 --- a/tests/Composer/Test/Util/PerforceTest.php +++ b/tests/Composer/Test/Util/PerforceTest.php @@ -686,7 +686,7 @@ class PerforceTest extends \PHPUnit_Framework_TestCase $this->perforce->setFilesystem($fs); $testClient = $this->perforce->getClient(); - $expectedCommand = 'p4 client -d ' . $testClient; + $expectedCommand = 'p4 -u ' . self::TEST_P4USER . ' -p ' . self::TEST_PORT . ' client -d ' . $testClient; $this->processExecutor->expects($this->once())->method('execute')->with($this->equalTo($expectedCommand)); $fs->expects($this->once())->method('remove')->with($this->perforce->getP4ClientSpec()); From 15b8c6f1c38b6c2541616b44b00928526f00b7db Mon Sep 17 00:00:00 2001 From: Clark Stuth Date: Fri, 21 Mar 2014 13:42:00 -0500 Subject: [PATCH 06/16] Fixing perforce dev-master stored reference bug. --- src/Composer/Util/Perforce.php | 17 ++++++++-------- tests/Composer/Test/Util/PerforceTest.php | 24 +++++++++++++++++++++-- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index f3e9d2023..ae6f44d04 100644 --- a/src/Composer/Util/Perforce.php +++ b/src/Composer/Util/Perforce.php @@ -315,11 +315,7 @@ class Perforce chdir($this->path); $p4SyncCommand = $this->generateP4Command('sync -f '); - if (isset($label)) { - if (strcmp($label, 'dev-master') != 0) { - $p4SyncCommand = $p4SyncCommand . '@' . $label; - } - } + $p4SyncCommand = $p4SyncCommand . '@' . $label; $this->executeCommand($p4SyncCommand); chdir($prevDir); @@ -481,9 +477,15 @@ class Perforce } } } - $branches = array(); - $branches['master'] = $possibleBranches[$this->p4Branch]; + $command = $this->generateP4Command('changes '. $this->getStream() . '/...', false); + $this->executeCommand($command); + $result = $this->commandResult; + $resArray = explode(PHP_EOL, $result); + $lastCommit = $resArray[0]; + $lastCommitArr = explode(' ', $lastCommit); + $lastCommitNum = $lastCommitArr[1]; + $branches = array('master' => $possibleBranches[$this->p4Branch] . '@'. $lastCommitNum); return $branches; } @@ -501,7 +503,6 @@ class Perforce $tags[$fields[1]] = $this->getStream() . '@' . $fields[1]; } } - return $tags; } diff --git a/tests/Composer/Test/Util/PerforceTest.php b/tests/Composer/Test/Util/PerforceTest.php index 06e3cce8b..1b8063258 100644 --- a/tests/Composer/Test/Util/PerforceTest.php +++ b/tests/Composer/Test/Util/PerforceTest.php @@ -351,15 +351,35 @@ class PerforceTest extends \PHPUnit_Framework_TestCase } ) ); + $expectedCommand2 = 'p4 -u user -p port changes //depot/branch/...'; + $expectedCallback = function($command, &$output) + { + $output = 'Change 1234 on 2014/03/19 by Clark.Stuth@Clark.Stuth_test_client \'test changelist\''; + return true; + }; + $this->processExecutor->expects($this->at(1)) + ->method('execute') + ->with($this->equalTo($expectedCommand2)) + ->will($this->returnCallback($expectedCallback)); $branches = $this->perforce->getBranches(); - $this->assertEquals('//depot/branch', $branches['master']); + $this->assertEquals('//depot/branch@1234', $branches['master']); } public function testGetBranchesWithoutStream() { + $expectedCommand = 'p4 -u user -p port changes //depot/...'; + $expectedCallback = function($command, &$output) + { + $output = 'Change 5678 on 2014/03/19 by Clark.Stuth@Clark.Stuth_test_client \'test changelist\''; + return true; + }; + $this->processExecutor->expects($this->once()) + ->method('execute') + ->with($this->equalTo($expectedCommand)) + ->will($this->returnCallback($expectedCallback)); $branches = $this->perforce->getBranches(); - $this->assertEquals('//depot', $branches['master']); + $this->assertEquals('//depot@5678', $branches['master']); } public function testGetTagsWithoutStream() From 0f7b078d6ccb555348ade0abe1a854e9bd53e841 Mon Sep 17 00:00:00 2001 From: Clark Stuth Date: Fri, 14 Mar 2014 14:45:31 -0500 Subject: [PATCH 07/16] added new dependency to Perforce object, updating some tests. --- .../Downloader/PerforceDownloader.php | 4 +- .../Repository/Vcs/PerforceDriver.php | 2 +- src/Composer/Util/Perforce.php | 21 ++- .../Downloader/PerforceDownloaderTest.php | 160 +++++++++++------- tests/Composer/Test/Util/PerforceTest.php | 11 +- 5 files changed, 122 insertions(+), 76 deletions(-) diff --git a/src/Composer/Downloader/PerforceDownloader.php b/src/Composer/Downloader/PerforceDownloader.php index 2bb1ba619..632ac648c 100644 --- a/src/Composer/Downloader/PerforceDownloader.php +++ b/src/Composer/Downloader/PerforceDownloader.php @@ -22,7 +22,7 @@ use Composer\Util\Perforce; class PerforceDownloader extends VcsDownloader { protected $perforce; - protected $perforceInjected = false; +// protected $perforceInjected = false; /** * {@inheritDoc} @@ -54,7 +54,7 @@ class PerforceDownloader extends VcsDownloader if ($repository instanceof VcsRepository) { $repoConfig = $this->getRepoConfig($repository); } - $this->perforce = Perforce::create($repoConfig, $package->getSourceUrl(), $path); + $this->perforce = Perforce::create($repoConfig, $package->getSourceUrl(), $path, $this->process, $this->io); } private function getRepoConfig(VcsRepository $repository) diff --git a/src/Composer/Repository/Vcs/PerforceDriver.php b/src/Composer/Repository/Vcs/PerforceDriver.php index 79500f1d6..8a1b40623 100644 --- a/src/Composer/Repository/Vcs/PerforceDriver.php +++ b/src/Composer/Repository/Vcs/PerforceDriver.php @@ -56,7 +56,7 @@ class PerforceDriver extends VcsDriver } $repoDir = $this->config->get('cache-vcs-dir') . '/' . $this->depot; - $this->perforce = Perforce::create($repoConfig, $this->getUrl(), $repoDir, $this->process); + $this->perforce = Perforce::create($repoConfig, $this->getUrl(), $repoDir, $this->process, $this->io); } /** diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index 94b9730eb..c3b66329f 100644 --- a/src/Composer/Util/Perforce.php +++ b/src/Composer/Util/Perforce.php @@ -35,27 +35,36 @@ class Perforce protected $windowsFlag; protected $commandResult; - public function __construct($repoConfig, $port, $path, ProcessExecutor $process, $isWindows) + protected $io; + + public function __construct($repoConfig, $port, $path, ProcessExecutor $process, $isWindows, IOInterface $io) { $this->windowsFlag = $isWindows; $this->p4Port = $port; $this->initializePath($path); $this->process = $process; $this->initialize($repoConfig); + $this->io = $io; } - public static function create($repoConfig, $port, $path, ProcessExecutor $process = null) + public static function create($repoConfig, $port, $path, ProcessExecutor $process = null, IOInterface $io) { if (!isset($process)) { $process = new ProcessExecutor; } $isWindows = defined('PHP_WINDOWS_VERSION_BUILD'); - $perforce = new Perforce($repoConfig, $port, $path, $process, $isWindows); + $perforce = new Perforce($repoConfig, $port, $path, $process, $isWindows, $io); return $perforce; } + public static function checkServerExists($url, ProcessExecutor $processExecutor) + { + $output = null; + return 0 === $processExecutor->execute('p4 -p ' . $url . ' info -s', $output); + } + public function initialize($repoConfig) { $this->uniquePerforceClientName = $this->generateUniquePerforceClientName(); @@ -382,12 +391,6 @@ class Perforce } } - public static function checkServerExists($url, ProcessExecutor $processExecutor) - { - $output = null; - return 0 === $processExecutor->execute('p4 -p ' . $url . ' info -s', $output); - } - public function getComposerInformation($identifier) { $index = strpos($identifier, '@'); diff --git a/tests/Composer/Test/Downloader/PerforceDownloaderTest.php b/tests/Composer/Test/Downloader/PerforceDownloaderTest.php index 8a20f67cc..0eb981362 100644 --- a/tests/Composer/Test/Downloader/PerforceDownloaderTest.php +++ b/tests/Composer/Test/Downloader/PerforceDownloaderTest.php @@ -15,86 +15,120 @@ namespace Composer\Test\Downloader; use Composer\Downloader\PerforceDownloader; use Composer\Config; use Composer\Repository\VcsRepository; +use Composer\IO\IOInterface; /** * @author Matt Whittom */ class PerforceDownloaderTest extends \PHPUnit_Framework_TestCase { - private $io; - private $config; - private $testPath; - public static $repository; + + protected $config; + protected $downloader; + protected $io; + protected $package; + protected $processExecutor; + protected $repoConfig; + protected $repository; + protected $testPath; - protected function setUp() + public function setUp() { - $this->testPath = sys_get_temp_dir() . '/composer-test'; - $this->config = new Config(); - $this->config->merge( - array( - 'config' => array( - 'home' => $this->testPath, - ), - ) - ); - $this->io = $this->getMock('Composer\IO\IOInterface'); + $this->testPath = sys_get_temp_dir() . '/composer-test'; + $this->repoConfig = $this->getRepoConfig(); + $this->config = $this->getConfig(); + $this->io = $this->getMockIoInterface(); + $this->processExecutor = $this->getMockProcessExecutor(); + $this->repository = $this->getMockRepository($this->repoConfig, $this->io, $this->config); + $this->package = $this->getMockPackageInterface($this->repository); + $this->downloader = new PerforceDownloader($this->io, $this->config, $this->processExecutor); } - public function testInitPerforceGetRepoConfig() + public function tearDown() + { + $this->downloader = null; + $this->package = null; + $this->repository = null; + $this->io = null; + $this->config = null; + $this->repoConfig = null; + $this->testPath = null; + } + + protected function getMockProcessExecutor() + { + return $this->getMock('Composer\Util\ProcessExecutor'); + } + + protected function getConfig() + { + $config = new Config(); + $settings = array('config' => array('home' => $this->testPath)); + $config->merge($settings); + return $config; + } + + protected function getMockIoInterface() + { + return $this->getMock('Composer\IO\IOInterface'); + } + + protected function getMockPackageInterface(VcsRepository $repository) { - $downloader = new PerforceDownloader($this->io, $this->config); $package = $this->getMock('Composer\Package\PackageInterface'); - $repoConfig = array('url' => 'TEST_URL', 'p4user' => 'TEST_USER'); - $repository = $this->getMock( - 'Composer\Repository\VcsRepository', - array('getRepoConfig'), - array($repoConfig, $this->io, $this->config) - ); - $package->expects($this->at(0)) - ->method('getRepository') - ->will($this->returnValue($repository)); - $repository->expects($this->at(0)) - ->method('getRepoConfig'); - $path = $this->testPath; - $downloader->initPerforce($package, $path, 'SOURCE_REF'); + $package->expects($this->any())->method('getRepository')->will($this->returnValue($repository)); + return $package; } + protected function getRepoConfig() + { + return array('url' => 'TEST_URL', 'p4user' => 'TEST_USER'); + } + + protected function getMockRepository(array $repoConfig, IOInterface $io, Config $config) + { + $class = 'Composer\Repository\VcsRepository'; + $methods = array('getRepoConfig'); + $args = array($repoConfig, $io, $config); + $repository = $this->getMock($class, $methods, $args); + $repository->expects($this->any())->method('getRepoConfig')->will($this->returnValue($repoConfig)); + return $repository; + } + + public function testInitPerforceInstantiatesANewPerforceObject() + { + $this->downloader->initPerforce($this->package, $this->testPath, 'SOURCE_REF'); + } + + public function testInitPerforceDoesNothingIfPerforceAlreadySet() + { + $perforce = $this->getMockBuilder('Composer\Util\Perforce')->disableOriginalConstructor()->getMock(); + $this->downloader->setPerforce($perforce); + $this->repository->expects($this->never())->method('getRepoConfig'); + $this->downloader->initPerforce($this->package, $this->testPath, 'SOURCE_REF'); + } + + /** + * @depends testInitPerforceInstantiatesANewPerforceObject + * @depends testInitPerforceDoesNothingIfPerforceAlreadySet + */ public function testDoDownload() { - $downloader = new PerforceDownloader($this->io, $this->config); - $repoConfig = array('depot' => 'TEST_DEPOT', 'branch' => 'TEST_BRANCH', 'p4user' => 'TEST_USER'); - $port = 'TEST_PORT'; - $path = 'TEST_PATH'; - $process = $this->getmock('Composer\Util\ProcessExecutor'); - $perforce = $this->getMock( - 'Composer\Util\Perforce', - array('setStream', 'queryP4User', 'writeP4ClientSpec', 'connectClient', 'syncCodeBase'), - array($repoConfig, $port, $path, $process, true, 'TEST') - ); + //I really don't like this test but the logic of each Perforce method is tested in the Perforce class. Really I am just enforcing workflow. $ref = 'SOURCE_REF'; $label = 'LABEL'; - $perforce->expects($this->at(0)) - ->method('setStream') - ->with($this->equalTo($ref)); - $perforce->expects($this->at(1)) - ->method('queryP4User') - ->with($this->io); - $perforce->expects($this->at(2)) - ->method('writeP4ClientSpec'); - $perforce->expects($this->at(3)) - ->method('connectClient'); - $perforce->expects($this->at(4)) - ->method('syncCodeBase') - ->with($this->equalTo($label)); - $downloader->setPerforce($perforce); - $package = $this->getMock('Composer\Package\PackageInterface'); - $package->expects($this->at(0)) - ->method('getSourceReference') - ->will($this->returnValue($ref)); - $package->expects($this->at(1)) - ->method('getPrettyVersion') - ->will($this->returnValue($label)); - $path = $this->testPath; - $downloader->doDownload($package, $path); + $this->package->expects($this->once())->method('getSourceReference')->will($this->returnValue($ref)); + $this->package->expects($this->once())->method('getPrettyVersion')->will($this->returnValue($label)); + $this->io->expects($this->once())->method('write')->with($this->stringContains('Cloning '.$ref)); + $perforceMethods = array('setStream', 'p4Login', 'writeP4ClientSpec', 'connectClient', 'syncCodeBase', 'cleanupClientSpec'); + $perforce = $this->getMockBuilder('Composer\Util\Perforce', $perforceMethods)->disableOriginalConstructor()->getMock(); + $perforce->expects($this->at(0))->method('setStream')->with($this->equalTo($ref)); + $perforce->expects($this->at(1))->method('p4Login')->with($this->identicalTo($this->io)); + $perforce->expects($this->at(2))->method('writeP4ClientSpec'); + $perforce->expects($this->at(3))->method('connectClient'); + $perforce->expects($this->at(4))->method('syncCodeBase'); + $perforce->expects($this->at(5))->method('cleanupClientSpec'); + $this->downloader->setPerforce($perforce); + $this->downloader->doDownload($this->package, $this->testPath); } } diff --git a/tests/Composer/Test/Util/PerforceTest.php b/tests/Composer/Test/Util/PerforceTest.php index f2eeb1964..56a234536 100644 --- a/tests/Composer/Test/Util/PerforceTest.php +++ b/tests/Composer/Test/Util/PerforceTest.php @@ -22,6 +22,7 @@ class PerforceTest extends \PHPUnit_Framework_TestCase { protected $perforce; protected $processExecutor; + protected $io; public function setUp() { @@ -32,7 +33,15 @@ class PerforceTest extends \PHPUnit_Framework_TestCase 'p4user' => 'user', 'unique_perforce_client_name' => 'TEST' ); - $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, true); + $io = $this->getMock('Composer\IO\IOInterface'); + $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, true, $io); + } + + public function tearDown() + { + $this->perforce = null; + $this->io = null; + $this->processExecutor = null; } public function testGetClientWithoutStream() From 24dd42267f391f49ee311672f9d93b009d21239b Mon Sep 17 00:00:00 2001 From: Clark Stuth Date: Mon, 17 Mar 2014 16:06:19 -0500 Subject: [PATCH 08/16] almost all unit tests passing after IOInterface dependency refactor. no longer passing IOInterface into any Perforce methods --- .../Downloader/PerforceDownloader.php | 2 +- .../Repository/Vcs/PerforceDriver.php | 8 +- src/Composer/Util/Perforce.php | 29 ++- .../Downloader/PerforceDownloaderTest.php | 13 +- .../Repository/Vcs/PerforceDriverTest.php | 186 +++++++------- tests/Composer/Test/Util/PerforceTest.php | 230 ++++++++---------- 6 files changed, 239 insertions(+), 229 deletions(-) diff --git a/src/Composer/Downloader/PerforceDownloader.php b/src/Composer/Downloader/PerforceDownloader.php index 632ac648c..da70c3469 100644 --- a/src/Composer/Downloader/PerforceDownloader.php +++ b/src/Composer/Downloader/PerforceDownloader.php @@ -44,7 +44,7 @@ class PerforceDownloader extends VcsDownloader public function initPerforce($package, $path) { - if ($this->perforce) { + if (!empty($this->perforce)) { $this->perforce->initializePath($path); return; } diff --git a/src/Composer/Repository/Vcs/PerforceDriver.php b/src/Composer/Repository/Vcs/PerforceDriver.php index 8a1b40623..6a55033a1 100644 --- a/src/Composer/Repository/Vcs/PerforceDriver.php +++ b/src/Composer/Repository/Vcs/PerforceDriver.php @@ -35,7 +35,7 @@ class PerforceDriver extends VcsDriver { $this->depot = $this->repoConfig['depot']; $this->branch = ''; - if (isset($this->repoConfig['branch'])) { + if (!empty($this->repoConfig['branch'])) { $this->branch = $this->repoConfig['branch']; } @@ -51,7 +51,7 @@ class PerforceDriver extends VcsDriver private function initPerforce($repoConfig) { - if (isset($this->perforce)) { + if (!empty($this->perforce)) { return; } @@ -64,7 +64,7 @@ class PerforceDriver extends VcsDriver */ public function getComposerInformation($identifier) { - if (isset($this->composerInfoIdentifier)) { + if (!empty($this->composerInfoIdentifier)) { if (strcmp($identifier, $this->composerInfoIdentifier) === 0) { return $this->composerInfo; } @@ -141,7 +141,7 @@ class PerforceDriver extends VcsDriver $this->composerInfo = $this->perforce->getComposerInformation('//' . $this->depot . '/' . $identifier); $this->composerInfoIdentifier = $identifier; $result = false; - if (isset($this->composerInfo)) { + if (!empty($this->composerInfo)) { $result = count($this->composerInfo) > 0; } diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index c3b66329f..2a1094e59 100644 --- a/src/Composer/Util/Perforce.php +++ b/src/Composer/Util/Perforce.php @@ -200,7 +200,12 @@ class Perforce return $this->p4User; } - public function queryP4User(IOInterface $io) + public function setUser($user) + { + $this->p4User = $user; + } + + public function queryP4User() { $this->getUser(); if (strlen($this->p4User) > 0) { @@ -210,7 +215,7 @@ class Perforce if (strlen($this->p4User) > 0) { return; } - $this->p4User = $io->ask('Enter P4 User:'); + $this->p4User = $this->io->ask('Enter P4 User:'); if ($this->windowsFlag) { $command = 'p4 set P4USER=' . $this->p4User; } else { @@ -248,14 +253,14 @@ class Perforce } } - public function queryP4Password(IOInterface $io) + public function queryP4Password() { if (isset($this->p4Password)) { return $this->p4Password; } $password = $this->getP4variable('P4PASSWD'); if (strlen($password) <= 0) { - $password = $io->askAndHideAnswer('Enter password for Perforce user ' . $this->getUser() . ': '); + $password = $this->io->askAndHideAnswer('Enter password for Perforce user ' . $this->getUser() . ': '); } $this->p4Password = $password; @@ -365,6 +370,16 @@ class Perforce return; } + public function getWindowsFlag() + { + return $this->windowsFlag; + } + + public function setWindowsFlag($flag) + { + $this->windowsFlag = $flag; + } + public function windowsLogin($password) { $command = $this->generateP4Command(' login -a'); @@ -373,11 +388,11 @@ class Perforce return $process->run(); } - public function p4Login(IOInterface $io) + public function p4Login() { - $this->queryP4User($io); + $this->queryP4User(); if (!$this->isLoggedIn()) { - $password = $this->queryP4Password($io); + $password = $this->queryP4Password(); if ($this->windowsFlag) { $this->windowsLogin($password); } else { diff --git a/tests/Composer/Test/Downloader/PerforceDownloaderTest.php b/tests/Composer/Test/Downloader/PerforceDownloaderTest.php index 0eb981362..c78f1ed13 100644 --- a/tests/Composer/Test/Downloader/PerforceDownloaderTest.php +++ b/tests/Composer/Test/Downloader/PerforceDownloaderTest.php @@ -122,12 +122,13 @@ class PerforceDownloaderTest extends \PHPUnit_Framework_TestCase $this->io->expects($this->once())->method('write')->with($this->stringContains('Cloning '.$ref)); $perforceMethods = array('setStream', 'p4Login', 'writeP4ClientSpec', 'connectClient', 'syncCodeBase', 'cleanupClientSpec'); $perforce = $this->getMockBuilder('Composer\Util\Perforce', $perforceMethods)->disableOriginalConstructor()->getMock(); - $perforce->expects($this->at(0))->method('setStream')->with($this->equalTo($ref)); - $perforce->expects($this->at(1))->method('p4Login')->with($this->identicalTo($this->io)); - $perforce->expects($this->at(2))->method('writeP4ClientSpec'); - $perforce->expects($this->at(3))->method('connectClient'); - $perforce->expects($this->at(4))->method('syncCodeBase'); - $perforce->expects($this->at(5))->method('cleanupClientSpec'); + $perforce->expects($this->at(0))->method('initializePath')->with($this->equalTo($this->testPath)); + $perforce->expects($this->at(1))->method('setStream')->with($this->equalTo($ref)); + $perforce->expects($this->at(2))->method('p4Login')->with($this->identicalTo($this->io)); + $perforce->expects($this->at(3))->method('writeP4ClientSpec'); + $perforce->expects($this->at(4))->method('connectClient'); + $perforce->expects($this->at(5))->method('syncCodeBase'); + $perforce->expects($this->at(6))->method('cleanupClientSpec'); $this->downloader->setPerforce($perforce); $this->downloader->doDownload($this->package, $this->testPath); } diff --git a/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php b/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php index 36cd69ebc..bc228de7e 100644 --- a/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php @@ -21,113 +21,129 @@ use Composer\Config; */ class PerforceDriverTest extends \PHPUnit_Framework_TestCase { - private $config; - private $io; - private $process; - private $remoteFileSystem; - private $testPath; + protected $config; + protected $io; + protected $process; + protected $remoteFileSystem; + protected $testPath; + protected $driver; + protected $repoConfig; + + const TEST_URL = 'TEST_PERFORCE_URL'; + const TEST_DEPOT = 'TEST_DEPOT_CONFIG'; + const TEST_BRANCH = 'TEST_BRANCH_CONFIG'; public function setUp() { - $this->testPath = sys_get_temp_dir() . '/composer-test'; - $this->config = new Config(); - $this->config->merge( - array( - 'config' => array( - 'home' => $this->testPath, - ), - ) - ); - - $this->io = $this->getMock('Composer\IO\IOInterface'); - $this->process = $this->getMock('Composer\Util\ProcessExecutor'); - $this->remoteFileSystem = $this->getMockBuilder('Composer\Util\RemoteFilesystem')->disableOriginalConstructor() - ->getMock(); + $this->testPath = sys_get_temp_dir() . '/composer-test'; + $this->config = $this->getTestConfig($this->testPath); + $this->repoConfig = $this->getTestRepoConfig(); + $this->io = $this->getMockIOInterface(); + $this->process = $this->getMockProcessExecutor(); + $this->remoteFileSystem = $this->getMockRemoteFilesystem(); + $this->perforce = $this->getMockPerforce(); + $this->driver = new PerforceDriver($this->repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem); } public function tearDown() { + //cleanup directory under test path $fs = new Filesystem; $fs->removeDirectory($this->testPath); + $this->driver = null; + $this->perforce = null; + $this->remoteFileSystem = null; + $this->process = null; + $this->io = null; + $this->repoConfig = null; + $this->config = null; + $this->testPath = null; + } + + protected function getTestConfig($testPath) + { + $config = new Config(); + $config->merge(array('config'=>array('home'=>$testPath))); + return $config; + } + + protected function getTestRepoConfig() + { + return array( + 'url' => self::TEST_URL, + 'depot' => self::TEST_DEPOT, + 'branch' => self::TEST_BRANCH, + ); + } + + protected function getMockIOInterface() + { + return $this->getMock('Composer\IO\IOInterface'); + } + + protected function getMockProcessExecutor() + { + return $this->getMock('Composer\Util\ProcessExecutor'); + } + + protected function getMockRemoteFilesystem() + { + return $this->getMockBuilder('Composer\Util\RemoteFilesystem')->disableOriginalConstructor()->getMock(); + } + + protected function getMockPerforce() + { + $methods = array('p4login', 'checkStream', 'writeP4ClientSpec', 'connectClient', 'getComposerInformation'); + return $this->getMockBuilder('Composer\Util\Perforce', $methods)->disableOriginalConstructor()->getMock(); } public function testInitializeCapturesVariablesFromRepoConfig() { - $this->setUp(); - $repoConfig = array( - 'url' => 'TEST_PERFORCE_URL', - 'depot' => 'TEST_DEPOT_CONFIG', - 'branch' => 'TEST_BRANCH_CONFIG' - ); - $driver = new PerforceDriver($repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem); - $process = $this->getMock('Composer\Util\ProcessExecutor'); - $arguments = array( - array('depot' => 'TEST_DEPOT', 'branch' => 'TEST_BRANCH'), - 'port' => 'TEST_PORT', - 'path' => $this->testPath, - $process, - true, - 'TEST' - ); - $perforce = $this->getMock('Composer\Util\Perforce', null, $arguments); - $driver->setPerforce($perforce); + $driver = new PerforceDriver($this->repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem); + $driver->setPerforce($this->perforce); $driver->initialize(); - $this->assertEquals('TEST_PERFORCE_URL', $driver->getUrl()); - $this->assertEquals('TEST_DEPOT_CONFIG', $driver->getDepot()); - $this->assertEquals('TEST_BRANCH_CONFIG', $driver->getBranch()); + $this->assertEquals(self::TEST_URL, $driver->getUrl()); + $this->assertEquals(self::TEST_DEPOT, $driver->getDepot()); + $this->assertEquals(self::TEST_BRANCH, $driver->getBranch()); } public function testInitializeLogsInAndConnectsClient() { - $this->setUp(); - $repoConfig = array( - 'url' => 'TEST_PERFORCE_URL', - 'depot' => 'TEST_DEPOT_CONFIG', - 'branch' => 'TEST_BRANCH_CONFIG' - ); - $driver = new PerforceDriver($repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem); - $perforce = $this->getMockBuilder('Composer\Util\Perforce')->disableOriginalConstructor()->getMock(); - $perforce->expects($this->at(0)) - ->method('p4Login') - ->with($this->io); - $perforce->expects($this->at(1)) - ->method('checkStream') - ->with($this->equalTo('TEST_DEPOT_CONFIG')); - $perforce->expects($this->at(2)) - ->method('writeP4ClientSpec'); - $perforce->expects($this->at(3)) - ->method('connectClient'); - - $driver->setPerforce($perforce); - $driver->initialize(); + $this->driver->setPerforce($this->perforce); + $this->perforce->expects($this->at(0))->method('p4Login')->with($this->identicalTo($this->io)); + $this->perforce->expects($this->at(1))->method('checkStream')->with($this->equalTo(self::TEST_DEPOT)); + $this->perforce->expects($this->at(2))->method('writeP4ClientSpec'); + $this->perforce->expects($this->at(3))->method('connectClient'); + $this->driver->initialize(); } - public function testHasComposerFile() + /** + * @depends testInitializeCapturesVariablesFromRepoConfig + * @depends testInitializeLogsInAndConnectsClient + */ + public function testHasComposerFileReturnsFalseOnNoComposerFile() { - $repoConfig = array( - 'url' => 'TEST_PERFORCE_URL', - 'depot' => 'TEST_DEPOT_CONFIG', - 'branch' => 'TEST_BRANCH_CONFIG' - ); - $driver = new PerforceDriver($repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem); - $process = $this->getMock('Composer\Util\ProcessExecutor'); - $arguments = array( - array('depot' => 'TEST_DEPOT', 'branch' => 'TEST_BRANCH'), - 'port' => 'TEST_PORT', - 'path' => $this->testPath, - $process, - true, - 'TEST' - ); - $perforce = $this->getMock('Composer\Util\Perforce', array('getComposerInformation'), $arguments); - $perforce->expects($this->at(0)) - ->method('getComposerInformation') - ->with($this->equalTo('//TEST_DEPOT_CONFIG/TEST_IDENTIFIER')) - ->will($this->returnValue('Some json stuff')); - $driver->setPerforce($perforce); - $driver->initialize(); $identifier = 'TEST_IDENTIFIER'; - $result = $driver->hasComposerFile($identifier); + $formatted_depot_path = '//' . self::TEST_DEPOT . '/' . $identifier; + $this->driver->setPerforce($this->perforce); + $this->perforce->expects($this->at(0))->method('getComposerInformation')->with($this->equalTo($formatted_depot_path))->will($this->returnValue(array())); + $this->driver->initialize(); + $result = $this->driver->hasComposerFile($identifier); + $this->assertFalse($result); + } + + /** + * @depends testInitializeCapturesVariablesFromRepoConfig + * @depends testInitializeLogsInAndConnectsClient + */ + public function testHasComposerFileReturnsTrueWithOneOrMoreComposerFiles() + { + $identifier = 'TEST_IDENTIFIER'; + $formatted_depot_path = '//' . self::TEST_DEPOT . '/' . $identifier; + $this->driver->setPerforce($this->perforce); + $this->perforce->expects($this->at(0))->method('getComposerInformation')->with($this->equalTo($formatted_depot_path))->will($this->returnValue(array(''))); + $this->driver->initialize(); + $result = $this->driver->hasComposerFile($identifier); $this->assertTrue($result); } diff --git a/tests/Composer/Test/Util/PerforceTest.php b/tests/Composer/Test/Util/PerforceTest.php index 56a234536..b7865d5e6 100644 --- a/tests/Composer/Test/Util/PerforceTest.php +++ b/tests/Composer/Test/Util/PerforceTest.php @@ -24,26 +24,44 @@ class PerforceTest extends \PHPUnit_Framework_TestCase protected $processExecutor; protected $io; + const TEST_DEPOT = 'depot'; + const TEST_BRANCH = 'branch'; + const TEST_P4USER = 'user'; + const TEST_CLIENT_NAME = 'TEST'; + const TEST_PORT = 'port'; + const TEST_PATH = 'path'; + public function setUp() { $this->processExecutor = $this->getMock('Composer\Util\ProcessExecutor'); - $repoConfig = array( - 'depot' => 'depot', - 'branch' => 'branch', - 'p4user' => 'user', - 'unique_perforce_client_name' => 'TEST' - ); - $io = $this->getMock('Composer\IO\IOInterface'); - $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, true, $io); + $this->repoConfig = $this->getTestRepoConfig(); + $this->io = $this->getMockIOInterface(); + $this->perforce = new Perforce($this->repoConfig, self::TEST_PORT, self::TEST_PATH, $this->processExecutor, true, $this->io); } public function tearDown() { - $this->perforce = null; - $this->io = null; + $this->perforce = null; + $this->io = null; + $this->repoConfig = null; $this->processExecutor = null; } + public function getTestRepoConfig() + { + return array( + 'depot' => self::TEST_DEPOT, + 'branch' => self::TEST_BRANCH, + 'p4user' => self::TEST_P4USER, + 'unique_perforce_client_name' => self::TEST_CLIENT_NAME + ); + } + + public function getMockIOInterface() + { + return $this->getMock('Composer\IO\IOInterface'); + } + public function testGetClientWithoutStream() { $client = $this->perforce->getClient(); @@ -107,116 +125,90 @@ class PerforceTest extends \PHPUnit_Framework_TestCase public function testQueryP4UserWithUserAlreadySet() { - $io = $this->getMock('Composer\IO\IOInterface'); - - $repoConfig = array('depot' => 'depot', 'branch' => 'branch', 'p4user' => 'TEST_USER'); - $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, true, 'TEST'); - - $this->perforce->queryP4user($io); - $this->assertEquals('TEST_USER', $this->perforce->getUser()); + $this->perforce->queryP4user(); + $this->assertEquals(self::TEST_P4USER, $this->perforce->getUser()); } public function testQueryP4UserWithUserSetInP4VariablesWithWindowsOS() { - $repoConfig = array('depot' => 'depot', 'branch' => 'branch'); - $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, true, 'TEST'); - - $io = $this->getMock('Composer\IO\IOInterface'); + $this->perforce->setUser(null); + $this->perforce->setWindowsFlag(true); $expectedCommand = 'p4 set'; + $callback = function($command, &$output) + { + $output = 'P4USER=TEST_P4VARIABLE_USER' . PHP_EOL; + return true; + }; $this->processExecutor->expects($this->at(0)) - ->method('execute') - ->with($this->equalTo($expectedCommand)) - ->will( - $this->returnCallback( - function ($command, &$output) { - $output = 'P4USER=TEST_P4VARIABLE_USER' . PHP_EOL ; - - return true; - } - ) - ); - - $this->perforce->queryP4user($io); + ->method('execute') + ->with($this->equalTo($expectedCommand)) + ->will($this->returnCallback($callback)); + $this->perforce->queryP4user(); $this->assertEquals('TEST_P4VARIABLE_USER', $this->perforce->getUser()); } public function testQueryP4UserWithUserSetInP4VariablesNotWindowsOS() { - $repoConfig = array('depot' => 'depot', 'branch' => 'branch'); - $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, false, 'TEST'); - - $io = $this->getMock('Composer\IO\IOInterface'); + $this->perforce->setUser(null); + $this->perforce->setWindowsFlag(false); $expectedCommand = 'echo $P4USER'; + $callback = function($command, &$output) + { + $output = 'TEST_P4VARIABLE_USER' . PHP_EOL; + return true; + }; $this->processExecutor->expects($this->at(0)) - ->method('execute') - ->with($this->equalTo($expectedCommand)) - ->will( - $this->returnCallback( - function ($command, &$output) { - $output = 'TEST_P4VARIABLE_USER' . PHP_EOL; - - return true; - } - ) - ); - - $this->perforce->queryP4user($io); + ->method('execute') + ->with($this->equalTo($expectedCommand)) + ->will($this->returnCallback($callback)); + $this->perforce->queryP4user(); $this->assertEquals('TEST_P4VARIABLE_USER', $this->perforce->getUser()); } public function testQueryP4UserQueriesForUser() { - $repoConfig = array('depot' => 'depot', 'branch' => 'branch'); - $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, false, 'TEST'); - $io = $this->getMock('Composer\IO\IOInterface'); + $this->perforce->setUser(null); $expectedQuestion = 'Enter P4 User:'; - $io->expects($this->at(0)) - ->method('ask') - ->with($this->equalTo($expectedQuestion)) - ->will($this->returnValue('TEST_QUERY_USER')); - - $this->perforce->queryP4user($io); + $this->io->expects($this->at(0)) + ->method('ask') + ->with($this->equalTo($expectedQuestion)) + ->will($this->returnValue('TEST_QUERY_USER')); + $this->perforce->queryP4user(); $this->assertEquals('TEST_QUERY_USER', $this->perforce->getUser()); } public function testQueryP4UserStoresResponseToQueryForUserWithWindows() { - $repoConfig = array('depot' => 'depot', 'branch' => 'branch'); - $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, true, 'TEST'); - - $io = $this->getMock('Composer\IO\IOInterface'); + $this->perforce->setUser(null); + $this->perforce->setWindowsFlag(true); $expectedQuestion = 'Enter P4 User:'; - $io->expects($this->at(0)) - ->method('ask') - ->with($this->equalTo($expectedQuestion)) - ->will($this->returnValue('TEST_QUERY_USER')); - $expectedCommand = 'p4 set P4USER=TEST_QUERY_USER'; + $expectedCommand = 'p4 set P4USER=TEST_QUERY_USER'; + $this->io->expects($this->at(0)) + ->method('ask') + ->with($this->equalTo($expectedQuestion)) + ->will($this->returnValue('TEST_QUERY_USER')); $this->processExecutor->expects($this->at(1)) - ->method('execute') - ->with($this->equalTo($expectedCommand)) - ->will($this->returnValue(0)); - - $this->perforce->queryP4user($io); + ->method('execute') + ->with($this->equalTo($expectedCommand)) + ->will($this->returnValue(0)); + $this->perforce->queryP4user(); } public function testQueryP4UserStoresResponseToQueryForUserWithoutWindows() { - $repoConfig = array('depot' => 'depot', 'branch' => 'branch'); - $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, false, 'TEST'); - - $io = $this->getMock('Composer\IO\IOInterface'); + $this->perforce->setUser(null); + $this->perforce->setWindowsFlag(false); $expectedQuestion = 'Enter P4 User:'; - $io->expects($this->at(0)) - ->method('ask') - ->with($this->equalTo($expectedQuestion)) - ->will($this->returnValue('TEST_QUERY_USER')); - $expectedCommand = 'export P4USER=TEST_QUERY_USER'; + $expectedCommand = 'export P4USER=TEST_QUERY_USER'; + $this->io->expects($this->at(0)) + ->method('ask') + ->with($this->equalTo($expectedQuestion)) + ->will($this->returnValue('TEST_QUERY_USER')); $this->processExecutor->expects($this->at(1)) - ->method('execute') - ->with($this->equalTo($expectedCommand)) - ->will($this->returnValue(0)); - - $this->perforce->queryP4user($io); + ->method('execute') + ->with($this->equalTo($expectedCommand)) + ->will($this->returnValue(0)); + $this->perforce->queryP4user(); } public function testQueryP4PasswordWithPasswordAlreadySet() @@ -227,69 +219,55 @@ class PerforceTest extends \PHPUnit_Framework_TestCase 'p4user' => 'user', 'p4password' => 'TEST_PASSWORD' ); - $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, false, 'TEST'); - $io = $this->getMock('Composer\IO\IOInterface'); - - $password = $this->perforce->queryP4Password($io); + $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, false, $this->getMockIOInterface(), 'TEST'); + $password = $this->perforce->queryP4Password(); $this->assertEquals('TEST_PASSWORD', $password); } public function testQueryP4PasswordWithPasswordSetInP4VariablesWithWindowsOS() { - $io = $this->getMock('Composer\IO\IOInterface'); - + $this->perforce->setWindowsFlag(true); $expectedCommand = 'p4 set'; + $callback = function($command, &$output) + { + $output = 'P4PASSWD=TEST_P4VARIABLE_PASSWORD' . PHP_EOL; + return true; + }; $this->processExecutor->expects($this->at(0)) - ->method('execute') - ->with($this->equalTo($expectedCommand)) - ->will( - $this->returnCallback( - function ($command, &$output) { - $output = 'P4PASSWD=TEST_P4VARIABLE_PASSWORD' . PHP_EOL; - - return true; - } - ) - ); - - $password = $this->perforce->queryP4Password($io); + ->method('execute') + ->with($this->equalTo($expectedCommand)) + ->will($this->returnCallback($callback)); + $password = $this->perforce->queryP4Password(); $this->assertEquals('TEST_P4VARIABLE_PASSWORD', $password); } public function testQueryP4PasswordWithPasswordSetInP4VariablesNotWindowsOS() { - $repoConfig = array('depot' => 'depot', 'branch' => 'branch', 'p4user' => 'user'); - $this->perforce = new Perforce($repoConfig, 'port', 'path', $this->processExecutor, false, 'TEST'); - - $io = $this->getMock('Composer\IO\IOInterface'); + $this->perforce->setWindowsFlag(false); $expectedCommand = 'echo $P4PASSWD'; + $callback = function($command, &$output) + { + $output = 'TEST_P4VARIABLE_PASSWORD' . PHP_EOL; + return true; + }; $this->processExecutor->expects($this->at(0)) - ->method('execute') - ->with($this->equalTo($expectedCommand)) - ->will( - $this->returnCallback( - function ($command, &$output) { - $output = 'TEST_P4VARIABLE_PASSWORD' . PHP_EOL; + ->method('execute') + ->with($this->equalTo($expectedCommand)) + ->will($this->returnCallback($callback)); - return true; - } - ) - ); - - $password = $this->perforce->queryP4Password($io); + $password = $this->perforce->queryP4Password(); $this->assertEquals('TEST_P4VARIABLE_PASSWORD', $password); } public function testQueryP4PasswordQueriesForPassword() { - $io = $this->getMock('Composer\IO\IOInterface'); $expectedQuestion = 'Enter password for Perforce user user: '; - $io->expects($this->at(0)) + $this->io->expects($this->at(0)) ->method('askAndHideAnswer') ->with($this->equalTo($expectedQuestion)) ->will($this->returnValue('TEST_QUERY_PASSWORD')); - $password = $this->perforce->queryP4Password($io); + $password = $this->perforce->queryP4Password(); $this->assertEquals('TEST_QUERY_PASSWORD', $password); } From 492539101cf660f394545bbde32152c29ec1d965 Mon Sep 17 00:00:00 2001 From: Clark Stuth Date: Tue, 18 Mar 2014 13:52:54 -0500 Subject: [PATCH 09/16] got all unit tests passing --- src/Composer/Repository/Vcs/PerforceDriver.php | 2 ++ src/Composer/Util/Perforce.php | 2 +- tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Composer/Repository/Vcs/PerforceDriver.php b/src/Composer/Repository/Vcs/PerforceDriver.php index 6a55033a1..535a79516 100644 --- a/src/Composer/Repository/Vcs/PerforceDriver.php +++ b/src/Composer/Repository/Vcs/PerforceDriver.php @@ -141,6 +141,8 @@ class PerforceDriver extends VcsDriver $this->composerInfo = $this->perforce->getComposerInformation('//' . $this->depot . '/' . $identifier); $this->composerInfoIdentifier = $identifier; $result = false; + return !empty($this->composerInfo); + if (!empty($this->composerInfo)) { $result = count($this->composerInfo) > 0; } diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index 2a1094e59..ecafaf6f0 100644 --- a/src/Composer/Util/Perforce.php +++ b/src/Composer/Util/Perforce.php @@ -47,7 +47,7 @@ class Perforce $this->io = $io; } - public static function create($repoConfig, $port, $path, ProcessExecutor $process = null, IOInterface $io) + public static function create($repoConfig, $port, $path, ProcessExecutor $process, IOInterface $io) { if (!isset($process)) { $process = new ProcessExecutor; diff --git a/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php b/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php index bc228de7e..7666efebc 100644 --- a/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php @@ -126,7 +126,7 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase $identifier = 'TEST_IDENTIFIER'; $formatted_depot_path = '//' . self::TEST_DEPOT . '/' . $identifier; $this->driver->setPerforce($this->perforce); - $this->perforce->expects($this->at(0))->method('getComposerInformation')->with($this->equalTo($formatted_depot_path))->will($this->returnValue(array())); + $this->perforce->expects($this->any())->method('getComposerInformation')->with($this->equalTo($formatted_depot_path))->will($this->returnValue(array())); $this->driver->initialize(); $result = $this->driver->hasComposerFile($identifier); $this->assertFalse($result); @@ -141,7 +141,7 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase $identifier = 'TEST_IDENTIFIER'; $formatted_depot_path = '//' . self::TEST_DEPOT . '/' . $identifier; $this->driver->setPerforce($this->perforce); - $this->perforce->expects($this->at(0))->method('getComposerInformation')->with($this->equalTo($formatted_depot_path))->will($this->returnValue(array(''))); + $this->perforce->expects($this->any())->method('getComposerInformation')->with($this->equalTo($formatted_depot_path))->will($this->returnValue(array(''))); $this->driver->initialize(); $result = $this->driver->hasComposerFile($identifier); $this->assertTrue($result); From c11105dd6033f25225ce2c16baf64465f891e2a8 Mon Sep 17 00:00:00 2001 From: Clark Stuth Date: Tue, 18 Mar 2014 14:39:47 -0500 Subject: [PATCH 10/16] Fixing bug not cleaning up workspaces. --- .../Repository/Vcs/PerforceDriver.php | 6 +++++ src/Composer/Util/Perforce.php | 24 ++++++++++++++++--- .../Repository/Vcs/PerforceDriverTest.php | 11 ++++++++- tests/Composer/Test/Util/PerforceTest.php | 15 ++++++++++++ 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/Composer/Repository/Vcs/PerforceDriver.php b/src/Composer/Repository/Vcs/PerforceDriver.php index 535a79516..090de1bb8 100644 --- a/src/Composer/Repository/Vcs/PerforceDriver.php +++ b/src/Composer/Repository/Vcs/PerforceDriver.php @@ -193,4 +193,10 @@ class PerforceDriver extends VcsDriver { $this->perforce = $perforce; } + + public function getPerforce() + { + return $this->perforce; + } + } diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index ecafaf6f0..659cbfc67 100644 --- a/src/Composer/Util/Perforce.php +++ b/src/Composer/Util/Perforce.php @@ -37,6 +37,8 @@ class Perforce protected $io; + protected $filesystem; + public function __construct($repoConfig, $port, $path, ProcessExecutor $process, $isWindows, IOInterface $io) { $this->windowsFlag = $isWindows; @@ -109,10 +111,10 @@ class Perforce public function cleanupClientSpec() { $client = $this->getClient(); - $command = 'p4 client -d $client'; + $command = 'p4 client -d ' . $client; $this->executeCommand($command); $clientSpec = $this->getP4ClientSpec(); - $fileSystem = new FileSystem($this->process); + $fileSystem = $this->getFilesystem(); $fileSystem->remove($clientSpec); } @@ -141,7 +143,7 @@ class Perforce public function initializePath($path) { $this->path = $path; - $fs = new Filesystem(); + $fs = $this->getFilesystem(); $fs->ensureDirectoryExists($path); } @@ -559,4 +561,20 @@ class Perforce return $result; } + + public function getFilesystem() + { + if (empty($this->filesystem)) + { + $this->filesystem = new Filesystem($this->process); + } + return $this->filesystem; + } + + + public function setFilesystem(Filesystem $fs) + { + $this->filesystem = $fs; + } + } diff --git a/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php b/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php index 7666efebc..9afc57d30 100644 --- a/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php @@ -93,7 +93,7 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase protected function getMockPerforce() { - $methods = array('p4login', 'checkStream', 'writeP4ClientSpec', 'connectClient', 'getComposerInformation'); + $methods = array('p4login', 'checkStream', 'writeP4ClientSpec', 'connectClient', 'getComposerInformation', 'cleanupClientSpec'); return $this->getMockBuilder('Composer\Util\Perforce', $methods)->disableOriginalConstructor()->getMock(); } @@ -159,4 +159,13 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase $this->expectOutputString(''); $this->assertFalse(PerforceDriver::supports($this->io, $this->config, 'existing.url')); } + + public function testCleanup() + { + $this->perforce->expects($this->once())->method('cleanupClientSpec'); + $this->driver->setPerforce($this->perforce); + $this->driver->cleanup(); + $this->assertNull($this->driver->getPerforce()); + } + } diff --git a/tests/Composer/Test/Util/PerforceTest.php b/tests/Composer/Test/Util/PerforceTest.php index b7865d5e6..65857343b 100644 --- a/tests/Composer/Test/Util/PerforceTest.php +++ b/tests/Composer/Test/Util/PerforceTest.php @@ -679,4 +679,19 @@ class PerforceTest extends \PHPUnit_Framework_TestCase { $this->perforce->setStream('//depot/branch'); } + + public function testCleanupClientSpecShouldDeleteClient() + { + $fs = $this->getMock('Composer\Util\Filesystem'); + $this->perforce->setFilesystem($fs); + + $testClient = $this->perforce->getClient(); + $expectedCommand = 'p4 client -d ' . $testClient; + $this->processExecutor->expects($this->once())->method('execute')->with($this->equalTo($expectedCommand)); + + $fs->expects($this->once())->method('remove')->with($this->perforce->getP4ClientSpec()); + + $this->perforce->cleanupClientSpec(); + } + } From 8fc1961463e4ff549a7e949259dedee2a86bdf64 Mon Sep 17 00:00:00 2001 From: Clark Stuth Date: Wed, 19 Mar 2014 13:58:41 -0500 Subject: [PATCH 11/16] Fixing delete client workspace bug. --- src/Composer/Util/Perforce.php | 4 +++- tests/Composer/Test/Util/PerforceTest.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index 659cbfc67..f3e9d2023 100644 --- a/src/Composer/Util/Perforce.php +++ b/src/Composer/Util/Perforce.php @@ -111,7 +111,9 @@ class Perforce public function cleanupClientSpec() { $client = $this->getClient(); - $command = 'p4 client -d ' . $client; + $task = 'client -d ' . $client; + $useP4Client = false; + $command = $this->generateP4Command($task, $useP4Client); $this->executeCommand($command); $clientSpec = $this->getP4ClientSpec(); $fileSystem = $this->getFilesystem(); diff --git a/tests/Composer/Test/Util/PerforceTest.php b/tests/Composer/Test/Util/PerforceTest.php index 65857343b..06e3cce8b 100644 --- a/tests/Composer/Test/Util/PerforceTest.php +++ b/tests/Composer/Test/Util/PerforceTest.php @@ -686,7 +686,7 @@ class PerforceTest extends \PHPUnit_Framework_TestCase $this->perforce->setFilesystem($fs); $testClient = $this->perforce->getClient(); - $expectedCommand = 'p4 client -d ' . $testClient; + $expectedCommand = 'p4 -u ' . self::TEST_P4USER . ' -p ' . self::TEST_PORT . ' client -d ' . $testClient; $this->processExecutor->expects($this->once())->method('execute')->with($this->equalTo($expectedCommand)); $fs->expects($this->once())->method('remove')->with($this->perforce->getP4ClientSpec()); From 2651cbc5fe573a61d0dec106f8c48e6187ba05fc Mon Sep 17 00:00:00 2001 From: Clark Stuth Date: Fri, 21 Mar 2014 13:42:00 -0500 Subject: [PATCH 12/16] Fixing perforce dev-master stored reference bug. --- src/Composer/Util/Perforce.php | 17 ++++++++-------- tests/Composer/Test/Util/PerforceTest.php | 24 +++++++++++++++++++++-- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index f3e9d2023..ae6f44d04 100644 --- a/src/Composer/Util/Perforce.php +++ b/src/Composer/Util/Perforce.php @@ -315,11 +315,7 @@ class Perforce chdir($this->path); $p4SyncCommand = $this->generateP4Command('sync -f '); - if (isset($label)) { - if (strcmp($label, 'dev-master') != 0) { - $p4SyncCommand = $p4SyncCommand . '@' . $label; - } - } + $p4SyncCommand = $p4SyncCommand . '@' . $label; $this->executeCommand($p4SyncCommand); chdir($prevDir); @@ -481,9 +477,15 @@ class Perforce } } } - $branches = array(); - $branches['master'] = $possibleBranches[$this->p4Branch]; + $command = $this->generateP4Command('changes '. $this->getStream() . '/...', false); + $this->executeCommand($command); + $result = $this->commandResult; + $resArray = explode(PHP_EOL, $result); + $lastCommit = $resArray[0]; + $lastCommitArr = explode(' ', $lastCommit); + $lastCommitNum = $lastCommitArr[1]; + $branches = array('master' => $possibleBranches[$this->p4Branch] . '@'. $lastCommitNum); return $branches; } @@ -501,7 +503,6 @@ class Perforce $tags[$fields[1]] = $this->getStream() . '@' . $fields[1]; } } - return $tags; } diff --git a/tests/Composer/Test/Util/PerforceTest.php b/tests/Composer/Test/Util/PerforceTest.php index 06e3cce8b..1b8063258 100644 --- a/tests/Composer/Test/Util/PerforceTest.php +++ b/tests/Composer/Test/Util/PerforceTest.php @@ -351,15 +351,35 @@ class PerforceTest extends \PHPUnit_Framework_TestCase } ) ); + $expectedCommand2 = 'p4 -u user -p port changes //depot/branch/...'; + $expectedCallback = function($command, &$output) + { + $output = 'Change 1234 on 2014/03/19 by Clark.Stuth@Clark.Stuth_test_client \'test changelist\''; + return true; + }; + $this->processExecutor->expects($this->at(1)) + ->method('execute') + ->with($this->equalTo($expectedCommand2)) + ->will($this->returnCallback($expectedCallback)); $branches = $this->perforce->getBranches(); - $this->assertEquals('//depot/branch', $branches['master']); + $this->assertEquals('//depot/branch@1234', $branches['master']); } public function testGetBranchesWithoutStream() { + $expectedCommand = 'p4 -u user -p port changes //depot/...'; + $expectedCallback = function($command, &$output) + { + $output = 'Change 5678 on 2014/03/19 by Clark.Stuth@Clark.Stuth_test_client \'test changelist\''; + return true; + }; + $this->processExecutor->expects($this->once()) + ->method('execute') + ->with($this->equalTo($expectedCommand)) + ->will($this->returnCallback($expectedCallback)); $branches = $this->perforce->getBranches(); - $this->assertEquals('//depot', $branches['master']); + $this->assertEquals('//depot@5678', $branches['master']); } public function testGetTagsWithoutStream() From 3a3661a0b3ff307e5084fa4846c6e72feb904022 Mon Sep 17 00:00:00 2001 From: Clark Stuth Date: Mon, 24 Mar 2014 09:43:45 -0500 Subject: [PATCH 13/16] removing dead code lines and excess comments --- src/Composer/Downloader/PerforceDownloader.php | 1 - src/Composer/Repository/Vcs/PerforceDriver.php | 6 ------ 2 files changed, 7 deletions(-) diff --git a/src/Composer/Downloader/PerforceDownloader.php b/src/Composer/Downloader/PerforceDownloader.php index da70c3469..c2def4ee2 100644 --- a/src/Composer/Downloader/PerforceDownloader.php +++ b/src/Composer/Downloader/PerforceDownloader.php @@ -22,7 +22,6 @@ use Composer\Util\Perforce; class PerforceDownloader extends VcsDownloader { protected $perforce; -// protected $perforceInjected = false; /** * {@inheritDoc} diff --git a/src/Composer/Repository/Vcs/PerforceDriver.php b/src/Composer/Repository/Vcs/PerforceDriver.php index 090de1bb8..9599dd964 100644 --- a/src/Composer/Repository/Vcs/PerforceDriver.php +++ b/src/Composer/Repository/Vcs/PerforceDriver.php @@ -142,12 +142,6 @@ class PerforceDriver extends VcsDriver $this->composerInfoIdentifier = $identifier; $result = false; return !empty($this->composerInfo); - - if (!empty($this->composerInfo)) { - $result = count($this->composerInfo) > 0; - } - - return $result; } /** From dd1fd0e306dbad073fa8b32c0b23eea52ada8dea Mon Sep 17 00:00:00 2001 From: Clark Stuth Date: Mon, 24 Mar 2014 15:19:35 -0500 Subject: [PATCH 14/16] fixed perforce to reference labels instead of invalid tags --- .../Downloader/PerforceDownloader.php | 12 ++++++- src/Composer/Util/Perforce.php | 8 ++--- .../Downloader/PerforceDownloaderTest.php | 33 ++++++++++++++++--- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/Composer/Downloader/PerforceDownloader.php b/src/Composer/Downloader/PerforceDownloader.php index c2def4ee2..8892e4b74 100644 --- a/src/Composer/Downloader/PerforceDownloader.php +++ b/src/Composer/Downloader/PerforceDownloader.php @@ -29,7 +29,7 @@ class PerforceDownloader extends VcsDownloader public function doDownload(PackageInterface $package, $path) { $ref = $package->getSourceReference(); - $label = $package->getPrettyVersion(); + $label = $this->getLabelFromSourceReference($ref); $this->io->write(' Cloning ' . $ref); $this->initPerforce($package, $path); @@ -41,6 +41,16 @@ class PerforceDownloader extends VcsDownloader $this->perforce->cleanupClientSpec(); } + private function getLabelFromSourceReference($ref) + { + $pos = strpos($ref,'@'); + if (false !== $pos) + { + return substr($ref, $pos + 1); + } + return null; + } + public function initPerforce($package, $path) { if (!empty($this->perforce)) { diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index ae6f44d04..7801f966b 100644 --- a/src/Composer/Util/Perforce.php +++ b/src/Composer/Util/Perforce.php @@ -309,15 +309,15 @@ class Perforce $this->executeCommand($p4CreateClientCommand); } - public function syncCodeBase($label) + public function syncCodeBase($sourceReference) { $prevDir = getcwd(); chdir($this->path); - $p4SyncCommand = $this->generateP4Command('sync -f '); - $p4SyncCommand = $p4SyncCommand . '@' . $label; + if (null != $sourceReference) { + $p4SyncCommand = $p4SyncCommand . '@' . $sourceReference; + } $this->executeCommand($p4SyncCommand); - chdir($prevDir); } diff --git a/tests/Composer/Test/Downloader/PerforceDownloaderTest.php b/tests/Composer/Test/Downloader/PerforceDownloaderTest.php index c78f1ed13..da93db767 100644 --- a/tests/Composer/Test/Downloader/PerforceDownloaderTest.php +++ b/tests/Composer/Test/Downloader/PerforceDownloaderTest.php @@ -112,13 +112,12 @@ class PerforceDownloaderTest extends \PHPUnit_Framework_TestCase * @depends testInitPerforceInstantiatesANewPerforceObject * @depends testInitPerforceDoesNothingIfPerforceAlreadySet */ - public function testDoDownload() + public function testDoDownloadWithTag() { //I really don't like this test but the logic of each Perforce method is tested in the Perforce class. Really I am just enforcing workflow. - $ref = 'SOURCE_REF'; - $label = 'LABEL'; + $ref = 'SOURCE_REF@123'; + $label = 123; $this->package->expects($this->once())->method('getSourceReference')->will($this->returnValue($ref)); - $this->package->expects($this->once())->method('getPrettyVersion')->will($this->returnValue($label)); $this->io->expects($this->once())->method('write')->with($this->stringContains('Cloning '.$ref)); $perforceMethods = array('setStream', 'p4Login', 'writeP4ClientSpec', 'connectClient', 'syncCodeBase', 'cleanupClientSpec'); $perforce = $this->getMockBuilder('Composer\Util\Perforce', $perforceMethods)->disableOriginalConstructor()->getMock(); @@ -127,9 +126,33 @@ class PerforceDownloaderTest extends \PHPUnit_Framework_TestCase $perforce->expects($this->at(2))->method('p4Login')->with($this->identicalTo($this->io)); $perforce->expects($this->at(3))->method('writeP4ClientSpec'); $perforce->expects($this->at(4))->method('connectClient'); - $perforce->expects($this->at(5))->method('syncCodeBase'); + $perforce->expects($this->at(5))->method('syncCodeBase')->with($label); $perforce->expects($this->at(6))->method('cleanupClientSpec'); $this->downloader->setPerforce($perforce); $this->downloader->doDownload($this->package, $this->testPath); } + + /** + * @depends testInitPerforceInstantiatesANewPerforceObject + * @depends testInitPerforceDoesNothingIfPerforceAlreadySet + */ + public function testDoDownloadWithNoTag() + { + $ref = 'SOURCE_REF'; + $label = null; + $this->package->expects($this->once())->method('getSourceReference')->will($this->returnValue($ref)); + $this->io->expects($this->once())->method('write')->with($this->stringContains('Cloning '.$ref)); + $perforceMethods = array('setStream', 'p4Login', 'writeP4ClientSpec', 'connectClient', 'syncCodeBase', 'cleanupClientSpec'); + $perforce = $this->getMockBuilder('Composer\Util\Perforce', $perforceMethods)->disableOriginalConstructor()->getMock(); + $perforce->expects($this->at(0))->method('initializePath')->with($this->equalTo($this->testPath)); + $perforce->expects($this->at(1))->method('setStream')->with($this->equalTo($ref)); + $perforce->expects($this->at(2))->method('p4Login')->with($this->identicalTo($this->io)); + $perforce->expects($this->at(3))->method('writeP4ClientSpec'); + $perforce->expects($this->at(4))->method('connectClient'); + $perforce->expects($this->at(5))->method('syncCodeBase')->with($label); + $perforce->expects($this->at(6))->method('cleanupClientSpec'); + $this->downloader->setPerforce($perforce); + $this->downloader->doDownload($this->package, $this->testPath); + } + } From a12c4e2a1722730c199b32e90b3be5240f2f4698 Mon Sep 17 00:00:00 2001 From: Clark Stuth Date: Tue, 25 Mar 2014 08:30:44 -0500 Subject: [PATCH 15/16] Removed getWindowsFlag and setWindowsFlag methods from Perforce object. --- .../Repository/Vcs/PerforceDriver.php | 11 --------- src/Composer/Util/Perforce.php | 10 -------- .../Downloader/PerforceDownloaderTest.php | 4 ++-- .../Repository/Vcs/PerforceDriverTest.php | 20 +++++++++------- tests/Composer/Test/Util/PerforceTest.php | 23 +++++++++++-------- 5 files changed, 28 insertions(+), 40 deletions(-) diff --git a/src/Composer/Repository/Vcs/PerforceDriver.php b/src/Composer/Repository/Vcs/PerforceDriver.php index 9599dd964..e928e5835 100644 --- a/src/Composer/Repository/Vcs/PerforceDriver.php +++ b/src/Composer/Repository/Vcs/PerforceDriver.php @@ -140,7 +140,6 @@ class PerforceDriver extends VcsDriver { $this->composerInfo = $this->perforce->getComposerInformation('//' . $this->depot . '/' . $identifier); $this->composerInfoIdentifier = $identifier; - $result = false; return !empty($this->composerInfo); } @@ -183,14 +182,4 @@ class PerforceDriver extends VcsDriver return $this->branch; } - public function setPerforce(Perforce $perforce) - { - $this->perforce = $perforce; - } - - public function getPerforce() - { - return $this->perforce; - } - } diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index 7801f966b..e812fbce3 100644 --- a/src/Composer/Util/Perforce.php +++ b/src/Composer/Util/Perforce.php @@ -370,16 +370,6 @@ class Perforce return; } - public function getWindowsFlag() - { - return $this->windowsFlag; - } - - public function setWindowsFlag($flag) - { - $this->windowsFlag = $flag; - } - public function windowsLogin($password) { $command = $this->generateP4Command(' login -a'); diff --git a/tests/Composer/Test/Downloader/PerforceDownloaderTest.php b/tests/Composer/Test/Downloader/PerforceDownloaderTest.php index da93db767..7562f7fca 100644 --- a/tests/Composer/Test/Downloader/PerforceDownloaderTest.php +++ b/tests/Composer/Test/Downloader/PerforceDownloaderTest.php @@ -32,7 +32,7 @@ class PerforceDownloaderTest extends \PHPUnit_Framework_TestCase protected $repository; protected $testPath; - public function setUp() + protected function setUp() { $this->testPath = sys_get_temp_dir() . '/composer-test'; $this->repoConfig = $this->getRepoConfig(); @@ -44,7 +44,7 @@ class PerforceDownloaderTest extends \PHPUnit_Framework_TestCase $this->downloader = new PerforceDownloader($this->io, $this->config, $this->processExecutor); } - public function tearDown() + protected function tearDown() { $this->downloader = null; $this->package = null; diff --git a/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php b/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php index 9afc57d30..dcb50244a 100644 --- a/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php @@ -15,6 +15,7 @@ namespace Composer\Test\Repository\Vcs; use Composer\Repository\Vcs\PerforceDriver; use Composer\Util\Filesystem; use Composer\Config; +use Composer\Util\Perforce; /** * @author Matt Whittom @@ -33,7 +34,7 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase const TEST_DEPOT = 'TEST_DEPOT_CONFIG'; const TEST_BRANCH = 'TEST_BRANCH_CONFIG'; - public function setUp() + protected function setUp() { $this->testPath = sys_get_temp_dir() . '/composer-test'; $this->config = $this->getTestConfig($this->testPath); @@ -43,9 +44,10 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase $this->remoteFileSystem = $this->getMockRemoteFilesystem(); $this->perforce = $this->getMockPerforce(); $this->driver = new PerforceDriver($this->repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem); + $this->overrideDriverInternalPerforce($this->perforce); } - public function tearDown() + protected function tearDown() { //cleanup directory under test path $fs = new Filesystem; @@ -60,6 +62,14 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase $this->testPath = null; } + protected function overrideDriverInternalPerforce(Perforce $perforce) + { + $reflectionClass = new \ReflectionClass($this->driver); + $property = $reflectionClass->getProperty('perforce'); + $property->setAccessible(true); + $property->setValue($this->driver, $perforce); + } + protected function getTestConfig($testPath) { $config = new Config(); @@ -100,7 +110,6 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase public function testInitializeCapturesVariablesFromRepoConfig() { $driver = new PerforceDriver($this->repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem); - $driver->setPerforce($this->perforce); $driver->initialize(); $this->assertEquals(self::TEST_URL, $driver->getUrl()); $this->assertEquals(self::TEST_DEPOT, $driver->getDepot()); @@ -109,7 +118,6 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase public function testInitializeLogsInAndConnectsClient() { - $this->driver->setPerforce($this->perforce); $this->perforce->expects($this->at(0))->method('p4Login')->with($this->identicalTo($this->io)); $this->perforce->expects($this->at(1))->method('checkStream')->with($this->equalTo(self::TEST_DEPOT)); $this->perforce->expects($this->at(2))->method('writeP4ClientSpec'); @@ -125,7 +133,6 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase { $identifier = 'TEST_IDENTIFIER'; $formatted_depot_path = '//' . self::TEST_DEPOT . '/' . $identifier; - $this->driver->setPerforce($this->perforce); $this->perforce->expects($this->any())->method('getComposerInformation')->with($this->equalTo($formatted_depot_path))->will($this->returnValue(array())); $this->driver->initialize(); $result = $this->driver->hasComposerFile($identifier); @@ -140,7 +147,6 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase { $identifier = 'TEST_IDENTIFIER'; $formatted_depot_path = '//' . self::TEST_DEPOT . '/' . $identifier; - $this->driver->setPerforce($this->perforce); $this->perforce->expects($this->any())->method('getComposerInformation')->with($this->equalTo($formatted_depot_path))->will($this->returnValue(array(''))); $this->driver->initialize(); $result = $this->driver->hasComposerFile($identifier); @@ -163,9 +169,7 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase public function testCleanup() { $this->perforce->expects($this->once())->method('cleanupClientSpec'); - $this->driver->setPerforce($this->perforce); $this->driver->cleanup(); - $this->assertNull($this->driver->getPerforce()); } } diff --git a/tests/Composer/Test/Util/PerforceTest.php b/tests/Composer/Test/Util/PerforceTest.php index 1b8063258..a5f3e60fa 100644 --- a/tests/Composer/Test/Util/PerforceTest.php +++ b/tests/Composer/Test/Util/PerforceTest.php @@ -31,15 +31,15 @@ class PerforceTest extends \PHPUnit_Framework_TestCase const TEST_PORT = 'port'; const TEST_PATH = 'path'; - public function setUp() + protected function setUp() { $this->processExecutor = $this->getMock('Composer\Util\ProcessExecutor'); $this->repoConfig = $this->getTestRepoConfig(); $this->io = $this->getMockIOInterface(); - $this->perforce = new Perforce($this->repoConfig, self::TEST_PORT, self::TEST_PATH, $this->processExecutor, true, $this->io); + $this->createNewPerforceWithWindowsFlag(true); } - public function tearDown() + protected function tearDown() { $this->perforce = null; $this->io = null; @@ -62,6 +62,11 @@ class PerforceTest extends \PHPUnit_Framework_TestCase return $this->getMock('Composer\IO\IOInterface'); } + protected function createNewPerforceWithWindowsFlag($flag) + { + $this->perforce = new Perforce($this->repoConfig, self::TEST_PORT, self::TEST_PATH, $this->processExecutor, $flag, $this->io); + } + public function testGetClientWithoutStream() { $client = $this->perforce->getClient(); @@ -131,8 +136,8 @@ class PerforceTest extends \PHPUnit_Framework_TestCase public function testQueryP4UserWithUserSetInP4VariablesWithWindowsOS() { + $this->createNewPerforceWithWindowsFlag(true); $this->perforce->setUser(null); - $this->perforce->setWindowsFlag(true); $expectedCommand = 'p4 set'; $callback = function($command, &$output) { @@ -149,8 +154,8 @@ class PerforceTest extends \PHPUnit_Framework_TestCase public function testQueryP4UserWithUserSetInP4VariablesNotWindowsOS() { + $this->createNewPerforceWithWindowsFlag(false); $this->perforce->setUser(null); - $this->perforce->setWindowsFlag(false); $expectedCommand = 'echo $P4USER'; $callback = function($command, &$output) { @@ -179,8 +184,8 @@ class PerforceTest extends \PHPUnit_Framework_TestCase public function testQueryP4UserStoresResponseToQueryForUserWithWindows() { + $this->createNewPerforceWithWindowsFlag(true); $this->perforce->setUser(null); - $this->perforce->setWindowsFlag(true); $expectedQuestion = 'Enter P4 User:'; $expectedCommand = 'p4 set P4USER=TEST_QUERY_USER'; $this->io->expects($this->at(0)) @@ -196,8 +201,8 @@ class PerforceTest extends \PHPUnit_Framework_TestCase public function testQueryP4UserStoresResponseToQueryForUserWithoutWindows() { + $this->createNewPerforceWithWindowsFlag(false); $this->perforce->setUser(null); - $this->perforce->setWindowsFlag(false); $expectedQuestion = 'Enter P4 User:'; $expectedCommand = 'export P4USER=TEST_QUERY_USER'; $this->io->expects($this->at(0)) @@ -226,7 +231,7 @@ class PerforceTest extends \PHPUnit_Framework_TestCase public function testQueryP4PasswordWithPasswordSetInP4VariablesWithWindowsOS() { - $this->perforce->setWindowsFlag(true); + $this->createNewPerforceWithWindowsFlag(true); $expectedCommand = 'p4 set'; $callback = function($command, &$output) { @@ -243,7 +248,7 @@ class PerforceTest extends \PHPUnit_Framework_TestCase public function testQueryP4PasswordWithPasswordSetInP4VariablesNotWindowsOS() { - $this->perforce->setWindowsFlag(false); + $this->createNewPerforceWithWindowsFlag(false); $expectedCommand = 'echo $P4PASSWD'; $callback = function($command, &$output) { From 8dc6a13a1c9322b1f98a567d235a269f94a30f76 Mon Sep 17 00:00:00 2001 From: Clark Stuth Date: Tue, 25 Mar 2014 10:48:38 -0500 Subject: [PATCH 16/16] Removing dead code segment. --- src/Composer/Util/Perforce.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index e812fbce3..894a151ef 100644 --- a/src/Composer/Util/Perforce.php +++ b/src/Composer/Util/Perforce.php @@ -51,13 +51,8 @@ class Perforce public static function create($repoConfig, $port, $path, ProcessExecutor $process, IOInterface $io) { - if (!isset($process)) { - $process = new ProcessExecutor; - } $isWindows = defined('PHP_WINDOWS_VERSION_BUILD'); - $perforce = new Perforce($repoConfig, $port, $path, $process, $isWindows, $io); - return $perforce; }