1
0
Fork 0

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
Julius Beckmann 2014-02-06 10:50:06 +01:00
parent ed02997a7b
commit ed5da804dd
2 changed files with 89 additions and 2 deletions

View File

@ -179,8 +179,10 @@ class DownloadManager
$this->filesystem->ensureDirectoryExists($targetDir); $this->filesystem->ensureDirectoryExists($targetDir);
$downloader = $this->getDownloaderForInstalledPackage($package); $downloader = $this->getDownloaderForInstalledPackage($package);
if($downloader) {
$downloader->download($package, $targetDir); $downloader->download($package, $targetDir);
} }
}
/** /**
* Updates package from initial to target version. * Updates package from initial to target version.
@ -194,6 +196,11 @@ class DownloadManager
public function update(PackageInterface $initial, PackageInterface $target, $targetDir) public function update(PackageInterface $initial, PackageInterface $target, $targetDir)
{ {
$downloader = $this->getDownloaderForInstalledPackage($initial); $downloader = $this->getDownloaderForInstalledPackage($initial);
if(!$downloader) {
return;
}
$installationSource = $initial->getInstallationSource(); $installationSource = $initial->getInstallationSource();
if ('dist' === $installationSource) { if ('dist' === $installationSource) {
@ -230,6 +237,8 @@ class DownloadManager
public function remove(PackageInterface $package, $targetDir) public function remove(PackageInterface $package, $targetDir)
{ {
$downloader = $this->getDownloaderForInstalledPackage($package); $downloader = $this->getDownloaderForInstalledPackage($package);
if($downloader) {
$downloader->remove($package, $targetDir); $downloader->remove($package, $targetDir);
} }
}
} }

View File

@ -182,6 +182,19 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
$manager->getDownloaderForInstalledPackage($package); $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() public function testFullPackageDownload()
{ {
$package = $this->createPackageMock(); $package = $this->createPackageMock();
@ -308,6 +321,36 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
$manager->download($package, 'target_dir'); $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() public function testFullPackageDownloadWithSourcePreferred()
{ {
$package = $this->createPackageMock(); $package = $this->createPackageMock();
@ -598,6 +641,24 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
$manager->update($initial, $target, 'vendor/pkg'); $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() public function testRemove()
{ {
$package = $this->createPackageMock(); $package = $this->createPackageMock();
@ -621,6 +682,23 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase
$manager->remove($package, 'vendor/bundles/FOS/UserBundle'); $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() private function createDownloaderMock()
{ {
return $this->getMockBuilder('Composer\Downloader\DownloaderInterface') return $this->getMockBuilder('Composer\Downloader\DownloaderInterface')