1
0
Fork 0

fixed perforce to reference labels instead of invalid tags

pull/2834/head
Clark Stuth 2014-03-24 15:19:35 -05:00
parent 3a3661a0b3
commit dd1fd0e306
3 changed files with 43 additions and 10 deletions

View File

@ -29,7 +29,7 @@ class PerforceDownloader extends VcsDownloader
public function doDownload(PackageInterface $package, $path) public function doDownload(PackageInterface $package, $path)
{ {
$ref = $package->getSourceReference(); $ref = $package->getSourceReference();
$label = $package->getPrettyVersion(); $label = $this->getLabelFromSourceReference($ref);
$this->io->write(' Cloning ' . $ref); $this->io->write(' Cloning ' . $ref);
$this->initPerforce($package, $path); $this->initPerforce($package, $path);
@ -41,6 +41,16 @@ class PerforceDownloader extends VcsDownloader
$this->perforce->cleanupClientSpec(); $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) public function initPerforce($package, $path)
{ {
if (!empty($this->perforce)) { if (!empty($this->perforce)) {

View File

@ -309,15 +309,15 @@ class Perforce
$this->executeCommand($p4CreateClientCommand); $this->executeCommand($p4CreateClientCommand);
} }
public function syncCodeBase($label) public function syncCodeBase($sourceReference)
{ {
$prevDir = getcwd(); $prevDir = getcwd();
chdir($this->path); chdir($this->path);
$p4SyncCommand = $this->generateP4Command('sync -f '); $p4SyncCommand = $this->generateP4Command('sync -f ');
$p4SyncCommand = $p4SyncCommand . '@' . $label; if (null != $sourceReference) {
$p4SyncCommand = $p4SyncCommand . '@' . $sourceReference;
}
$this->executeCommand($p4SyncCommand); $this->executeCommand($p4SyncCommand);
chdir($prevDir); chdir($prevDir);
} }

View File

@ -112,13 +112,12 @@ class PerforceDownloaderTest extends \PHPUnit_Framework_TestCase
* @depends testInitPerforceInstantiatesANewPerforceObject * @depends testInitPerforceInstantiatesANewPerforceObject
* @depends testInitPerforceDoesNothingIfPerforceAlreadySet * @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. //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'; $ref = 'SOURCE_REF@123';
$label = 'LABEL'; $label = 123;
$this->package->expects($this->once())->method('getSourceReference')->will($this->returnValue($ref)); $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)); $this->io->expects($this->once())->method('write')->with($this->stringContains('Cloning '.$ref));
$perforceMethods = array('setStream', 'p4Login', 'writeP4ClientSpec', 'connectClient', 'syncCodeBase', 'cleanupClientSpec'); $perforceMethods = array('setStream', 'p4Login', 'writeP4ClientSpec', 'connectClient', 'syncCodeBase', 'cleanupClientSpec');
$perforce = $this->getMockBuilder('Composer\Util\Perforce', $perforceMethods)->disableOriginalConstructor()->getMock(); $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(2))->method('p4Login')->with($this->identicalTo($this->io));
$perforce->expects($this->at(3))->method('writeP4ClientSpec'); $perforce->expects($this->at(3))->method('writeP4ClientSpec');
$perforce->expects($this->at(4))->method('connectClient'); $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'); $perforce->expects($this->at(6))->method('cleanupClientSpec');
$this->downloader->setPerforce($perforce); $this->downloader->setPerforce($perforce);
$this->downloader->doDownload($this->package, $this->testPath); $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);
}
} }