From ed5da804dd90a95d362c5f1ce5b8443f31934a21 Mon Sep 17 00:00:00 2001 From: Julius Beckmann Date: Thu, 6 Feb 2014 10:50:06 +0100 Subject: [PATCH] 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. --- src/Composer/Downloader/DownloadManager.php | 13 +++- .../Test/Downloader/DownloadManagerTest.php | 78 +++++++++++++++++++ 2 files changed, 89 insertions(+), 2 deletions(-) diff --git a/src/Composer/Downloader/DownloadManager.php b/src/Composer/Downloader/DownloadManager.php index e1eb1a9b7..ef6f79d5c 100644 --- a/src/Composer/Downloader/DownloadManager.php +++ b/src/Composer/Downloader/DownloadManager.php @@ -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); + } } } diff --git a/tests/Composer/Test/Downloader/DownloadManagerTest.php b/tests/Composer/Test/Downloader/DownloadManagerTest.php index 29b2edf90..48242a818 100644 --- a/tests/Composer/Test/Downloader/DownloadManagerTest.php +++ b/tests/Composer/Test/Downloader/DownloadManagerTest.php @@ -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')