From 002f0f30f4048928161646d96f291145e8cd5e89 Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Tue, 27 Jan 2015 12:13:22 +0100 Subject: [PATCH] Fixed throwing of load errors --- src/Package/PackageManagerImpl.php | 8 ++++---- tests/Package/PackageManagerImplTest.php | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/Package/PackageManagerImpl.php b/src/Package/PackageManagerImpl.php index 4f8c5d3..5bec305 100644 --- a/src/Package/PackageManagerImpl.php +++ b/src/Package/PackageManagerImpl.php @@ -360,11 +360,11 @@ private function assertPackagesLoaded() private function assertNoLoadErrors(Package $package) { - $loadError = $package->getLoadErrors(); + $loadErrors = $package->getLoadErrors(); - if ($loadError) { - // Rethrow error - throw $loadError; + if (count($loadErrors) > 0) { + // Rethrow first error + throw reset($loadErrors); } } } diff --git a/tests/Package/PackageManagerImplTest.php b/tests/Package/PackageManagerImplTest.php index c37d4e4..9389ba5 100644 --- a/tests/Package/PackageManagerImplTest.php +++ b/tests/Package/PackageManagerImplTest.php @@ -530,6 +530,23 @@ public function testInstallPackageFailsIfNoNameFound() $this->manager->installPackage($this->packageDir3); } + /** + * @expectedException \Puli\RepositoryManager\Api\Package\UnsupportedVersionException + * @expectedExceptionMessage The exception text + */ + public function testInstallPackageFailsIfPackageNotLoadableAndCustomNameSet() + { + $manager = new PackageManagerImpl($this->environment, $this->packageFileStorage); + $e = new UnsupportedVersionException('The exception text.'); + + $this->packageFileStorage->expects($this->once()) + ->method('loadPackageFile') + ->with(__DIR__.'/Fixtures/version-too-high/puli.json') + ->willThrowException($e); + + $manager->installPackage(__DIR__.'/Fixtures/version-too-high', 'vendor/my-package'); + } + public function testInstallPackageRevertsIfSavingNotPossible() { $this->initDefaultManager();