mirror of
https://github.com/php/pie.git
synced 2026-03-23 23:12:17 +01:00
535: Add more robust testing for testRequiresReturnsListOfStatuses
This commit is contained in:
@@ -10,12 +10,24 @@ use Composer\IO\IOInterface;
|
||||
use Composer\Package\CompletePackage;
|
||||
use Composer\Package\Link;
|
||||
use Composer\Semver\Constraint\Constraint;
|
||||
use Composer\Semver\VersionParser;
|
||||
use Php\Pie\DependencyResolver\FetchDependencyStatuses;
|
||||
use Php\Pie\Platform\Architecture;
|
||||
use Php\Pie\Platform\OperatingSystem;
|
||||
use Php\Pie\Platform\OperatingSystemFamily;
|
||||
use Php\Pie\Platform\TargetPhp\PhpBinaryPath;
|
||||
use Php\Pie\Platform\TargetPlatform;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
use function assert;
|
||||
|
||||
use const PHP_MAJOR_VERSION;
|
||||
use const PHP_MINOR_VERSION;
|
||||
use const PHP_RELEASE_VERSION;
|
||||
use const PHP_VERSION;
|
||||
|
||||
#[CoversClass(FetchDependencyStatuses::class)]
|
||||
final class FetchDependencyStatusesTest extends TestCase
|
||||
{
|
||||
@@ -26,15 +38,44 @@ final class FetchDependencyStatusesTest extends TestCase
|
||||
self::assertEquals([], (new FetchDependencyStatuses())(TargetPlatform::fromPhpBinaryPath(PhpBinaryPath::fromCurrentProcess(), null, null), $this->createMock(Composer::class), $package));
|
||||
}
|
||||
|
||||
public function testRequiresReturnsListOfStatuses(): void
|
||||
/** @return array<non-empty-string, array{0: non-empty-string, 1: non-empty-string}> */
|
||||
public function phpVersionProvider(): array
|
||||
{
|
||||
$php = PhpBinaryPath::fromCurrentProcess();
|
||||
return [
|
||||
'8.2.0' => ['8.2.0', '8.2.0'],
|
||||
'8.2.0-dev' => ['8.2.0', '8.2.0-dev'],
|
||||
'8.2.0-alpha' => ['8.2.0', '8.2.0-alpha'],
|
||||
'8.2.0-RC1' => ['8.2.0', '8.2.0-RC1'],
|
||||
PHP_VERSION => [PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION, PHP_VERSION],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider('phpVersionProvider')]
|
||||
public function testRequiresReturnsListOfStatuses(string $version, string $versionWithExtra): void
|
||||
{
|
||||
$php = $this->createMock(PhpBinaryPath::class);
|
||||
$php->method('operatingSystem')->willReturn(OperatingSystem::NonWindows);
|
||||
$php->method('operatingSystemFamily')->willReturn(OperatingSystemFamily::Linux);
|
||||
$php->method('machineType')->willReturn(Architecture::x86_64);
|
||||
$php->expects(self::any())
|
||||
->method('version')
|
||||
->willReturn($version);
|
||||
$php->expects(self::any())
|
||||
->method('phpVersionWithExtra')
|
||||
->willReturn($versionWithExtra);
|
||||
$php->expects(self::any())
|
||||
->method('extensions')
|
||||
->willReturn(['Core' => $versionWithExtra, 'standard' => $versionWithExtra]);
|
||||
|
||||
$versionParser = new VersionParser();
|
||||
$parsedPhpVersion = $versionParser->parseConstraints($php->phpVersionWithExtra());
|
||||
assert($parsedPhpVersion instanceof Constraint);
|
||||
|
||||
$package = new CompletePackage('vendor/foo', '1.2.3.0', '1.2.3');
|
||||
$package->setRequires([
|
||||
'ext-core' => new Link('__root__', 'ext-core', new Constraint('=', $php->version() . '.0')),
|
||||
'ext-nonsense_extension' => new Link('__root__', 'ext-nonsense_extension', new Constraint('=', '*')),
|
||||
'ext-standard' => new Link('__root__', 'ext-standard', new Constraint('<', '1.0.0.0')),
|
||||
'ext-core' => new Link('__root__', 'ext-core', $versionParser->parseConstraints('= ' . $php->phpVersionWithExtra())),
|
||||
'ext-nonsense_extension' => new Link('__root__', 'ext-nonsense_extension', $versionParser->parseConstraints('*')),
|
||||
'ext-standard' => new Link('__root__', 'ext-standard', $versionParser->parseConstraints('< 1.0.0')),
|
||||
]);
|
||||
|
||||
$deps = (new FetchDependencyStatuses())(
|
||||
@@ -45,8 +86,8 @@ final class FetchDependencyStatusesTest extends TestCase
|
||||
|
||||
self::assertCount(3, $deps);
|
||||
|
||||
self::assertSame('ext-core: == ' . $php->version() . '.0 ✅', $deps[0]->asPrettyString());
|
||||
self::assertSame('ext-nonsense_extension: == * 🚫 (not installed)', $deps[1]->asPrettyString());
|
||||
self::assertSame('ext-standard: < 1.0.0.0 🚫 (your version is ' . $php->version() . '.0)', $deps[2]->asPrettyString());
|
||||
self::assertSame('ext-core: = ' . $php->phpVersionWithExtra() . ' ✅', $deps[0]->asPrettyString());
|
||||
self::assertSame('ext-nonsense_extension: * 🚫 (not installed)', $deps[1]->asPrettyString());
|
||||
self::assertSame('ext-standard: < 1.0.0 🚫 (your version is ' . $parsedPhpVersion->getVersion() . ')', $deps[2]->asPrettyString());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user