Fix downloader tests on windows and mock Filesystem properly
parent
e7441edcf1
commit
230e145053
|
@ -24,11 +24,13 @@ abstract class VcsDownloader implements DownloaderInterface
|
||||||
{
|
{
|
||||||
protected $io;
|
protected $io;
|
||||||
protected $process;
|
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->io = $io;
|
||||||
$this->process = $process ?: new ProcessExecutor;
|
$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)
|
public function remove(PackageInterface $package, $path)
|
||||||
{
|
{
|
||||||
$this->enforceCleanDirectory($path);
|
$this->enforceCleanDirectory($path);
|
||||||
$fs = new Filesystem();
|
$this->filesystem->removeDirectory($path);
|
||||||
$fs->removeDirectory($path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -32,7 +32,7 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testDownload()
|
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 = $this->getMock('Composer\Package\PackageInterface');
|
||||||
$packageMock->expects($this->any())
|
$packageMock->expects($this->any())
|
||||||
->method('getSourceReference')
|
->method('getSourceReference')
|
||||||
|
@ -66,8 +66,8 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testUpdate()
|
public function testUpdate()
|
||||||
{
|
{
|
||||||
$expectedGitUpdateCommand = 'cd \'composerPath\' && git fetch && git checkout \'ref\' && git reset --hard \'ref\'';
|
$expectedGitUpdateCommand = $this->getCmd('cd \'composerPath\' && git fetch && git checkout \'ref\' && git reset --hard \'ref\'');
|
||||||
$expectedGitResetCommand = 'cd \'composerPath\' && git status --porcelain';
|
$expectedGitResetCommand = $this->getCmd('cd \'composerPath\' && git status --porcelain');
|
||||||
|
|
||||||
$packageMock = $this->getMock('Composer\Package\PackageInterface');
|
$packageMock = $this->getMock('Composer\Package\PackageInterface');
|
||||||
$packageMock->expects($this->any())
|
$packageMock->expects($this->any())
|
||||||
|
@ -90,22 +90,35 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testRemove()
|
public function testRemove()
|
||||||
{
|
{
|
||||||
$expectedGitResetCommand = 'cd \'composerPath\' && git status --porcelain';
|
$expectedGitResetCommand = $this->getCmd('cd \'composerPath\' && git status --porcelain');
|
||||||
|
|
||||||
$packageMock = $this->getMock('Composer\Package\PackageInterface');
|
$packageMock = $this->getMock('Composer\Package\PackageInterface');
|
||||||
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
|
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
|
||||||
$processExecutor->expects($this->any())
|
$processExecutor->expects($this->any())
|
||||||
->method('execute')
|
->method('execute')
|
||||||
->with($this->equalTo($expectedGitResetCommand));
|
->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');
|
$downloader->remove($packageMock, 'composerPath');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetInstallationSource()
|
public function testGetInstallationSource()
|
||||||
{
|
{
|
||||||
$downloader = new GitDownloader($this->getMock('Composer\IO\IOInterface'));
|
$downloader = new GitDownloader($this->getMock('Composer\IO\IOInterface'));
|
||||||
|
|
||||||
$this->assertEquals('source', $downloader->getInstallationSource());
|
$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()
|
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 = $this->getMock('Composer\Package\PackageInterface');
|
||||||
$packageMock->expects($this->any())
|
$packageMock->expects($this->any())
|
||||||
->method('getSourceReference')
|
->method('getSourceReference')
|
||||||
|
@ -66,8 +66,8 @@ class HgDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testUpdate()
|
public function testUpdate()
|
||||||
{
|
{
|
||||||
$expectedUpdateCommand = 'cd \'composerPath\' && hg pull && hg up \'ref\'';
|
$expectedUpdateCommand = $this->getCmd('cd \'composerPath\' && hg pull && hg up \'ref\'');
|
||||||
$expectedResetCommand = 'cd \'composerPath\' && hg st';
|
$expectedResetCommand = $this->getCmd('cd \'composerPath\' && hg st');
|
||||||
|
|
||||||
$packageMock = $this->getMock('Composer\Package\PackageInterface');
|
$packageMock = $this->getMock('Composer\Package\PackageInterface');
|
||||||
$packageMock->expects($this->any())
|
$packageMock->expects($this->any())
|
||||||
|
@ -90,22 +90,35 @@ class HgDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testRemove()
|
public function testRemove()
|
||||||
{
|
{
|
||||||
$expectedResetCommand = 'cd \'composerPath\' && hg st';
|
$expectedResetCommand = $this->getCmd('cd \'composerPath\' && hg st');
|
||||||
|
|
||||||
$packageMock = $this->getMock('Composer\Package\PackageInterface');
|
$packageMock = $this->getMock('Composer\Package\PackageInterface');
|
||||||
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
|
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
|
||||||
$processExecutor->expects($this->any())
|
$processExecutor->expects($this->any())
|
||||||
->method('execute')
|
->method('execute')
|
||||||
->with($this->equalTo($expectedResetCommand));
|
->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');
|
$downloader->remove($packageMock, 'composerPath');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetInstallationSource()
|
public function testGetInstallationSource()
|
||||||
{
|
{
|
||||||
$downloader = new HgDownloader($this->getMock('Composer\IO\IOInterface'));
|
$downloader = new HgDownloader($this->getMock('Composer\IO\IOInterface'));
|
||||||
|
|
||||||
$this->assertEquals('source', $downloader->getInstallationSource());
|
$this->assertEquals('source', $downloader->getInstallationSource());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getCmd($cmd)
|
||||||
|
{
|
||||||
|
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
|
||||||
|
return strtr($cmd, "'", '"');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $cmd;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue