44
55namespace Php \PieUnitTest \ComposerIntegration ;
66
7+ use Composer \Composer ;
8+ use Composer \Package \CompletePackage ;
9+ use Composer \Package \Link ;
710use Composer \Package \PackageInterface ;
11+ use Composer \Semver \Constraint \Constraint ;
812use Php \Pie \ComposerIntegration \PhpBinaryPathBasedPlatformRepository ;
13+ use Php \Pie \DependencyResolver \Package ;
914use Php \Pie \ExtensionName ;
15+ use Php \Pie \Platform \InstalledPiePackages ;
1016use Php \Pie \Platform \TargetPhp \PhpBinaryPath ;
1117use PHPUnit \Framework \Attributes \CoversClass ;
1218use PHPUnit \Framework \TestCase ;
@@ -18,6 +24,11 @@ final class PhpBinaryPathBasedPlatformRepositoryTest extends TestCase
1824{
1925 public function testPlatformRepositoryContainsExpectedPacakges (): void
2026 {
27+ $ composer = $ this ->createMock (Composer::class);
28+
29+ $ installedPiePackages = $ this ->createMock (InstalledPiePackages::class);
30+ $ installedPiePackages ->method ('allPiePackages ' )->willReturn ([]);
31+
2132 $ phpBinaryPath = $ this ->createMock (PhpBinaryPath::class);
2233 $ phpBinaryPath ->expects (self ::once ())
2334 ->method ('version ' )
@@ -31,7 +42,7 @@ public function testPlatformRepositoryContainsExpectedPacakges(): void
3142 'another ' => '1.2.3-alpha.34 ' ,
3243 ]);
3344
34- $ platformRepository = new PhpBinaryPathBasedPlatformRepository ($ phpBinaryPath , null );
45+ $ platformRepository = new PhpBinaryPathBasedPlatformRepository ($ phpBinaryPath , $ composer , $ installedPiePackages , null );
3546
3647 self ::assertSame (
3748 [
@@ -50,6 +61,11 @@ public function testPlatformRepositoryContainsExpectedPacakges(): void
5061
5162 public function testPlatformRepositoryExcludesExtensionBeingInstalled (): void
5263 {
64+ $ composer = $ this ->createMock (Composer::class);
65+
66+ $ installedPiePackages = $ this ->createMock (InstalledPiePackages::class);
67+ $ installedPiePackages ->method ('allPiePackages ' )->willReturn ([]);
68+
5369 $ extensionBeingInstalled = ExtensionName::normaliseFromString ('extension_being_installed ' );
5470
5571 $ phpBinaryPath = $ this ->createMock (PhpBinaryPath::class);
@@ -63,7 +79,48 @@ public function testPlatformRepositoryExcludesExtensionBeingInstalled(): void
6379 'extension_being_installed ' => '1.2.3 ' ,
6480 ]);
6581
66- $ platformRepository = new PhpBinaryPathBasedPlatformRepository ($ phpBinaryPath , $ extensionBeingInstalled );
82+ $ platformRepository = new PhpBinaryPathBasedPlatformRepository ($ phpBinaryPath , $ composer , $ installedPiePackages , $ extensionBeingInstalled );
83+
84+ self ::assertSame (
85+ [
86+ 'php:8.1.0 ' ,
87+ 'ext-foo:8.1.0 ' ,
88+ ],
89+ array_map (
90+ static fn (PackageInterface $ package ): string => $ package ->getName () . ': ' . $ package ->getPrettyVersion (),
91+ $ platformRepository ->getPackages (),
92+ ),
93+ );
94+ }
95+
96+ public function testPlatformRepositoryExcludesReplacedExtensions (): void
97+ {
98+ $ composer = $ this ->createMock (Composer::class);
99+
100+ $ composerPackage = $ this ->createMock (CompletePackage::class);
101+ $ composerPackage ->method ('getPrettyName ' )->willReturn ('myvendor/extension-with-replaces ' );
102+ $ composerPackage ->method ('getReplaces ' )->willReturn ([
103+ new Link ('myvendor/extension-with-replaces ' , 'ext-replaced_extension ' , new Constraint ('== ' , '* ' )),
104+ ]);
105+ $ installedPiePackages = $ this ->createMock (InstalledPiePackages::class);
106+ $ installedPiePackages ->method ('allPiePackages ' )->willReturn ([
107+ Package::fromComposerCompletePackage ($ composerPackage ),
108+ ]);
109+
110+ $ extensionBeingInstalled = ExtensionName::normaliseFromString ('extension_being_installed ' );
111+
112+ $ phpBinaryPath = $ this ->createMock (PhpBinaryPath::class);
113+ $ phpBinaryPath ->expects (self ::once ())
114+ ->method ('version ' )
115+ ->willReturn ('8.1.0 ' );
116+ $ phpBinaryPath ->expects (self ::once ())
117+ ->method ('extensions ' )
118+ ->willReturn ([
119+ 'foo ' => '8.1.0 ' ,
120+ 'replaced_extension ' => '3.0.0 ' ,
121+ ]);
122+
123+ $ platformRepository = new PhpBinaryPathBasedPlatformRepository ($ phpBinaryPath , $ composer , $ installedPiePackages , $ extensionBeingInstalled );
67124
68125 self ::assertSame (
69126 [
0 commit comments