Skip to content

Commit

Permalink
bugfix: ensure package returned by Composer is always implementing …
Browse files Browse the repository at this point in the history
…`BasePackage`

Fixes `InvalidArgumentException` with message `Only subclasses of BasePackage are supported`.

Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
  • Loading branch information
boesing committed Jun 13, 2022
1 parent 0d50e10 commit 85caea7
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions test/ComponentInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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([]);
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 85caea7

Please sign in to comment.