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; + } }