Merge pull request #5 from clarkstuth/master

composer/composer pull request changes
main
Clark Stuth 10 years ago
commit bee3070014

@ -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)) {

@ -140,7 +140,6 @@ class PerforceDriver extends VcsDriver
{ {
$this->composerInfo = $this->perforce->getComposerInformation('//' . $this->depot . '/' . $identifier); $this->composerInfo = $this->perforce->getComposerInformation('//' . $this->depot . '/' . $identifier);
$this->composerInfoIdentifier = $identifier; $this->composerInfoIdentifier = $identifier;
$result = false;
return !empty($this->composerInfo); return !empty($this->composerInfo);
} }
@ -183,14 +182,4 @@ class PerforceDriver extends VcsDriver
return $this->branch; return $this->branch;
} }
public function setPerforce(Perforce $perforce)
{
$this->perforce = $perforce;
}
public function getPerforce()
{
return $this->perforce;
}
} }

@ -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);
} }
@ -370,16 +370,6 @@ class Perforce
return; return;
} }
public function getWindowsFlag()
{
return $this->windowsFlag;
}
public function setWindowsFlag($flag)
{
$this->windowsFlag = $flag;
}
public function windowsLogin($password) public function windowsLogin($password)
{ {
$command = $this->generateP4Command(' login -a'); $command = $this->generateP4Command(' login -a');

@ -32,7 +32,7 @@ class PerforceDownloaderTest extends \PHPUnit_Framework_TestCase
protected $repository; protected $repository;
protected $testPath; protected $testPath;
public function setUp() protected function setUp()
{ {
$this->testPath = sys_get_temp_dir() . '/composer-test'; $this->testPath = sys_get_temp_dir() . '/composer-test';
$this->repoConfig = $this->getRepoConfig(); $this->repoConfig = $this->getRepoConfig();
@ -44,7 +44,7 @@ class PerforceDownloaderTest extends \PHPUnit_Framework_TestCase
$this->downloader = new PerforceDownloader($this->io, $this->config, $this->processExecutor); $this->downloader = new PerforceDownloader($this->io, $this->config, $this->processExecutor);
} }
public function tearDown() protected function tearDown()
{ {
$this->downloader = null; $this->downloader = null;
$this->package = null; $this->package = null;
@ -112,13 +112,35 @@ 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@123';
$label = 123;
$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);
}
/**
* @depends testInitPerforceInstantiatesANewPerforceObject
* @depends testInitPerforceDoesNothingIfPerforceAlreadySet
*/
public function testDoDownloadWithNoTag()
{
$ref = 'SOURCE_REF'; $ref = 'SOURCE_REF';
$label = 'LABEL'; $label = null;
$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 +149,10 @@ 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);
} }
} }

@ -15,6 +15,7 @@ namespace Composer\Test\Repository\Vcs;
use Composer\Repository\Vcs\PerforceDriver; use Composer\Repository\Vcs\PerforceDriver;
use Composer\Util\Filesystem; use Composer\Util\Filesystem;
use Composer\Config; use Composer\Config;
use Composer\Util\Perforce;
/** /**
* @author Matt Whittom <Matt.Whittom@veteransunited.com> * @author Matt Whittom <Matt.Whittom@veteransunited.com>
@ -33,7 +34,7 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase
const TEST_DEPOT = 'TEST_DEPOT_CONFIG'; const TEST_DEPOT = 'TEST_DEPOT_CONFIG';
const TEST_BRANCH = 'TEST_BRANCH_CONFIG'; const TEST_BRANCH = 'TEST_BRANCH_CONFIG';
public function setUp() protected function setUp()
{ {
$this->testPath = sys_get_temp_dir() . '/composer-test'; $this->testPath = sys_get_temp_dir() . '/composer-test';
$this->config = $this->getTestConfig($this->testPath); $this->config = $this->getTestConfig($this->testPath);
@ -43,9 +44,10 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase
$this->remoteFileSystem = $this->getMockRemoteFilesystem(); $this->remoteFileSystem = $this->getMockRemoteFilesystem();
$this->perforce = $this->getMockPerforce(); $this->perforce = $this->getMockPerforce();
$this->driver = new PerforceDriver($this->repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem); $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 //cleanup directory under test path
$fs = new Filesystem; $fs = new Filesystem;
@ -60,6 +62,14 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase
$this->testPath = null; $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) protected function getTestConfig($testPath)
{ {
$config = new Config(); $config = new Config();
@ -100,7 +110,6 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase
public function testInitializeCapturesVariablesFromRepoConfig() public function testInitializeCapturesVariablesFromRepoConfig()
{ {
$driver = new PerforceDriver($this->repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem); $driver = new PerforceDriver($this->repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem);
$driver->setPerforce($this->perforce);
$driver->initialize(); $driver->initialize();
$this->assertEquals(self::TEST_URL, $driver->getUrl()); $this->assertEquals(self::TEST_URL, $driver->getUrl());
$this->assertEquals(self::TEST_DEPOT, $driver->getDepot()); $this->assertEquals(self::TEST_DEPOT, $driver->getDepot());
@ -109,7 +118,6 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase
public function testInitializeLogsInAndConnectsClient() 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(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(1))->method('checkStream')->with($this->equalTo(self::TEST_DEPOT));
$this->perforce->expects($this->at(2))->method('writeP4ClientSpec'); $this->perforce->expects($this->at(2))->method('writeP4ClientSpec');
@ -125,7 +133,6 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase
{ {
$identifier = 'TEST_IDENTIFIER'; $identifier = 'TEST_IDENTIFIER';
$formatted_depot_path = '//' . self::TEST_DEPOT . '/' . $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->perforce->expects($this->any())->method('getComposerInformation')->with($this->equalTo($formatted_depot_path))->will($this->returnValue(array()));
$this->driver->initialize(); $this->driver->initialize();
$result = $this->driver->hasComposerFile($identifier); $result = $this->driver->hasComposerFile($identifier);
@ -140,7 +147,6 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase
{ {
$identifier = 'TEST_IDENTIFIER'; $identifier = 'TEST_IDENTIFIER';
$formatted_depot_path = '//' . self::TEST_DEPOT . '/' . $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->perforce->expects($this->any())->method('getComposerInformation')->with($this->equalTo($formatted_depot_path))->will($this->returnValue(array('')));
$this->driver->initialize(); $this->driver->initialize();
$result = $this->driver->hasComposerFile($identifier); $result = $this->driver->hasComposerFile($identifier);
@ -163,9 +169,7 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase
public function testCleanup() public function testCleanup()
{ {
$this->perforce->expects($this->once())->method('cleanupClientSpec'); $this->perforce->expects($this->once())->method('cleanupClientSpec');
$this->driver->setPerforce($this->perforce);
$this->driver->cleanup(); $this->driver->cleanup();
$this->assertNull($this->driver->getPerforce());
} }
} }

@ -31,15 +31,15 @@ class PerforceTest extends \PHPUnit_Framework_TestCase
const TEST_PORT = 'port'; const TEST_PORT = 'port';
const TEST_PATH = 'path'; const TEST_PATH = 'path';
public function setUp() protected function setUp()
{ {
$this->processExecutor = $this->getMock('Composer\Util\ProcessExecutor'); $this->processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
$this->repoConfig = $this->getTestRepoConfig(); $this->repoConfig = $this->getTestRepoConfig();
$this->io = $this->getMockIOInterface(); $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->perforce = null;
$this->io = null; $this->io = null;
@ -62,6 +62,11 @@ class PerforceTest extends \PHPUnit_Framework_TestCase
return $this->getMock('Composer\IO\IOInterface'); 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() public function testGetClientWithoutStream()
{ {
$client = $this->perforce->getClient(); $client = $this->perforce->getClient();
@ -131,8 +136,8 @@ class PerforceTest extends \PHPUnit_Framework_TestCase
public function testQueryP4UserWithUserSetInP4VariablesWithWindowsOS() public function testQueryP4UserWithUserSetInP4VariablesWithWindowsOS()
{ {
$this->createNewPerforceWithWindowsFlag(true);
$this->perforce->setUser(null); $this->perforce->setUser(null);
$this->perforce->setWindowsFlag(true);
$expectedCommand = 'p4 set'; $expectedCommand = 'p4 set';
$callback = function($command, &$output) $callback = function($command, &$output)
{ {
@ -149,8 +154,8 @@ class PerforceTest extends \PHPUnit_Framework_TestCase
public function testQueryP4UserWithUserSetInP4VariablesNotWindowsOS() public function testQueryP4UserWithUserSetInP4VariablesNotWindowsOS()
{ {
$this->createNewPerforceWithWindowsFlag(false);
$this->perforce->setUser(null); $this->perforce->setUser(null);
$this->perforce->setWindowsFlag(false);
$expectedCommand = 'echo $P4USER'; $expectedCommand = 'echo $P4USER';
$callback = function($command, &$output) $callback = function($command, &$output)
{ {
@ -179,8 +184,8 @@ class PerforceTest extends \PHPUnit_Framework_TestCase
public function testQueryP4UserStoresResponseToQueryForUserWithWindows() public function testQueryP4UserStoresResponseToQueryForUserWithWindows()
{ {
$this->createNewPerforceWithWindowsFlag(true);
$this->perforce->setUser(null); $this->perforce->setUser(null);
$this->perforce->setWindowsFlag(true);
$expectedQuestion = 'Enter P4 User:'; $expectedQuestion = 'Enter P4 User:';
$expectedCommand = 'p4 set P4USER=TEST_QUERY_USER'; $expectedCommand = 'p4 set P4USER=TEST_QUERY_USER';
$this->io->expects($this->at(0)) $this->io->expects($this->at(0))
@ -196,8 +201,8 @@ class PerforceTest extends \PHPUnit_Framework_TestCase
public function testQueryP4UserStoresResponseToQueryForUserWithoutWindows() public function testQueryP4UserStoresResponseToQueryForUserWithoutWindows()
{ {
$this->createNewPerforceWithWindowsFlag(false);
$this->perforce->setUser(null); $this->perforce->setUser(null);
$this->perforce->setWindowsFlag(false);
$expectedQuestion = 'Enter P4 User:'; $expectedQuestion = 'Enter P4 User:';
$expectedCommand = 'export P4USER=TEST_QUERY_USER'; $expectedCommand = 'export P4USER=TEST_QUERY_USER';
$this->io->expects($this->at(0)) $this->io->expects($this->at(0))
@ -226,7 +231,7 @@ class PerforceTest extends \PHPUnit_Framework_TestCase
public function testQueryP4PasswordWithPasswordSetInP4VariablesWithWindowsOS() public function testQueryP4PasswordWithPasswordSetInP4VariablesWithWindowsOS()
{ {
$this->perforce->setWindowsFlag(true); $this->createNewPerforceWithWindowsFlag(true);
$expectedCommand = 'p4 set'; $expectedCommand = 'p4 set';
$callback = function($command, &$output) $callback = function($command, &$output)
{ {
@ -243,7 +248,7 @@ class PerforceTest extends \PHPUnit_Framework_TestCase
public function testQueryP4PasswordWithPasswordSetInP4VariablesNotWindowsOS() public function testQueryP4PasswordWithPasswordSetInP4VariablesNotWindowsOS()
{ {
$this->perforce->setWindowsFlag(false); $this->createNewPerforceWithWindowsFlag(false);
$expectedCommand = 'echo $P4PASSWD'; $expectedCommand = 'echo $P4PASSWD';
$callback = function($command, &$output) $callback = function($command, &$output)
{ {

Loading…
Cancel
Save