Updated to clean up code and rename variables to camelcase
parent
f7d9f3d8b4
commit
8207518e04
|
@ -26,8 +26,8 @@ class PerforceDriver extends VcsDriver
|
||||||
protected $depot;
|
protected $depot;
|
||||||
protected $branch;
|
protected $branch;
|
||||||
protected $perforce;
|
protected $perforce;
|
||||||
protected $composer_info;
|
protected $composerInfo;
|
||||||
protected $composer_info_identifier;
|
protected $composerInfoIdentifier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
|
@ -65,9 +65,9 @@ class PerforceDriver extends VcsDriver
|
||||||
*/
|
*/
|
||||||
public function getComposerInformation($identifier)
|
public function getComposerInformation($identifier)
|
||||||
{
|
{
|
||||||
if (isset($this->composer_info_identifier)) {
|
if (isset($this->composerInfoIdentifier)) {
|
||||||
if (strcmp($identifier, $this->composer_info_identifier) === 0) {
|
if (strcmp($identifier, $this->composerInfoIdentifier) === 0) {
|
||||||
return $this->composer_info;
|
return $this->composerInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$composer_info = $this->perforce->getComposerInformation($identifier);
|
$composer_info = $this->perforce->getComposerInformation($identifier);
|
||||||
|
@ -139,11 +139,11 @@ class PerforceDriver extends VcsDriver
|
||||||
*/
|
*/
|
||||||
public function hasComposerFile($identifier)
|
public function hasComposerFile($identifier)
|
||||||
{
|
{
|
||||||
$this->composer_info = $this->perforce->getComposerInformation("//$this->depot/$identifier");
|
$this->composerInfo = $this->perforce->getComposerInformation("//$this->depot/$identifier");
|
||||||
$this->composer_info_identifier = $identifier;
|
$this->composerInfoIdentifier = $identifier;
|
||||||
$result = false;
|
$result = false;
|
||||||
if (isset($this->composer_info)) {
|
if (isset($this->composerInfo)) {
|
||||||
$result = count($this->composer_info) > 0;
|
$result = count($this->composerInfo) > 0;
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ class Perforce
|
||||||
protected $p4DepotType;
|
protected $p4DepotType;
|
||||||
protected $p4Branch;
|
protected $p4Branch;
|
||||||
protected $process;
|
protected $process;
|
||||||
protected $unique_perforce_client_name;
|
protected $uniquePerforceClientName;
|
||||||
protected $windowsFlag;
|
protected $windowsFlag;
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,12 +59,12 @@ class Perforce
|
||||||
|
|
||||||
public function initialize($repoConfig)
|
public function initialize($repoConfig)
|
||||||
{
|
{
|
||||||
$this->unique_perforce_client_name = $this->generateUniquePerforceClientName();
|
$this->uniquePerforceClientName = $this->generateUniquePerforceClientName();
|
||||||
if (!isset ($repoConfig)) {
|
if (null == $repoConfig) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (isset($repoConfig['unique_perforce_client_name'])) {
|
if (isset($repoConfig['unique_perforce_client_name'])) {
|
||||||
$this->unique_perforce_client_name = $repoConfig['unique_perforce_client_name'];
|
$this->uniquePerforceClientName = $repoConfig['unique_perforce_client_name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($repoConfig['depot'])) {
|
if (isset($repoConfig['depot'])) {
|
||||||
|
@ -119,8 +119,8 @@ class Perforce
|
||||||
public function getClient()
|
public function getClient()
|
||||||
{
|
{
|
||||||
if (!isset($this->p4Client)) {
|
if (!isset($this->p4Client)) {
|
||||||
$clean_stream_name = str_replace("@", "", str_replace("/", "_", str_replace("//", "", $this->getStream())));
|
$cleanStreamName = str_replace("@", "", str_replace("/", "_", str_replace("//", "", $this->getStream())));
|
||||||
$this->p4Client = "composer_perforce_" . $this->unique_perforce_client_name . "_" . $clean_stream_name;
|
$this->p4Client = "composer_perforce_" . $this->uniquePerforceClientName . "_" . $cleanStreamName;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->p4Client;
|
return $this->p4Client;
|
||||||
|
@ -327,7 +327,7 @@ class Perforce
|
||||||
$spec = fopen($clientSpec, 'w');
|
$spec = fopen($clientSpec, 'w');
|
||||||
try {
|
try {
|
||||||
$this->writeClientSpecToFile($spec);
|
$this->writeClientSpecToFile($spec);
|
||||||
} catch (Exception $e) {
|
} catch (\Exception $e) {
|
||||||
fclose($spec);
|
fclose($spec);
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
@ -369,9 +369,9 @@ class Perforce
|
||||||
fclose($pipes[1]);
|
fclose($pipes[1]);
|
||||||
fclose($pipes[2]);
|
fclose($pipes[2]);
|
||||||
|
|
||||||
$return_code = proc_close($process);
|
$returnCode = proc_close($process);
|
||||||
|
|
||||||
return $return_code;
|
return $returnCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -389,34 +389,27 @@ class Perforce
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function checkServerExists($url, ProcessExecutor $process_executor)
|
public static function checkServerExists($url, ProcessExecutor $processExecutor)
|
||||||
{
|
{
|
||||||
$process = $process_executor ? : new ProcessExecutor;
|
|
||||||
$result = "";
|
$result = "";
|
||||||
$process->execute("p4 -p $url info -s", $result);
|
$processExecutor->execute("p4 -p $url info -s", $result);
|
||||||
$index = strpos($result, "error");
|
return false === strpos($result, "error");
|
||||||
if ($index === false) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getComposerInformation($identifier)
|
public function getComposerInformation($identifier)
|
||||||
{
|
{
|
||||||
$index = strpos($identifier, "@");
|
$index = strpos($identifier, "@");
|
||||||
if ($index === false) {
|
if ($index === false) {
|
||||||
$composer_json = "$identifier/composer.json";
|
$composerJson = "$identifier/composer.json";
|
||||||
|
|
||||||
return $this->getComposerInformationFromPath($composer_json);
|
return $this->getComposerInformationFromPath($composerJson);
|
||||||
} else {
|
}
|
||||||
return $this->getComposerInformationFromLabel($identifier, $index);
|
return $this->getComposerInformationFromLabel($identifier, $index);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public function getComposerInformationFromPath($composer_json)
|
public function getComposerInformationFromPath($composerJson)
|
||||||
{
|
{
|
||||||
$command = $this->generateP4Command(" print $composer_json");
|
$command = $this->generateP4Command(" print $composerJson");
|
||||||
$result = $this->executeCommand($command);
|
$result = $this->executeCommand($command);
|
||||||
$index = strpos($result, "{");
|
$index = strpos($result, "{");
|
||||||
if ($index === false) {
|
if ($index === false) {
|
||||||
|
@ -434,8 +427,8 @@ class Perforce
|
||||||
|
|
||||||
public function getComposerInformationFromLabel($identifier, $index)
|
public function getComposerInformationFromLabel($identifier, $index)
|
||||||
{
|
{
|
||||||
$composer_json_path = substr($identifier, 0, $index) . "/composer.json" . substr($identifier, $index);
|
$composerJsonPath = substr($identifier, 0, $index) . "/composer.json" . substr($identifier, $index);
|
||||||
$command = $this->generateP4Command(" files $composer_json_path", false);
|
$command = $this->generateP4Command(" files $composerJsonPath", false);
|
||||||
$result = $this->executeCommand($command);
|
$result = $this->executeCommand($command);
|
||||||
$index2 = strpos($result, "no such file(s).");
|
$index2 = strpos($result, "no such file(s).");
|
||||||
if ($index2 === false) {
|
if ($index2 === false) {
|
||||||
|
@ -444,9 +437,9 @@ class Perforce
|
||||||
$phrase = trim(substr($result, $index3));
|
$phrase = trim(substr($result, $index3));
|
||||||
$fields = explode(" ", $phrase);
|
$fields = explode(" ", $phrase);
|
||||||
$id = $fields[1];
|
$id = $fields[1];
|
||||||
$composer_json = substr($identifier, 0, $index) . "/composer.json@" . $id;
|
$composerJson = substr($identifier, 0, $index) . "/composer.json@" . $id;
|
||||||
|
|
||||||
return $this->getComposerInformationFromPath($composer_json);
|
return $this->getComposerInformationFromPath($composerJson);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -455,9 +448,9 @@ class Perforce
|
||||||
|
|
||||||
public function getBranches()
|
public function getBranches()
|
||||||
{
|
{
|
||||||
$possible_branches = array();
|
$possibleBranches = array();
|
||||||
if (!$this->isStream()) {
|
if (!$this->isStream()) {
|
||||||
$possible_branches[$this->p4Branch] = $this->getStream();
|
$possibleBranches[$this->p4Branch] = $this->getStream();
|
||||||
} else {
|
} else {
|
||||||
$command = $this->generateP4Command("streams //$this->p4Depot/...");
|
$command = $this->generateP4Command("streams //$this->p4Depot/...");
|
||||||
$result = $this->executeCommand($command);
|
$result = $this->executeCommand($command);
|
||||||
|
@ -466,12 +459,12 @@ class Perforce
|
||||||
$resBits = explode(" ", $line);
|
$resBits = explode(" ", $line);
|
||||||
if (count($resBits) > 4) {
|
if (count($resBits) > 4) {
|
||||||
$branch = preg_replace("/[^A-Za-z0-9 ]/", '', $resBits[4]);
|
$branch = preg_replace("/[^A-Za-z0-9 ]/", '', $resBits[4]);
|
||||||
$possible_branches[$branch] = $resBits[1];
|
$possibleBranches[$branch] = $resBits[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$branches = array();
|
$branches = array();
|
||||||
$branches['master'] = $possible_branches[$this->p4Branch];
|
$branches['master'] = $possibleBranches[$this->p4Branch];
|
||||||
|
|
||||||
return $branches;
|
return $branches;
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,7 +146,6 @@ class ArchivableFilesFinderTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testHgExcludes()
|
public function testHgExcludes()
|
||||||
{
|
{
|
||||||
$this->markTestSkipped('Mercurial test does not work.');
|
|
||||||
// Ensure that Mercurial is available for testing.
|
// Ensure that Mercurial is available for testing.
|
||||||
if (!$this->isProcessAvailable('hg')) {
|
if (!$this->isProcessAvailable('hg')) {
|
||||||
return $this->markTestSkipped('Mercurial is not available.');
|
return $this->markTestSkipped('Mercurial is not available.');
|
||||||
|
|
|
@ -54,12 +54,12 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testInitializeCapturesVariablesFromRepoConfig()
|
public function testInitializeCapturesVariablesFromRepoConfig()
|
||||||
{
|
{
|
||||||
$this->setUp();
|
$this->setUp();
|
||||||
$repo_config = array(
|
$repoConfig = array(
|
||||||
'url' => 'TEST_PERFORCE_URL',
|
'url' => 'TEST_PERFORCE_URL',
|
||||||
'depot' => 'TEST_DEPOT_CONFIG',
|
'depot' => 'TEST_DEPOT_CONFIG',
|
||||||
'branch' => 'TEST_BRANCH_CONFIG'
|
'branch' => 'TEST_BRANCH_CONFIG'
|
||||||
);
|
);
|
||||||
$driver = new PerforceDriver($repo_config, $this->io, $this->config, $this->process, $this->remoteFileSystem);
|
$driver = new PerforceDriver($repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem);
|
||||||
$process = $this->getMock('Composer\Util\ProcessExecutor');
|
$process = $this->getMock('Composer\Util\ProcessExecutor');
|
||||||
$arguments = array(
|
$arguments = array(
|
||||||
array('depot' => 'TEST_DEPOT', 'branch' => 'TEST_BRANCH'),
|
array('depot' => 'TEST_DEPOT', 'branch' => 'TEST_BRANCH'),
|
||||||
|
@ -80,12 +80,12 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testInitializeLogsInAndConnectsClient()
|
public function testInitializeLogsInAndConnectsClient()
|
||||||
{
|
{
|
||||||
$this->setUp();
|
$this->setUp();
|
||||||
$repo_config = array(
|
$repoConfig = array(
|
||||||
'url' => 'TEST_PERFORCE_URL',
|
'url' => 'TEST_PERFORCE_URL',
|
||||||
'depot' => 'TEST_DEPOT_CONFIG',
|
'depot' => 'TEST_DEPOT_CONFIG',
|
||||||
'branch' => 'TEST_BRANCH_CONFIG'
|
'branch' => 'TEST_BRANCH_CONFIG'
|
||||||
);
|
);
|
||||||
$driver = new PerforceDriver($repo_config, $this->io, $this->config, $this->process, $this->remoteFileSystem);
|
$driver = new PerforceDriver($repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem);
|
||||||
$perforce = $this->getMockBuilder('Composer\Util\Perforce')->disableOriginalConstructor()->getMock();
|
$perforce = $this->getMockBuilder('Composer\Util\Perforce')->disableOriginalConstructor()->getMock();
|
||||||
$perforce->expects($this->at(0))
|
$perforce->expects($this->at(0))
|
||||||
->method('p4Login')
|
->method('p4Login')
|
||||||
|
@ -105,12 +105,12 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase
|
||||||
public function testHasComposerFile()
|
public function testHasComposerFile()
|
||||||
{
|
{
|
||||||
$this->setUp();
|
$this->setUp();
|
||||||
$repo_config = array(
|
$repoConfig = array(
|
||||||
'url' => 'TEST_PERFORCE_URL',
|
'url' => 'TEST_PERFORCE_URL',
|
||||||
'depot' => 'TEST_DEPOT_CONFIG',
|
'depot' => 'TEST_DEPOT_CONFIG',
|
||||||
'branch' => 'TEST_BRANCH_CONFIG'
|
'branch' => 'TEST_BRANCH_CONFIG'
|
||||||
);
|
);
|
||||||
$driver = new PerforceDriver($repo_config, $this->io, $this->config, $this->process, $this->remoteFileSystem);
|
$driver = new PerforceDriver($repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem);
|
||||||
$process = $this->getMock('Composer\Util\ProcessExecutor');
|
$process = $this->getMock('Composer\Util\ProcessExecutor');
|
||||||
$arguments = array(
|
$arguments = array(
|
||||||
array('depot' => 'TEST_DEPOT', 'branch' => 'TEST_BRANCH'),
|
array('depot' => 'TEST_DEPOT', 'branch' => 'TEST_BRANCH'),
|
||||||
|
|
Loading…
Reference in New Issue