|
12 | 12 | use Composer\Repository\ArrayRepository; |
13 | 13 | use Composer\Repository\RepositoryManager; |
14 | 14 | use Composer\Util\HttpDownloader; |
| 15 | +use Php\Pie\ExtensionName; |
15 | 16 | use Php\Pie\ExtensionType; |
16 | 17 | use Php\Pie\Installing\InstallForPhpProject\FindMatchingPackages; |
17 | 18 | use PHPUnit\Framework\Attributes\CoversClass; |
@@ -69,4 +70,52 @@ public function testSearchResultsAreFilteredByExtensionName(): void |
69 | 70 | (new FindMatchingPackages())->bySearching($composer, 'bar'), |
70 | 71 | ); |
71 | 72 | } |
| 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 | + } |
72 | 121 | } |
0 commit comments