|
15 | 15 | use Composer\Repository\RepositoryFactory; |
16 | 16 | use Composer\Repository\RepositoryManager; |
17 | 17 | use Composer\Semver\Constraint\Constraint; |
| 18 | +use Php\Pie\ComposerIntegration\BundledPhpExtensionsRepository; |
18 | 19 | use Php\Pie\ComposerIntegration\QuieterConsoleIO; |
| 20 | +use Php\Pie\DependencyResolver\BundledPhpExtensionRefusal; |
19 | 21 | use Php\Pie\DependencyResolver\IncompatibleOperatingSystemFamily; |
20 | 22 | use Php\Pie\DependencyResolver\IncompatibleThreadSafetyMode; |
21 | 23 | use Php\Pie\DependencyResolver\RequestedPackageAndVersion; |
22 | 24 | use Php\Pie\DependencyResolver\ResolveDependencyWithComposer; |
23 | 25 | use Php\Pie\DependencyResolver\UnableToResolveRequirement; |
| 26 | +use Php\Pie\ExtensionType; |
24 | 27 | use Php\Pie\Platform\Architecture; |
25 | 28 | use Php\Pie\Platform\OperatingSystem; |
26 | 29 | use Php\Pie\Platform\OperatingSystemFamily; |
@@ -49,13 +52,21 @@ public function setUp(): void |
49 | 52 | ]); |
50 | 53 | $this->localRepo = $this->createMock(InstalledRepositoryInterface::class); |
51 | 54 | $this->localRepo->method('getPackages')->willReturn([ |
52 | | - new CompletePackage('already/installed1', '1.2.3.0', '1.2.3'), |
| 55 | + new CompletePackage('a/installed1', '1.2.3.0', '1.2.3'), |
53 | 56 | $packageWithReplaces, |
54 | 57 | ]); |
55 | 58 |
|
| 59 | + $bundledPhpPackage = new CompletePackage('php/bundled', '8.3.0', '8.3.0.0'); |
| 60 | + $bundledPhpPackage->setType(ExtensionType::PhpModule->value); |
| 61 | + |
56 | 62 | $repoManager = $this->createMock(RepositoryManager::class); |
57 | 63 | $repoManager->method('getRepositories') |
58 | | - ->willReturn([new CompositeRepository(RepositoryFactory::defaultReposWithDefaultManager(new NullIO()))]); |
| 64 | + ->willReturn([ |
| 65 | + new CompositeRepository([ |
| 66 | + ...RepositoryFactory::defaultReposWithDefaultManager(new NullIO()), |
| 67 | + new BundledPhpExtensionsRepository([$bundledPhpPackage]), |
| 68 | + ]), |
| 69 | + ]); |
59 | 70 | $repoManager->method('getLocalRepository')->willReturn($this->localRepo); |
60 | 71 |
|
61 | 72 | $this->composer = $this->createMock(Composer::class); |
@@ -415,4 +426,119 @@ public function testPackageThatCanBeResolvedWithReplaceConflict(): void |
415 | 426 | self::assertSame('asgrim/example-pie-extension', $package->name()); |
416 | 427 | self::assertStringStartsWith('1.', $package->version()); |
417 | 428 | } |
| 429 | + |
| 430 | + public function testBundledExtensionCannotBeInstalledOnDevPhpVersion(): void |
| 431 | + { |
| 432 | + $phpBinaryPath = $this->createMock(PhpBinaryPath::class); |
| 433 | + $phpBinaryPath->expects(self::any()) |
| 434 | + ->method('version') |
| 435 | + ->willReturn('8.3.0'); |
| 436 | + $phpBinaryPath->expects(self::any()) |
| 437 | + ->method('phpVersionWithExtra') |
| 438 | + ->willReturn('8.3.0-dev'); |
| 439 | + |
| 440 | + $targetPlatform = new TargetPlatform( |
| 441 | + OperatingSystem::NonWindows, |
| 442 | + OperatingSystemFamily::Linux, |
| 443 | + $phpBinaryPath, |
| 444 | + Architecture::x86_64, |
| 445 | + ThreadSafetyMode::ThreadSafe, |
| 446 | + 1, |
| 447 | + null, |
| 448 | + null, |
| 449 | + ); |
| 450 | + |
| 451 | + $resolver = new ResolveDependencyWithComposer( |
| 452 | + $this->createMock(IOInterface::class), |
| 453 | + $this->createMock(QuieterConsoleIO::class), |
| 454 | + ); |
| 455 | + $requestedPackage = new RequestedPackageAndVersion('php/bundled', null); |
| 456 | + |
| 457 | + $this->expectException(BundledPhpExtensionRefusal::class); |
| 458 | + $this->expectExceptionMessage('Cannot install bundled PHP extension for non-stable versions of PHP'); |
| 459 | + $resolver->__invoke($this->composer, $targetPlatform, $requestedPackage, false); |
| 460 | + } |
| 461 | + |
| 462 | + /** @return array<non-empty-string, array{0: non-empty-string}> */ |
| 463 | + public function buildProvidersWithBundledExtensionWarnings(): array |
| 464 | + { |
| 465 | + return [ |
| 466 | + 'Docker' => ['https://github.com/docker-library/php'], |
| 467 | + 'Debian/Ubuntu' => ['Debian'], |
| 468 | + 'Remi Repo' => ['Remi\'s RPM repository <https://rpms.remirepo.net/> #StandWithUkraine'], |
| 469 | + 'Brew' => ['Homebrew'], |
| 470 | + ]; |
| 471 | + } |
| 472 | + |
| 473 | + #[DataProvider('buildProvidersWithBundledExtensionWarnings')] |
| 474 | + public function testBundledExtensionWillNotInstallOnBuildProviderWithoutForce(string $buildProvider): void |
| 475 | + { |
| 476 | + $phpBinaryPath = $this->createMock(PhpBinaryPath::class); |
| 477 | + $phpBinaryPath->expects(self::any()) |
| 478 | + ->method('version') |
| 479 | + ->willReturn('8.3.0'); |
| 480 | + $phpBinaryPath->expects(self::any()) |
| 481 | + ->method('phpVersionWithExtra') |
| 482 | + ->willReturn('8.3.0'); |
| 483 | + $phpBinaryPath->expects(self::any()) |
| 484 | + ->method('buildProvider') |
| 485 | + ->willReturn($buildProvider); |
| 486 | + |
| 487 | + $targetPlatform = new TargetPlatform( |
| 488 | + OperatingSystem::NonWindows, |
| 489 | + OperatingSystemFamily::Linux, |
| 490 | + $phpBinaryPath, |
| 491 | + Architecture::x86_64, |
| 492 | + ThreadSafetyMode::ThreadSafe, |
| 493 | + 1, |
| 494 | + null, |
| 495 | + null, |
| 496 | + ); |
| 497 | + |
| 498 | + $resolver = new ResolveDependencyWithComposer( |
| 499 | + $this->createMock(IOInterface::class), |
| 500 | + $this->createMock(QuieterConsoleIO::class), |
| 501 | + ); |
| 502 | + $requestedPackage = new RequestedPackageAndVersion('php/bundled', null); |
| 503 | + |
| 504 | + $this->expectException(BundledPhpExtensionRefusal::class); |
| 505 | + $this->expectExceptionMessage('Bundled PHP extension php/bundled should be installed by your distribution, not by PIE'); |
| 506 | + $resolver->__invoke($this->composer, $targetPlatform, $requestedPackage, false); |
| 507 | + } |
| 508 | + |
| 509 | + #[DataProvider('buildProvidersWithBundledExtensionWarnings')] |
| 510 | + public function testBundledExtensionWillInstallOnBuildProviderWithForce(string $buildProvider): void |
| 511 | + { |
| 512 | + $phpBinaryPath = $this->createMock(PhpBinaryPath::class); |
| 513 | + $phpBinaryPath->expects(self::any()) |
| 514 | + ->method('version') |
| 515 | + ->willReturn('8.3.0'); |
| 516 | + $phpBinaryPath->expects(self::any()) |
| 517 | + ->method('phpVersionWithExtra') |
| 518 | + ->willReturn('8.3.0'); |
| 519 | + $phpBinaryPath->expects(self::any()) |
| 520 | + ->method('buildProvider') |
| 521 | + ->willReturn($buildProvider); |
| 522 | + |
| 523 | + $targetPlatform = new TargetPlatform( |
| 524 | + OperatingSystem::NonWindows, |
| 525 | + OperatingSystemFamily::Linux, |
| 526 | + $phpBinaryPath, |
| 527 | + Architecture::x86_64, |
| 528 | + ThreadSafetyMode::ThreadSafe, |
| 529 | + 1, |
| 530 | + null, |
| 531 | + null, |
| 532 | + ); |
| 533 | + |
| 534 | + $resolver = new ResolveDependencyWithComposer( |
| 535 | + $this->createMock(IOInterface::class), |
| 536 | + $this->createMock(QuieterConsoleIO::class), |
| 537 | + ); |
| 538 | + $requestedPackage = new RequestedPackageAndVersion('php/bundled', null); |
| 539 | + |
| 540 | + $package = $resolver->__invoke($this->composer, $targetPlatform, $requestedPackage, true); |
| 541 | + |
| 542 | + self::assertSame('php/bundled', $package->name()); |
| 543 | + } |
418 | 544 | } |
0 commit comments