From a12c4e2a1722730c199b32e90b3be5240f2f4698 Mon Sep 17 00:00:00 2001 From: Clark Stuth Date: Tue, 25 Mar 2014 08:30:44 -0500 Subject: [PATCH] Removed getWindowsFlag and setWindowsFlag methods from Perforce object. --- .../Repository/Vcs/PerforceDriver.php | 11 --------- src/Composer/Util/Perforce.php | 10 -------- .../Downloader/PerforceDownloaderTest.php | 4 ++-- .../Repository/Vcs/PerforceDriverTest.php | 20 +++++++++------- tests/Composer/Test/Util/PerforceTest.php | 23 +++++++++++-------- 5 files changed, 28 insertions(+), 40 deletions(-) diff --git a/src/Composer/Repository/Vcs/PerforceDriver.php b/src/Composer/Repository/Vcs/PerforceDriver.php index 9599dd964..e928e5835 100644 --- a/src/Composer/Repository/Vcs/PerforceDriver.php +++ b/src/Composer/Repository/Vcs/PerforceDriver.php @@ -140,7 +140,6 @@ class PerforceDriver extends VcsDriver { $this->composerInfo = $this->perforce->getComposerInformation('//' . $this->depot . '/' . $identifier); $this->composerInfoIdentifier = $identifier; - $result = false; return !empty($this->composerInfo); } @@ -183,14 +182,4 @@ class PerforceDriver extends VcsDriver return $this->branch; } - public function setPerforce(Perforce $perforce) - { - $this->perforce = $perforce; - } - - public function getPerforce() - { - return $this->perforce; - } - } diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index 7801f966b..e812fbce3 100644 --- a/src/Composer/Util/Perforce.php +++ b/src/Composer/Util/Perforce.php @@ -370,16 +370,6 @@ class Perforce return; } - public function getWindowsFlag() - { - return $this->windowsFlag; - } - - public function setWindowsFlag($flag) - { - $this->windowsFlag = $flag; - } - public function windowsLogin($password) { $command = $this->generateP4Command(' login -a'); diff --git a/tests/Composer/Test/Downloader/PerforceDownloaderTest.php b/tests/Composer/Test/Downloader/PerforceDownloaderTest.php index da93db767..7562f7fca 100644 --- a/tests/Composer/Test/Downloader/PerforceDownloaderTest.php +++ b/tests/Composer/Test/Downloader/PerforceDownloaderTest.php @@ -32,7 +32,7 @@ class PerforceDownloaderTest extends \PHPUnit_Framework_TestCase protected $repository; protected $testPath; - public function setUp() + protected function setUp() { $this->testPath = sys_get_temp_dir() . '/composer-test'; $this->repoConfig = $this->getRepoConfig(); @@ -44,7 +44,7 @@ class PerforceDownloaderTest extends \PHPUnit_Framework_TestCase $this->downloader = new PerforceDownloader($this->io, $this->config, $this->processExecutor); } - public function tearDown() + protected function tearDown() { $this->downloader = null; $this->package = null; diff --git a/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php b/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php index 9afc57d30..dcb50244a 100644 --- a/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php @@ -15,6 +15,7 @@ namespace Composer\Test\Repository\Vcs; use Composer\Repository\Vcs\PerforceDriver; use Composer\Util\Filesystem; use Composer\Config; +use Composer\Util\Perforce; /** * @author Matt Whittom @@ -33,7 +34,7 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase const TEST_DEPOT = 'TEST_DEPOT_CONFIG'; const TEST_BRANCH = 'TEST_BRANCH_CONFIG'; - public function setUp() + protected function setUp() { $this->testPath = sys_get_temp_dir() . '/composer-test'; $this->config = $this->getTestConfig($this->testPath); @@ -43,9 +44,10 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase $this->remoteFileSystem = $this->getMockRemoteFilesystem(); $this->perforce = $this->getMockPerforce(); $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 $fs = new Filesystem; @@ -60,6 +62,14 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase $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) { $config = new Config(); @@ -100,7 +110,6 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase public function testInitializeCapturesVariablesFromRepoConfig() { $driver = new PerforceDriver($this->repoConfig, $this->io, $this->config, $this->process, $this->remoteFileSystem); - $driver->setPerforce($this->perforce); $driver->initialize(); $this->assertEquals(self::TEST_URL, $driver->getUrl()); $this->assertEquals(self::TEST_DEPOT, $driver->getDepot()); @@ -109,7 +118,6 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase 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(1))->method('checkStream')->with($this->equalTo(self::TEST_DEPOT)); $this->perforce->expects($this->at(2))->method('writeP4ClientSpec'); @@ -125,7 +133,6 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase { $identifier = 'TEST_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->driver->initialize(); $result = $this->driver->hasComposerFile($identifier); @@ -140,7 +147,6 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase { $identifier = 'TEST_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->driver->initialize(); $result = $this->driver->hasComposerFile($identifier); @@ -163,9 +169,7 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase public function testCleanup() { $this->perforce->expects($this->once())->method('cleanupClientSpec'); - $this->driver->setPerforce($this->perforce); $this->driver->cleanup(); - $this->assertNull($this->driver->getPerforce()); } } diff --git a/tests/Composer/Test/Util/PerforceTest.php b/tests/Composer/Test/Util/PerforceTest.php index 1b8063258..a5f3e60fa 100644 --- a/tests/Composer/Test/Util/PerforceTest.php +++ b/tests/Composer/Test/Util/PerforceTest.php @@ -31,15 +31,15 @@ class PerforceTest extends \PHPUnit_Framework_TestCase const TEST_PORT = 'port'; const TEST_PATH = 'path'; - public function setUp() + protected function setUp() { $this->processExecutor = $this->getMock('Composer\Util\ProcessExecutor'); $this->repoConfig = $this->getTestRepoConfig(); $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->io = null; @@ -62,6 +62,11 @@ class PerforceTest extends \PHPUnit_Framework_TestCase 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() { $client = $this->perforce->getClient(); @@ -131,8 +136,8 @@ class PerforceTest extends \PHPUnit_Framework_TestCase public function testQueryP4UserWithUserSetInP4VariablesWithWindowsOS() { + $this->createNewPerforceWithWindowsFlag(true); $this->perforce->setUser(null); - $this->perforce->setWindowsFlag(true); $expectedCommand = 'p4 set'; $callback = function($command, &$output) { @@ -149,8 +154,8 @@ class PerforceTest extends \PHPUnit_Framework_TestCase public function testQueryP4UserWithUserSetInP4VariablesNotWindowsOS() { + $this->createNewPerforceWithWindowsFlag(false); $this->perforce->setUser(null); - $this->perforce->setWindowsFlag(false); $expectedCommand = 'echo $P4USER'; $callback = function($command, &$output) { @@ -179,8 +184,8 @@ class PerforceTest extends \PHPUnit_Framework_TestCase public function testQueryP4UserStoresResponseToQueryForUserWithWindows() { + $this->createNewPerforceWithWindowsFlag(true); $this->perforce->setUser(null); - $this->perforce->setWindowsFlag(true); $expectedQuestion = 'Enter P4 User:'; $expectedCommand = 'p4 set P4USER=TEST_QUERY_USER'; $this->io->expects($this->at(0)) @@ -196,8 +201,8 @@ class PerforceTest extends \PHPUnit_Framework_TestCase public function testQueryP4UserStoresResponseToQueryForUserWithoutWindows() { + $this->createNewPerforceWithWindowsFlag(false); $this->perforce->setUser(null); - $this->perforce->setWindowsFlag(false); $expectedQuestion = 'Enter P4 User:'; $expectedCommand = 'export P4USER=TEST_QUERY_USER'; $this->io->expects($this->at(0)) @@ -226,7 +231,7 @@ class PerforceTest extends \PHPUnit_Framework_TestCase public function testQueryP4PasswordWithPasswordSetInP4VariablesWithWindowsOS() { - $this->perforce->setWindowsFlag(true); + $this->createNewPerforceWithWindowsFlag(true); $expectedCommand = 'p4 set'; $callback = function($command, &$output) { @@ -243,7 +248,7 @@ class PerforceTest extends \PHPUnit_Framework_TestCase public function testQueryP4PasswordWithPasswordSetInP4VariablesNotWindowsOS() { - $this->perforce->setWindowsFlag(false); + $this->createNewPerforceWithWindowsFlag(false); $expectedCommand = 'echo $P4PASSWD'; $callback = function($command, &$output) {