fixed perforce to reference labels instead of invalid tags
parent
3a3661a0b3
commit
dd1fd0e306
|
@ -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)) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue