|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Php\PieUnitTest\Installing\InstallForPhpProject; |
| 6 | + |
| 7 | +use Composer\Composer; |
| 8 | +use Composer\Config; |
| 9 | +use Composer\IO\IOInterface; |
| 10 | +use Composer\Package\CompletePackage; |
| 11 | +use Composer\Repository\ArrayRepository; |
| 12 | +use Composer\Repository\RepositoryManager; |
| 13 | +use Composer\Util\HttpDownloader; |
| 14 | +use Php\Pie\ExtensionType; |
| 15 | +use Php\Pie\Installing\InstallForPhpProject\FindMatchingPackages; |
| 16 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 17 | +use PHPUnit\Framework\TestCase; |
| 18 | + |
| 19 | +#[CoversClass(FindMatchingPackages::class)] |
| 20 | +final class FindMatchingPackagesTest extends TestCase |
| 21 | +{ |
| 22 | + public function testSearchResultsAreFilteredByExtensionName(): void |
| 23 | + { |
| 24 | + $repository = new ArrayRepository([ |
| 25 | + (static function (): CompletePackage { |
| 26 | + $package = new CompletePackage('another/bar', '1.5.0.0', '1.5.0'); |
| 27 | + $package->setDescription('These are not the extensions you are looking for'); |
| 28 | + $package->setType(ExtensionType::PhpModule->value); |
| 29 | + $package->setPhpExt(['extension-name' => 'something_else']); |
| 30 | + |
| 31 | + return $package; |
| 32 | + })(), |
| 33 | + (static function (): CompletePackage { |
| 34 | + $package = new CompletePackage('foo/bar', '1.2.3.0', '1.2.3'); |
| 35 | + $package->setDescription('The best extension there is'); |
| 36 | + $package->setType(ExtensionType::PhpModule->value); |
| 37 | + |
| 38 | + return $package; |
| 39 | + })(), |
| 40 | + (static function (): CompletePackage { |
| 41 | + $package = new CompletePackage('foo/bar', '2.0.0.0', '2.0.0'); |
| 42 | + $package->setDescription('The best extension there is'); |
| 43 | + $package->setType(ExtensionType::PhpModule->value); |
| 44 | + |
| 45 | + return $package; |
| 46 | + })(), |
| 47 | + ]); |
| 48 | + |
| 49 | + $repoManager = new RepositoryManager( |
| 50 | + $this->createMock(IOInterface::class), |
| 51 | + $this->createMock(Config::class), |
| 52 | + $this->createMock(HttpDownloader::class), |
| 53 | + null, |
| 54 | + null, |
| 55 | + ); |
| 56 | + $repoManager->addRepository($repository); |
| 57 | + |
| 58 | + $composer = $this->createMock(Composer::class); |
| 59 | + $composer->method('getRepositoryManager')->willReturn($repoManager); |
| 60 | + |
| 61 | + self::assertSame( |
| 62 | + [ |
| 63 | + [ |
| 64 | + 'name' => 'foo/bar', |
| 65 | + 'description' => 'The best extension there is', |
| 66 | + ], |
| 67 | + ], |
| 68 | + (new FindMatchingPackages())->for($composer, 'bar'), |
| 69 | + ); |
| 70 | + } |
| 71 | +} |
0 commit comments