From dd1fd0e306dbad073fa8b32c0b23eea52ada8dea Mon Sep 17 00:00:00 2001 From: Clark Stuth Date: Mon, 24 Mar 2014 15:19:35 -0500 Subject: [PATCH] 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); + } + }