Fix DownloadManagerTest creating directories on disk
parent
939c745a9a
commit
0e9f88a3da
|
@ -24,6 +24,7 @@ use Composer\Util\Filesystem;
|
||||||
class DownloadManager
|
class DownloadManager
|
||||||
{
|
{
|
||||||
private $preferSource = false;
|
private $preferSource = false;
|
||||||
|
private $filesystem;
|
||||||
private $downloaders = array();
|
private $downloaders = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,9 +32,10 @@ class DownloadManager
|
||||||
*
|
*
|
||||||
* @param Boolean $preferSource prefer downloading from source
|
* @param Boolean $preferSource prefer downloading from source
|
||||||
*/
|
*/
|
||||||
public function __construct($preferSource = false)
|
public function __construct($preferSource = false, Filesystem $filesystem = null)
|
||||||
{
|
{
|
||||||
$this->preferSource = $preferSource;
|
$this->preferSource = $preferSource;
|
||||||
|
$this->filesystem = $filesystem ?: new Filesystem();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -135,8 +137,7 @@ class DownloadManager
|
||||||
throw new \InvalidArgumentException('Package '.$package.' must have a source or dist specified');
|
throw new \InvalidArgumentException('Package '.$package.' must have a source or dist specified');
|
||||||
}
|
}
|
||||||
|
|
||||||
$fs = new Filesystem();
|
$this->filesystem->ensureDirectoryExists($targetDir);
|
||||||
$fs->ensureDirectoryExists($targetDir);
|
|
||||||
|
|
||||||
$downloader = $this->getDownloaderForInstalledPackage($package);
|
$downloader = $this->getDownloaderForInstalledPackage($package);
|
||||||
$downloader->download($package, $targetDir);
|
$downloader->download($package, $targetDir);
|
||||||
|
|
|
@ -16,10 +16,17 @@ use Composer\Downloader\DownloadManager;
|
||||||
|
|
||||||
class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
protected $filesystem;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->filesystem = $this->getMock('Composer\Util\Filesystem');
|
||||||
|
}
|
||||||
|
|
||||||
public function testSetGetDownloader()
|
public function testSetGetDownloader()
|
||||||
{
|
{
|
||||||
$downloader = $this->createDownloaderMock();
|
$downloader = $this->createDownloaderMock();
|
||||||
$manager = new DownloadManager();
|
$manager = new DownloadManager(false, $this->filesystem);
|
||||||
|
|
||||||
$manager->setDownloader('test', $downloader);
|
$manager->setDownloader('test', $downloader);
|
||||||
$this->assertSame($downloader, $manager->getDownloader('test'));
|
$this->assertSame($downloader, $manager->getDownloader('test'));
|
||||||
|
@ -36,7 +43,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
||||||
->method('getInstallationSource')
|
->method('getInstallationSource')
|
||||||
->will($this->returnValue(null));
|
->will($this->returnValue(null));
|
||||||
|
|
||||||
$manager = new DownloadManager();
|
$manager = new DownloadManager(false, $this->filesystem);
|
||||||
|
|
||||||
$this->setExpectedException('InvalidArgumentException');
|
$this->setExpectedException('InvalidArgumentException');
|
||||||
|
|
||||||
|
@ -62,6 +69,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
||||||
->will($this->returnValue('dist'));
|
->will($this->returnValue('dist'));
|
||||||
|
|
||||||
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
||||||
|
->setConstructorArgs(array(false, $this->filesystem))
|
||||||
->setMethods(array('getDownloader'))
|
->setMethods(array('getDownloader'))
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
|
@ -93,6 +101,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
||||||
->will($this->returnValue('source'));
|
->will($this->returnValue('source'));
|
||||||
|
|
||||||
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
||||||
|
->setConstructorArgs(array(false, $this->filesystem))
|
||||||
->setMethods(array('getDownloader'))
|
->setMethods(array('getDownloader'))
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
|
@ -126,6 +135,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
||||||
->will($this->returnValue('source'));
|
->will($this->returnValue('source'));
|
||||||
|
|
||||||
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
||||||
|
->setConstructorArgs(array(false, $this->filesystem))
|
||||||
->setMethods(array('getDownloader'))
|
->setMethods(array('getDownloader'))
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
|
@ -157,6 +167,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
||||||
->will($this->returnValue('dist'));
|
->will($this->returnValue('dist'));
|
||||||
|
|
||||||
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
||||||
|
->setConstructorArgs(array(false, $this->filesystem))
|
||||||
->setMethods(array('getDownloader'))
|
->setMethods(array('getDownloader'))
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
|
@ -195,6 +206,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
||||||
->with($package, 'target_dir');
|
->with($package, 'target_dir');
|
||||||
|
|
||||||
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
||||||
|
->setConstructorArgs(array(false, $this->filesystem))
|
||||||
->setMethods(array('getDownloaderForInstalledPackage'))
|
->setMethods(array('getDownloaderForInstalledPackage'))
|
||||||
->getMock();
|
->getMock();
|
||||||
$manager
|
$manager
|
||||||
|
@ -218,7 +230,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
||||||
->method('getDistType')
|
->method('getDistType')
|
||||||
->will($this->returnValue(null));
|
->will($this->returnValue(null));
|
||||||
|
|
||||||
$manager = new DownloadManager();
|
$manager = new DownloadManager(false, $this->filesystem);
|
||||||
|
|
||||||
$this->setExpectedException('InvalidArgumentException');
|
$this->setExpectedException('InvalidArgumentException');
|
||||||
$manager->download($package, 'target_dir');
|
$manager->download($package, 'target_dir');
|
||||||
|
@ -248,6 +260,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
||||||
->with($package, 'target_dir');
|
->with($package, 'target_dir');
|
||||||
|
|
||||||
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
||||||
|
->setConstructorArgs(array(false, $this->filesystem))
|
||||||
->setMethods(array('getDownloaderForInstalledPackage'))
|
->setMethods(array('getDownloaderForInstalledPackage'))
|
||||||
->getMock();
|
->getMock();
|
||||||
$manager
|
$manager
|
||||||
|
@ -283,6 +296,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
||||||
->with($package, 'target_dir');
|
->with($package, 'target_dir');
|
||||||
|
|
||||||
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
||||||
|
->setConstructorArgs(array(false, $this->filesystem))
|
||||||
->setMethods(array('getDownloaderForInstalledPackage'))
|
->setMethods(array('getDownloaderForInstalledPackage'))
|
||||||
->getMock();
|
->getMock();
|
||||||
$manager
|
$manager
|
||||||
|
@ -318,6 +332,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
||||||
->with($package, 'target_dir');
|
->with($package, 'target_dir');
|
||||||
|
|
||||||
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
||||||
|
->setConstructorArgs(array(false, $this->filesystem))
|
||||||
->setMethods(array('getDownloaderForInstalledPackage'))
|
->setMethods(array('getDownloaderForInstalledPackage'))
|
||||||
->getMock();
|
->getMock();
|
||||||
$manager
|
$manager
|
||||||
|
@ -354,6 +369,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
||||||
->with($package, 'target_dir');
|
->with($package, 'target_dir');
|
||||||
|
|
||||||
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
||||||
|
->setConstructorArgs(array(false, $this->filesystem))
|
||||||
->setMethods(array('getDownloaderForInstalledPackage'))
|
->setMethods(array('getDownloaderForInstalledPackage'))
|
||||||
->getMock();
|
->getMock();
|
||||||
$manager
|
$manager
|
||||||
|
@ -390,6 +406,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
||||||
->with($package, 'target_dir');
|
->with($package, 'target_dir');
|
||||||
|
|
||||||
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
||||||
|
->setConstructorArgs(array(false, $this->filesystem))
|
||||||
->setMethods(array('getDownloaderForInstalledPackage'))
|
->setMethods(array('getDownloaderForInstalledPackage'))
|
||||||
->getMock();
|
->getMock();
|
||||||
$manager
|
$manager
|
||||||
|
@ -414,7 +431,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
||||||
->method('getDistType')
|
->method('getDistType')
|
||||||
->will($this->returnValue(null));
|
->will($this->returnValue(null));
|
||||||
|
|
||||||
$manager = new DownloadManager();
|
$manager = new DownloadManager(false, $this->filesystem);
|
||||||
$manager->setPreferSource(true);
|
$manager->setPreferSource(true);
|
||||||
|
|
||||||
$this->setExpectedException('InvalidArgumentException');
|
$this->setExpectedException('InvalidArgumentException');
|
||||||
|
@ -450,6 +467,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
||||||
->with($initial, $target, 'vendor/bundles/FOS/UserBundle');
|
->with($initial, $target, 'vendor/bundles/FOS/UserBundle');
|
||||||
|
|
||||||
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
||||||
|
->setConstructorArgs(array(false, $this->filesystem))
|
||||||
->setMethods(array('getDownloaderForInstalledPackage'))
|
->setMethods(array('getDownloaderForInstalledPackage'))
|
||||||
->getMock();
|
->getMock();
|
||||||
$manager
|
$manager
|
||||||
|
@ -486,6 +504,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
||||||
->with($initial, 'vendor/bundles/FOS/UserBundle');
|
->with($initial, 'vendor/bundles/FOS/UserBundle');
|
||||||
|
|
||||||
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
||||||
|
->setConstructorArgs(array(false, $this->filesystem))
|
||||||
->setMethods(array('getDownloaderForInstalledPackage', 'download'))
|
->setMethods(array('getDownloaderForInstalledPackage', 'download'))
|
||||||
->getMock();
|
->getMock();
|
||||||
$manager
|
$manager
|
||||||
|
@ -526,6 +545,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
||||||
->with($initial, $target, 'vendor/pkg');
|
->with($initial, $target, 'vendor/pkg');
|
||||||
|
|
||||||
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
||||||
|
->setConstructorArgs(array(false, $this->filesystem))
|
||||||
->setMethods(array('getDownloaderForInstalledPackage', 'download'))
|
->setMethods(array('getDownloaderForInstalledPackage', 'download'))
|
||||||
->getMock();
|
->getMock();
|
||||||
$manager
|
$manager
|
||||||
|
@ -562,6 +582,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
||||||
->with($initial, 'vendor/pkg');
|
->with($initial, 'vendor/pkg');
|
||||||
|
|
||||||
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
||||||
|
->setConstructorArgs(array(false, $this->filesystem))
|
||||||
->setMethods(array('getDownloaderForInstalledPackage', 'download'))
|
->setMethods(array('getDownloaderForInstalledPackage', 'download'))
|
||||||
->getMock();
|
->getMock();
|
||||||
$manager
|
$manager
|
||||||
|
@ -588,6 +609,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
||||||
->with($package, 'vendor/bundles/FOS/UserBundle');
|
->with($package, 'vendor/bundles/FOS/UserBundle');
|
||||||
|
|
||||||
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
||||||
|
->setConstructorArgs(array(false, $this->filesystem))
|
||||||
->setMethods(array('getDownloaderForInstalledPackage'))
|
->setMethods(array('getDownloaderForInstalledPackage'))
|
||||||
->getMock();
|
->getMock();
|
||||||
$manager
|
$manager
|
||||||
|
|
Loading…
Reference in New Issue