Fix downloader tests on windows and mock Filesystem properly

main
Jordi Boggiano 13 years ago
parent e7441edcf1
commit 230e145053

@ -24,11 +24,13 @@ abstract class VcsDownloader implements DownloaderInterface
{
protected $io;
protected $process;
protected $filesystem;
public function __construct(IOInterface $io, ProcessExecutor $process = null)
public function __construct(IOInterface $io, ProcessExecutor $process = null, Filesystem $fs = null)
{
$this->io = $io;
$this->process = $process ?: new ProcessExecutor;
$this->filesystem = $fs ?: new Filesystem;
}
/**
@ -74,8 +76,7 @@ abstract class VcsDownloader implements DownloaderInterface
public function remove(PackageInterface $package, $path)
{
$this->enforceCleanDirectory($path);
$fs = new Filesystem();
$fs->removeDirectory($path);
$this->filesystem->removeDirectory($path);
}
/**

@ -32,7 +32,7 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
public function testDownload()
{
$expectedGitCommand = 'git clone \'https://github.com/l3l0/composer\' \'composerPath\' && cd \'composerPath\' && git checkout \'ref\' && git reset --hard \'ref\'';
$expectedGitCommand = $this->getCmd('git clone \'https://github.com/l3l0/composer\' \'composerPath\' && cd \'composerPath\' && git checkout \'ref\' && git reset --hard \'ref\'');
$packageMock = $this->getMock('Composer\Package\PackageInterface');
$packageMock->expects($this->any())
->method('getSourceReference')
@ -66,8 +66,8 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
public function testUpdate()
{
$expectedGitUpdateCommand = 'cd \'composerPath\' && git fetch && git checkout \'ref\' && git reset --hard \'ref\'';
$expectedGitResetCommand = 'cd \'composerPath\' && git status --porcelain';
$expectedGitUpdateCommand = $this->getCmd('cd \'composerPath\' && git fetch && git checkout \'ref\' && git reset --hard \'ref\'');
$expectedGitResetCommand = $this->getCmd('cd \'composerPath\' && git status --porcelain');
$packageMock = $this->getMock('Composer\Package\PackageInterface');
$packageMock->expects($this->any())
@ -90,22 +90,35 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
public function testRemove()
{
$expectedGitResetCommand = 'cd \'composerPath\' && git status --porcelain';
$expectedGitResetCommand = $this->getCmd('cd \'composerPath\' && git status --porcelain');
$packageMock = $this->getMock('Composer\Package\PackageInterface');
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
$processExecutor->expects($this->any())
->method('execute')
->with($this->equalTo($expectedGitResetCommand));
$filesystem = $this->getMock('Composer\Util\Filesystem');
$filesystem->expects($this->any())
->method('removeDirectory')
->with($this->equalTo('composerPath'));
$downloader = new GitDownloader($this->getMock('Composer\IO\IOInterface'), $processExecutor);
$downloader = new GitDownloader($this->getMock('Composer\IO\IOInterface'), $processExecutor, $filesystem);
$downloader->remove($packageMock, 'composerPath');
}
public function testGetInstallationSource()
{
$downloader = new GitDownloader($this->getMock('Composer\IO\IOInterface'));
$this->assertEquals('source', $downloader->getInstallationSource());
}
private function getCmd($cmd)
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
return strtr($cmd, "'", '"');
}
return $cmd;
}
}

@ -32,7 +32,7 @@ class HgDownloaderTest extends \PHPUnit_Framework_TestCase
public function testDownload()
{
$expectedGitCommand = 'hg clone \'https://mercurial.dev/l3l0/composer\' \'composerPath\' && cd \'composerPath\' && hg up \'ref\'';
$expectedGitCommand = $this->getCmd('hg clone \'https://mercurial.dev/l3l0/composer\' \'composerPath\' && cd \'composerPath\' && hg up \'ref\'');
$packageMock = $this->getMock('Composer\Package\PackageInterface');
$packageMock->expects($this->any())
->method('getSourceReference')
@ -66,8 +66,8 @@ class HgDownloaderTest extends \PHPUnit_Framework_TestCase
public function testUpdate()
{
$expectedUpdateCommand = 'cd \'composerPath\' && hg pull && hg up \'ref\'';
$expectedResetCommand = 'cd \'composerPath\' && hg st';
$expectedUpdateCommand = $this->getCmd('cd \'composerPath\' && hg pull && hg up \'ref\'');
$expectedResetCommand = $this->getCmd('cd \'composerPath\' && hg st');
$packageMock = $this->getMock('Composer\Package\PackageInterface');
$packageMock->expects($this->any())
@ -90,22 +90,35 @@ class HgDownloaderTest extends \PHPUnit_Framework_TestCase
public function testRemove()
{
$expectedResetCommand = 'cd \'composerPath\' && hg st';
$expectedResetCommand = $this->getCmd('cd \'composerPath\' && hg st');
$packageMock = $this->getMock('Composer\Package\PackageInterface');
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
$processExecutor->expects($this->any())
->method('execute')
->with($this->equalTo($expectedResetCommand));
$filesystem = $this->getMock('Composer\Util\Filesystem');
$filesystem->expects($this->any())
->method('removeDirectory')
->with($this->equalTo('composerPath'));
$downloader = new HgDownloader($this->getMock('Composer\IO\IOInterface'), $processExecutor);
$downloader = new HgDownloader($this->getMock('Composer\IO\IOInterface'), $processExecutor, $filesystem);
$downloader->remove($packageMock, 'composerPath');
}
public function testGetInstallationSource()
{
$downloader = new HgDownloader($this->getMock('Composer\IO\IOInterface'));
$this->assertEquals('source', $downloader->getInstallationSource());
}
private function getCmd($cmd)
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
return strtr($cmd, "'", '"');
}
return $cmd;
}
}

Loading…
Cancel
Save