1010use Composer \Package \CompletePackage ;
1111use Composer \Package \Link ;
1212use Composer \Semver \Constraint \Constraint ;
13+ use Composer \Semver \VersionParser ;
1314use Php \Pie \DependencyResolver \FetchDependencyStatuses ;
15+ use Php \Pie \Platform \Architecture ;
16+ use Php \Pie \Platform \OperatingSystem ;
17+ use Php \Pie \Platform \OperatingSystemFamily ;
1418use Php \Pie \Platform \TargetPhp \PhpBinaryPath ;
1519use Php \Pie \Platform \TargetPlatform ;
1620use PHPUnit \Framework \Attributes \CoversClass ;
21+ use PHPUnit \Framework \Attributes \DataProvider ;
1722use PHPUnit \Framework \TestCase ;
1823
24+ use function assert ;
25+
26+ use const PHP_MAJOR_VERSION ;
27+ use const PHP_MINOR_VERSION ;
28+ use const PHP_RELEASE_VERSION ;
29+ use const PHP_VERSION ;
30+
1931#[CoversClass(FetchDependencyStatuses::class)]
2032final class FetchDependencyStatusesTest extends TestCase
2133{
@@ -26,15 +38,44 @@ public function testNoRequiresReturnsEmptyArray(): void
2638 self ::assertEquals ([], (new FetchDependencyStatuses ())(TargetPlatform::fromPhpBinaryPath (PhpBinaryPath::fromCurrentProcess (), null , null ), $ this ->createMock (Composer::class), $ package ));
2739 }
2840
29- public function testRequiresReturnsListOfStatuses (): void
41+ /** @return array<non-empty-string, array{0: non-empty-string, 1: non-empty-string}> */
42+ public function phpVersionProvider (): array
43+ {
44+ return [
45+ '8.2.0 ' => ['8.2.0 ' , '8.2.0 ' ],
46+ '8.2.0-dev ' => ['8.2.0 ' , '8.2.0-dev ' ],
47+ '8.2.0-alpha ' => ['8.2.0 ' , '8.2.0-alpha ' ],
48+ '8.2.0-RC1 ' => ['8.2.0 ' , '8.2.0-RC1 ' ],
49+ PHP_VERSION => [PHP_MAJOR_VERSION . '. ' . PHP_MINOR_VERSION . '. ' . PHP_RELEASE_VERSION , PHP_VERSION ],
50+ ];
51+ }
52+
53+ #[DataProvider('phpVersionProvider ' )]
54+ public function testRequiresReturnsListOfStatuses (string $ version , string $ versionWithExtra ): void
3055 {
31- $ php = PhpBinaryPath::fromCurrentProcess ();
56+ $ php = $ this ->createMock (PhpBinaryPath::class);
57+ $ php ->method ('operatingSystem ' )->willReturn (OperatingSystem::NonWindows);
58+ $ php ->method ('operatingSystemFamily ' )->willReturn (OperatingSystemFamily::Linux);
59+ $ php ->method ('machineType ' )->willReturn (Architecture::x86_64);
60+ $ php ->expects (self ::any ())
61+ ->method ('version ' )
62+ ->willReturn ($ version );
63+ $ php ->expects (self ::any ())
64+ ->method ('phpVersionWithExtra ' )
65+ ->willReturn ($ versionWithExtra );
66+ $ php ->expects (self ::any ())
67+ ->method ('extensions ' )
68+ ->willReturn (['Core ' => $ versionWithExtra , 'standard ' => $ versionWithExtra ]);
69+
70+ $ versionParser = new VersionParser ();
71+ $ parsedPhpVersion = $ versionParser ->parseConstraints ($ php ->phpVersionWithExtra ());
72+ assert ($ parsedPhpVersion instanceof Constraint);
3273
3374 $ package = new CompletePackage ('vendor/foo ' , '1.2.3.0 ' , '1.2.3 ' );
3475 $ package ->setRequires ([
35- 'ext-core ' => new Link ('__root__ ' , 'ext-core ' , new Constraint ('= ' , $ php ->version () . ' .0 ' )),
36- 'ext-nonsense_extension ' => new Link ('__root__ ' , 'ext-nonsense_extension ' , new Constraint ( ' = ' , '* ' )),
37- 'ext-standard ' => new Link ('__root__ ' , 'ext-standard ' , new Constraint ('< ' , ' 1.0 .0.0 ' )),
76+ 'ext-core ' => new Link ('__root__ ' , 'ext-core ' , $ versionParser -> parseConstraints ('= ' . $ php ->phpVersionWithExtra () )),
77+ 'ext-nonsense_extension ' => new Link ('__root__ ' , 'ext-nonsense_extension ' , $ versionParser -> parseConstraints ( '* ' )),
78+ 'ext-standard ' => new Link ('__root__ ' , 'ext-standard ' , $ versionParser -> parseConstraints ('< 1 .0.0 ' )),
3879 ]);
3980
4081 $ deps = (new FetchDependencyStatuses ())(
@@ -45,8 +86,8 @@ public function testRequiresReturnsListOfStatuses(): void
4586
4687 self ::assertCount (3 , $ deps );
4788
48- self ::assertSame ('ext-core: == ' . $ php ->version () . '.0 ✅ ' , $ deps [0 ]->asPrettyString ());
49- self ::assertSame ('ext-nonsense_extension: == * 🚫 (not installed) ' , $ deps [1 ]->asPrettyString ());
50- self ::assertSame ('ext-standard: < 1.0.0.0 🚫 (your version is ' . $ php -> version () . '.0 ) ' , $ deps [2 ]->asPrettyString ());
89+ self ::assertSame ('ext-core: = ' . $ php ->phpVersionWithExtra () . ' ✅ ' , $ deps [0 ]->asPrettyString ());
90+ self ::assertSame ('ext-nonsense_extension: * 🚫 (not installed) ' , $ deps [1 ]->asPrettyString ());
91+ self ::assertSame ('ext-standard: < 1.0.0 🚫 (your version is ' . $ parsedPhpVersion -> getVersion () . ') ' , $ deps [2 ]->asPrettyString ());
5192 }
5293}
0 commit comments