From 85caea7fb037a3035e0e09a1fa0319a9df8f4672 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20B=C3=B6sing?= <2189546+boesing@users.noreply.github.com> Date: Mon, 13 Jun 2022 13:44:00 +0200 Subject: [PATCH] bugfix: ensure package returned by `Composer` is always implementing `BasePackage` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes `InvalidArgumentException` with message `Only subclasses of BasePackage are supported`. Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com> --- test/ComponentInstallerTest.php | 50 ++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/test/ComponentInstallerTest.php b/test/ComponentInstallerTest.php index 7ee2eb0..6216ae2 100644 --- a/test/ComponentInstallerTest.php +++ b/test/ComponentInstallerTest.php @@ -73,9 +73,6 @@ protected function setUp(): void vfsStream::url('project') ); - $composer = $this->createMock(Composer::class); - $this->composer = $composer; - $rootPackage = $this->createMock(RootPackage::class); $this->rootPackage = $rootPackage; @@ -85,6 +82,16 @@ protected function setUp(): void return $this->rootPackageExtra; }); + $installationManager = $this->createMock(InstallationManager::class); + $this->installationManager = $installationManager; + + $composer = $this->createComposerMock( + $installationManager, + $rootPackage + ); + + $this->composer = $composer; + $this->rootPackage ->method('getProvides') ->willReturn([]); @@ -129,13 +136,6 @@ protected function setUp(): void $this->composer, $this->io ); - - $installationManager = $this->createMock(InstallationManager::class); - $this->installationManager = $installationManager; - - $this->composer - ->method('getInstallationManager') - ->willReturn($installationManager); } /** @@ -1067,12 +1067,7 @@ public function testOnPostPackageInstallPromptsForConfigOptionsWhenDefinedAsArra public function testAddPackageToConfigWillPassProjectRootAsStringToConfigDiscovery(): void { - $installationManager = $this->createMock(InstallationManager::class); - - $composer = $this->createMock(Composer::class); - $composer - ->method('getInstallationManager') - ->willReturn($installationManager); + $composer = $this->createComposerMock(); $io = $this->createMock(IOInterface::class); $io @@ -2010,4 +2005,27 @@ public function packageUpdateScenarios(): Generator ], ]; } + + /** + * @return Composer&MockObject + */ + private function createComposerMock( + ?InstallationManager $installationManager = null, + ?RootPackage $package = null + ): Composer { + $installationManager ??= $this->createMock(InstallationManager::class); + $composer = $this->createMock(Composer::class); + + $composer + ->method('getInstallationManager') + ->willReturn($installationManager); + + $package ??= $this->createMock(RootPackage::class); + + $composer + ->method('getPackage') + ->willReturn($package); + + return $composer; + } }