1
0
Fork 0

Fixing bug not cleaning up workspaces.

pull/2834/head
Clark Stuth 2014-03-18 14:39:47 -05:00
parent c6133050b3
commit 14a6406f9b
4 changed files with 52 additions and 4 deletions

View File

@ -193,4 +193,10 @@ class PerforceDriver extends VcsDriver
{
$this->perforce = $perforce;
}
public function getPerforce()
{
return $this->perforce;
}
}

View File

@ -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;
}
}

View File

@ -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());
}
}

View File

@ -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();
}
}