Fixed handling of Metapackages in DownloadManager.
The "getDownloaderForInstalledPackage" returns null for "metapackage" and the download(), update() and remove() methods did not handle this return value correctly.pull/2674/head
parent
ed02997a7b
commit
ed5da804dd
|
@ -179,7 +179,9 @@ class DownloadManager
|
|||
$this->filesystem->ensureDirectoryExists($targetDir);
|
||||
|
||||
$downloader = $this->getDownloaderForInstalledPackage($package);
|
||||
$downloader->download($package, $targetDir);
|
||||
if($downloader) {
|
||||
$downloader->download($package, $targetDir);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -194,6 +196,11 @@ class DownloadManager
|
|||
public function update(PackageInterface $initial, PackageInterface $target, $targetDir)
|
||||
{
|
||||
$downloader = $this->getDownloaderForInstalledPackage($initial);
|
||||
if(!$downloader) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$installationSource = $initial->getInstallationSource();
|
||||
|
||||
if ('dist' === $installationSource) {
|
||||
|
@ -230,6 +237,8 @@ class DownloadManager
|
|||
public function remove(PackageInterface $package, $targetDir)
|
||||
{
|
||||
$downloader = $this->getDownloaderForInstalledPackage($package);
|
||||
$downloader->remove($package, $targetDir);
|
||||
if($downloader) {
|
||||
$downloader->remove($package, $targetDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -182,6 +182,19 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
|||
$manager->getDownloaderForInstalledPackage($package);
|
||||
}
|
||||
|
||||
public function testGetDownloaderForMetapackage()
|
||||
{
|
||||
$package = $this->createPackageMock();
|
||||
$package
|
||||
->expects($this->once())
|
||||
->method('getType')
|
||||
->will($this->returnValue('metapackage'));
|
||||
|
||||
$manager = new DownloadManager(false, $this->filesystem);
|
||||
|
||||
$this->assertNull($manager->getDownloaderForInstalledPackage($package));
|
||||
}
|
||||
|
||||
public function testFullPackageDownload()
|
||||
{
|
||||
$package = $this->createPackageMock();
|
||||
|
@ -308,6 +321,36 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
|||
$manager->download($package, 'target_dir');
|
||||
}
|
||||
|
||||
public function testMetapackagePackageDownload()
|
||||
{
|
||||
$package = $this->createPackageMock();
|
||||
$package
|
||||
->expects($this->once())
|
||||
->method('getSourceType')
|
||||
->will($this->returnValue('git'));
|
||||
$package
|
||||
->expects($this->once())
|
||||
->method('getDistType')
|
||||
->will($this->returnValue(null));
|
||||
|
||||
$package
|
||||
->expects($this->once())
|
||||
->method('setInstallationSource')
|
||||
->with('source');
|
||||
|
||||
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
||||
->setConstructorArgs(array(false, $this->filesystem))
|
||||
->setMethods(array('getDownloaderForInstalledPackage'))
|
||||
->getMock();
|
||||
$manager
|
||||
->expects($this->once())
|
||||
->method('getDownloaderForInstalledPackage')
|
||||
->with($package)
|
||||
->will($this->returnValue(null)); // There is no downloader for Metapackages.
|
||||
|
||||
$manager->download($package, 'target_dir');
|
||||
}
|
||||
|
||||
public function testFullPackageDownloadWithSourcePreferred()
|
||||
{
|
||||
$package = $this->createPackageMock();
|
||||
|
@ -598,6 +641,24 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
|||
$manager->update($initial, $target, 'vendor/pkg');
|
||||
}
|
||||
|
||||
public function testUpdateMetapackage()
|
||||
{
|
||||
$initial = $this->createPackageMock();
|
||||
$target = $this->createPackageMock();
|
||||
|
||||
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
||||
->setConstructorArgs(array(false, $this->filesystem))
|
||||
->setMethods(array('getDownloaderForInstalledPackage'))
|
||||
->getMock();
|
||||
$manager
|
||||
->expects($this->once())
|
||||
->method('getDownloaderForInstalledPackage')
|
||||
->with($initial)
|
||||
->will($this->returnValue(null)); // There is no downloader for metapackages.
|
||||
|
||||
$manager->update($initial, $target, 'vendor/pkg');
|
||||
}
|
||||
|
||||
public function testRemove()
|
||||
{
|
||||
$package = $this->createPackageMock();
|
||||
|
@ -621,6 +682,23 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
|
|||
$manager->remove($package, 'vendor/bundles/FOS/UserBundle');
|
||||
}
|
||||
|
||||
public function testMetapackageRemove()
|
||||
{
|
||||
$package = $this->createPackageMock();
|
||||
|
||||
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
|
||||
->setConstructorArgs(array(false, $this->filesystem))
|
||||
->setMethods(array('getDownloaderForInstalledPackage'))
|
||||
->getMock();
|
||||
$manager
|
||||
->expects($this->once())
|
||||
->method('getDownloaderForInstalledPackage')
|
||||
->with($package)
|
||||
->will($this->returnValue(null)); // There is no downloader for metapackages.
|
||||
|
||||
$manager->remove($package, 'vendor/bundles/FOS/UserBundle');
|
||||
}
|
||||
|
||||
private function createDownloaderMock()
|
||||
{
|
||||
return $this->getMockBuilder('Composer\Downloader\DownloaderInterface')
|
||||
|
|
Loading…
Reference in New Issue