1
0
Fork 0

CS fixes and renaming a few methods, refs #2184

pull/2320/head
Jordi Boggiano 2013-10-11 20:21:34 -03:00
parent 11a0d16ccc
commit 0fbb4cbd16
6 changed files with 205 additions and 207 deletions

View File

@ -44,15 +44,16 @@ class PerforceDownloader extends VcsDownloader
private function initPerforce($package, $path, $ref) private function initPerforce($package, $path, $ref)
{ {
if ($this->perforceInjected) { if ($this->perforce) {
return; return;
} }
$repository = $package->getRepository(); $repository = $package->getRepository();
$repoConfig = null; $repoConfig = null;
if ($repository instanceof VcsRepository) { if ($repository instanceof VcsRepository) {
$repoConfig = $this->getRepoConfig($repository); $repoConfig = $this->getRepoConfig($repository);
} }
$this->perforce = Perforce::createPerforce($repoConfig, $package->getSourceUrl(), $path); $this->perforce = Perforce::create($repoConfig, $package->getSourceUrl(), $path);
} }
private function getRepoConfig(VcsRepository $repository) private function getRepoConfig(VcsRepository $repository)
@ -88,9 +89,8 @@ class PerforceDownloader extends VcsDownloader
return $commitLogs; return $commitLogs;
} }
public function injectPerforce($perforce) public function setPerforce($perforce)
{ {
$this->perforce = $perforce; $this->perforce = $perforce;
$this->perforceInjected = true;
} }
} }

View File

@ -55,7 +55,7 @@ class PerforceDriver extends VcsDriver
} }
$repoDir = $this->config->get('cache-vcs-dir') . '/' . $this->depot; $repoDir = $this->config->get('cache-vcs-dir') . '/' . $this->depot;
$this->perforce = Perforce::createPerforce($repoConfig, $this->getUrl(), $repoDir, $this->process); $this->perforce = Perforce::create($repoConfig, $this->getUrl(), $repoDir, $this->process);
} }
/** /**
@ -182,7 +182,7 @@ class PerforceDriver extends VcsDriver
return $this->branch; return $this->branch;
} }
public function injectPerforce(Perforce $perforce) public function setPerforce(Perforce $perforce)
{ {
$this->perforce = $perforce; $this->perforce = $perforce;
} }

View File

@ -34,18 +34,6 @@ class Perforce
protected $uniquePerforceClientName; protected $uniquePerforceClientName;
protected $windowsFlag; protected $windowsFlag;
public static function createPerforce($repoConfig, $port, $path, ProcessExecutor $process = null)
{
if (!isset($process)) {
$process = new ProcessExecutor;
}
$isWindows = defined('PHP_WINDOWS_VERSION_BUILD');
$perforce = new Perforce($repoConfig, $port, $path, $process, $isWindows);
return $perforce;
}
public function __construct($repoConfig, $port, $path, ProcessExecutor $process, $isWindows) public function __construct($repoConfig, $port, $path, ProcessExecutor $process, $isWindows)
{ {
$this->windowsFlag = $isWindows; $this->windowsFlag = $isWindows;
@ -57,6 +45,18 @@ class Perforce
$this->initialize($repoConfig); $this->initialize($repoConfig);
} }
public static function create($repoConfig, $port, $path, ProcessExecutor $process = null)
{
if (!isset($process)) {
$process = new ProcessExecutor;
}
$isWindows = defined('PHP_WINDOWS_VERSION_BUILD');
$perforce = new Perforce($repoConfig, $port, $path, $process, $isWindows);
return $perforce;
}
public function initialize($repoConfig) public function initialize($repoConfig)
{ {
$this->uniquePerforceClientName = $this->generateUniquePerforceClientName(); $this->uniquePerforceClientName = $this->generateUniquePerforceClientName();

View File

@ -21,7 +21,6 @@ use Composer\Repository\VcsRepository;
*/ */
class PerforceDownloaderTest extends \PHPUnit_Framework_TestCase class PerforceDownloaderTest extends \PHPUnit_Framework_TestCase
{ {
private $io; private $io;
private $config; private $config;
private $testPath; private $testPath;
@ -93,7 +92,7 @@ class PerforceDownloaderTest extends \PHPUnit_Framework_TestCase
$perforce->expects($this->at(4)) $perforce->expects($this->at(4))
->method('syncCodeBase') ->method('syncCodeBase')
->with($this->equalTo($label)); ->with($this->equalTo($label));
$downloader->injectPerforce($perforce); $downloader->setPerforce($perforce);
$package = $this->getMock('Composer\Package\PackageInterface'); $package = $this->getMock('Composer\Package\PackageInterface');
$package->expects($this->at(0)) $package->expects($this->at(0))
->method('getSourceReference') ->method('getSourceReference')

View File

@ -70,7 +70,7 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase
'TEST' 'TEST'
); );
$perforce = $this->getMock('Composer\Util\Perforce', null, $arguments); $perforce = $this->getMock('Composer\Util\Perforce', null, $arguments);
$driver->injectPerforce($perforce); $driver->setPerforce($perforce);
$driver->initialize(); $driver->initialize();
$this->assertEquals('TEST_PERFORCE_URL', $driver->getUrl()); $this->assertEquals('TEST_PERFORCE_URL', $driver->getUrl());
$this->assertEquals('TEST_DEPOT_CONFIG', $driver->getDepot()); $this->assertEquals('TEST_DEPOT_CONFIG', $driver->getDepot());
@ -98,7 +98,7 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase
$perforce->expects($this->at(3)) $perforce->expects($this->at(3))
->method('connectClient'); ->method('connectClient');
$driver->injectPerforce($perforce); $driver->setPerforce($perforce);
$driver->initialize(); $driver->initialize();
} }
@ -125,7 +125,7 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase
->method('getComposerInformation') ->method('getComposerInformation')
->with($this->equalTo('//TEST_DEPOT_CONFIG/TEST_IDENTIFIER')) ->with($this->equalTo('//TEST_DEPOT_CONFIG/TEST_IDENTIFIER'))
->will($this->returnValue('Some json stuff')); ->will($this->returnValue('Some json stuff'));
$driver->injectPerforce($perforce); $driver->setPerforce($perforce);
$driver->initialize(); $driver->initialize();
$identifier = 'TEST_IDENTIFIER'; $identifier = 'TEST_IDENTIFIER';
$result = $driver->hasComposerFile($identifier); $result = $driver->hasComposerFile($identifier);

View File

@ -20,7 +20,6 @@ use Composer\Util\ProcessExecutor;
*/ */
class PerforceTest extends \PHPUnit_Framework_TestCase class PerforceTest extends \PHPUnit_Framework_TestCase
{ {
protected $perforce; protected $perforce;
protected $processExecutor; protected $processExecutor;