Fix tests
parent
b855643865
commit
a02940cafb
|
@ -27,15 +27,17 @@ use Composer\Util\RemoteFilesystem;
|
||||||
class FileDownloader implements DownloaderInterface
|
class FileDownloader implements DownloaderInterface
|
||||||
{
|
{
|
||||||
protected $io;
|
protected $io;
|
||||||
|
protected $rfs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param IOInterface $io The IO instance
|
* @param IOInterface $io The IO instance
|
||||||
*/
|
*/
|
||||||
public function __construct(IOInterface $io)
|
public function __construct(IOInterface $io, RemoteFilesystem $rfs = null)
|
||||||
{
|
{
|
||||||
$this->io = $io;
|
$this->io = $io;
|
||||||
|
$this->rfs = $rfs ?: new RemoteFilesystem($io);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -71,8 +73,7 @@ class FileDownloader implements DownloaderInterface
|
||||||
|
|
||||||
$url = $this->processUrl($url);
|
$url = $this->processUrl($url);
|
||||||
|
|
||||||
$rfs = new RemoteFilesystem($this->io);
|
$this->rfs->copy($package->getSourceUrl(), $url, $fileName);
|
||||||
$rfs->copy($package->getSourceUrl(), $url, $fileName);
|
|
||||||
$this->io->write('');
|
$this->io->write('');
|
||||||
|
|
||||||
if (!file_exists($fileName)) {
|
if (!file_exists($fileName)) {
|
||||||
|
|
|
@ -17,6 +17,13 @@ use Composer\Util\Filesystem;
|
||||||
|
|
||||||
class FileDownloaderTest extends \PHPUnit_Framework_TestCase
|
class FileDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
protected function getDownloader($io = null, $rfs = null)
|
||||||
|
{
|
||||||
|
$io = $io ?: $this->getMock('Composer\IO\IOInterface');
|
||||||
|
$rfs = $rfs ?: $this->getMockBuilder('Composer\Util\RemoteFilesystem')->disableOriginalConstructor()->getMock();
|
||||||
|
return new FileDownloader($io, $rfs);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \InvalidArgumentException
|
* @expectedException \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
|
@ -28,7 +35,7 @@ class FileDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
->will($this->returnValue(null))
|
->will($this->returnValue(null))
|
||||||
;
|
;
|
||||||
|
|
||||||
$downloader = new FileDownloader($this->getMock('Composer\IO\IOInterface'));
|
$downloader = $this->getDownloader();
|
||||||
$downloader->download($packageMock, '/path');
|
$downloader->download($packageMock, '/path');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +49,7 @@ class FileDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$path = tempnam(sys_get_temp_dir(), 'c');
|
$path = tempnam(sys_get_temp_dir(), 'c');
|
||||||
|
|
||||||
$downloader = new FileDownloader($this->getMock('Composer\IO\IOInterface'));
|
$downloader = $this->getDownloader();
|
||||||
try {
|
try {
|
||||||
$downloader->download($packageMock, $path);
|
$downloader->download($packageMock, $path);
|
||||||
$this->fail();
|
$this->fail();
|
||||||
|
@ -63,7 +70,7 @@ class FileDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
->will($this->returnValue('http://example.com/script.js'))
|
->will($this->returnValue('http://example.com/script.js'))
|
||||||
;
|
;
|
||||||
|
|
||||||
$downloader = new FileDownloader($this->getMock('Composer\IO\IOInterface'));
|
$downloader = $this->getDownloader();
|
||||||
$method = new \ReflectionMethod($downloader, 'getFileName');
|
$method = new \ReflectionMethod($downloader, 'getFileName');
|
||||||
$method->setAccessible(true);
|
$method->setAccessible(true);
|
||||||
|
|
||||||
|
@ -93,7 +100,7 @@ class FileDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
}))
|
}))
|
||||||
;
|
;
|
||||||
|
|
||||||
$downloader = new FileDownloader($ioMock);
|
$downloader = $this->getDownloader($ioMock);
|
||||||
try {
|
try {
|
||||||
$downloader->download($packageMock, $path);
|
$downloader->download($packageMock, $path);
|
||||||
$this->fail();
|
$this->fail();
|
||||||
|
@ -126,7 +133,12 @@ class FileDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
$path = sys_get_temp_dir().'/'.md5(time().rand());
|
$path = sys_get_temp_dir().'/'.md5(time().rand());
|
||||||
} while (file_exists($path));
|
} while (file_exists($path));
|
||||||
|
|
||||||
$downloader = new FileDownloader($this->getMock('Composer\IO\IOInterface'));
|
$downloader = $this->getDownloader();
|
||||||
|
|
||||||
|
// make sure the file expected to be downloaded is on disk already
|
||||||
|
mkdir($path, 0777, true);
|
||||||
|
touch($path.'/script.js');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$downloader->download($packageMock, $path);
|
$downloader->download($packageMock, $path);
|
||||||
$this->fail();
|
$this->fail();
|
||||||
|
|
Loading…
Reference in New Issue