From c11105dd6033f25225ce2c16baf64465f891e2a8 Mon Sep 17 00:00:00 2001 From: Clark Stuth Date: Tue, 18 Mar 2014 14:39:47 -0500 Subject: [PATCH] Fixing bug not cleaning up workspaces. --- .../Repository/Vcs/PerforceDriver.php | 6 +++++ src/Composer/Util/Perforce.php | 24 ++++++++++++++++--- .../Repository/Vcs/PerforceDriverTest.php | 11 ++++++++- tests/Composer/Test/Util/PerforceTest.php | 15 ++++++++++++ 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/Composer/Repository/Vcs/PerforceDriver.php b/src/Composer/Repository/Vcs/PerforceDriver.php index 535a79516..090de1bb8 100644 --- a/src/Composer/Repository/Vcs/PerforceDriver.php +++ b/src/Composer/Repository/Vcs/PerforceDriver.php @@ -193,4 +193,10 @@ class PerforceDriver extends VcsDriver { $this->perforce = $perforce; } + + public function getPerforce() + { + return $this->perforce; + } + } diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index ecafaf6f0..659cbfc67 100644 --- a/src/Composer/Util/Perforce.php +++ b/src/Composer/Util/Perforce.php @@ -37,6 +37,8 @@ class Perforce protected $io; + protected $filesystem; + public function __construct($repoConfig, $port, $path, ProcessExecutor $process, $isWindows, IOInterface $io) { $this->windowsFlag = $isWindows; @@ -109,10 +111,10 @@ class Perforce public function cleanupClientSpec() { $client = $this->getClient(); - $command = 'p4 client -d $client'; + $command = 'p4 client -d ' . $client; $this->executeCommand($command); $clientSpec = $this->getP4ClientSpec(); - $fileSystem = new FileSystem($this->process); + $fileSystem = $this->getFilesystem(); $fileSystem->remove($clientSpec); } @@ -141,7 +143,7 @@ class Perforce public function initializePath($path) { $this->path = $path; - $fs = new Filesystem(); + $fs = $this->getFilesystem(); $fs->ensureDirectoryExists($path); } @@ -559,4 +561,20 @@ class Perforce return $result; } + + public function getFilesystem() + { + if (empty($this->filesystem)) + { + $this->filesystem = new Filesystem($this->process); + } + return $this->filesystem; + } + + + public function setFilesystem(Filesystem $fs) + { + $this->filesystem = $fs; + } + } diff --git a/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php b/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php index 7666efebc..9afc57d30 100644 --- a/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php @@ -93,7 +93,7 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase protected function getMockPerforce() { - $methods = array('p4login', 'checkStream', 'writeP4ClientSpec', 'connectClient', 'getComposerInformation'); + $methods = array('p4login', 'checkStream', 'writeP4ClientSpec', 'connectClient', 'getComposerInformation', 'cleanupClientSpec'); return $this->getMockBuilder('Composer\Util\Perforce', $methods)->disableOriginalConstructor()->getMock(); } @@ -159,4 +159,13 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase $this->expectOutputString(''); $this->assertFalse(PerforceDriver::supports($this->io, $this->config, 'existing.url')); } + + 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 b7865d5e6..65857343b 100644 --- a/tests/Composer/Test/Util/PerforceTest.php +++ b/tests/Composer/Test/Util/PerforceTest.php @@ -679,4 +679,19 @@ class PerforceTest extends \PHPUnit_Framework_TestCase { $this->perforce->setStream('//depot/branch'); } + + public function testCleanupClientSpecShouldDeleteClient() + { + $fs = $this->getMock('Composer\Util\Filesystem'); + $this->perforce->setFilesystem($fs); + + $testClient = $this->perforce->getClient(); + $expectedCommand = 'p4 client -d ' . $testClient; + $this->processExecutor->expects($this->once())->method('execute')->with($this->equalTo($expectedCommand)); + + $fs->expects($this->once())->method('remove')->with($this->perforce->getP4ClientSpec()); + + $this->perforce->cleanupClientSpec(); + } + }