Skip to content

Commit bee44c4

Browse files
committed
622: add test for FindMatchingPackages->byProviders
1 parent c692193 commit bee44c4

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

test/unit/Installing/InstallForPhpProject/FindMatchingPackagesTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Composer\Repository\ArrayRepository;
1313
use Composer\Repository\RepositoryManager;
1414
use Composer\Util\HttpDownloader;
15+
use Php\Pie\ExtensionName;
1516
use Php\Pie\ExtensionType;
1617
use Php\Pie\Installing\InstallForPhpProject\FindMatchingPackages;
1718
use PHPUnit\Framework\Attributes\CoversClass;
@@ -69,4 +70,52 @@ public function testSearchResultsAreFilteredByExtensionName(): void
6970
(new FindMatchingPackages())->bySearching($composer, 'bar'),
7071
);
7172
}
73+
74+
public function testByProvider(): void
75+
{
76+
$package = new CompletePackage('foo/bar', '2.0.0.0', '2.0.0');
77+
$package->setDescription('The best extension there is');
78+
$package->setType(ExtensionType::PhpModule->value);
79+
80+
$repository = $this->createPartialMock(ArrayRepository::class, ['getProviders']);
81+
$repository->addPackage($package);
82+
$repository->expects(self::once())
83+
->method('getProviders')
84+
->with('ext-bar')
85+
->willReturn([
86+
'foo1/bar' => [
87+
'name' => 'foo1/bar',
88+
'description' => 'This is foo1/bar, not quite what you are looking for',
89+
'type' => 'library',
90+
],
91+
'foo/bar' => [
92+
'name' => 'foo/bar',
93+
'description' => 'The best extension there is',
94+
'type' => 'php-ext',
95+
],
96+
]);
97+
98+
$repoManager = new RepositoryManager(
99+
$this->createMock(IOInterface::class),
100+
$this->createMock(Config::class),
101+
$this->createMock(HttpDownloader::class),
102+
null,
103+
null,
104+
);
105+
$repoManager->addRepository($repository);
106+
107+
$composer = $this->createMock(Composer::class);
108+
$composer->method('getRepositoryManager')->willReturn($repoManager);
109+
110+
self::assertSame(
111+
[
112+
[
113+
'name' => 'foo/bar',
114+
'description' => 'The best extension there is',
115+
'type' => 'php-ext',
116+
],
117+
],
118+
(new FindMatchingPackages())->byProvider($composer, ExtensionName::normaliseFromString('bar')),
119+
);
120+
}
72121
}

0 commit comments

Comments
 (0)