|
7 | 7 | use Composer\Composer; |
8 | 8 | use Composer\IO\NullIO; |
9 | 9 | use Composer\Package\CompletePackage; |
| 10 | +use Composer\Package\Link; |
10 | 11 | use Composer\Repository\ArrayRepository; |
11 | 12 | use Composer\Repository\CompositeRepository; |
| 13 | +use Composer\Repository\InstalledRepositoryInterface; |
12 | 14 | use Composer\Repository\RepositoryFactory; |
13 | 15 | use Composer\Repository\RepositoryManager; |
| 16 | +use Composer\Semver\Constraint\Constraint; |
14 | 17 | use Php\Pie\ComposerIntegration\QuieterConsoleIO; |
15 | 18 | use Php\Pie\DependencyResolver\IncompatibleOperatingSystemFamily; |
16 | 19 | use Php\Pie\DependencyResolver\IncompatibleThreadSafetyMode; |
|
25 | 28 | use Php\Pie\Platform\ThreadSafetyMode; |
26 | 29 | use PHPUnit\Framework\Attributes\CoversClass; |
27 | 30 | use PHPUnit\Framework\Attributes\DataProvider; |
| 31 | +use PHPUnit\Framework\MockObject\MockObject; |
28 | 32 | use PHPUnit\Framework\TestCase; |
29 | 33 |
|
30 | 34 | #[CoversClass(ResolveDependencyWithComposer::class)] |
31 | 35 | final class ResolveDependencyWithComposerTest extends TestCase |
32 | 36 | { |
33 | 37 | private Composer $composer; |
34 | 38 |
|
| 39 | + private InstalledRepositoryInterface&MockObject $localRepo; |
| 40 | + |
35 | 41 | public function setUp(): void |
36 | 42 | { |
37 | 43 | parent::setUp(); |
38 | 44 |
|
| 45 | + $packageWithReplaces = new CompletePackage('already/installed2', '1.2.3.0', '1.2.3'); |
| 46 | + $packageWithReplaces->setReplaces([ |
| 47 | + 'ext-installed2' => new Link('root/package', 'ext-installed2', new Constraint('==', '*')), |
| 48 | + ]); |
| 49 | + $this->localRepo = $this->createMock(InstalledRepositoryInterface::class); |
| 50 | + $this->localRepo->method('getPackages')->willReturn([ |
| 51 | + new CompletePackage('already/installed1', '1.2.3.0', '1.2.3'), |
| 52 | + $packageWithReplaces, |
| 53 | + ]); |
| 54 | + |
39 | 55 | $repoManager = $this->createMock(RepositoryManager::class); |
40 | 56 | $repoManager->method('getRepositories') |
41 | 57 | ->willReturn([new CompositeRepository(RepositoryFactory::defaultReposWithDefaultManager(new NullIO()))]); |
| 58 | + $repoManager->method('getLocalRepository')->willReturn($this->localRepo); |
42 | 59 |
|
43 | 60 | $this->composer = $this->createMock(Composer::class); |
44 | 61 | $this->composer->method('getRepositoryManager') |
@@ -175,6 +192,7 @@ public function testZtsOnlyPackageCannotBeInstalledOnNtsSystem(): void |
175 | 192 | $repoManager = $this->createMock(RepositoryManager::class); |
176 | 193 | $repoManager->method('getRepositories') |
177 | 194 | ->willReturn([new ArrayRepository([$pkg])]); |
| 195 | + $repoManager->method('getLocalRepository')->willReturn($this->localRepo); |
178 | 196 |
|
179 | 197 | $this->composer = $this->createMock(Composer::class); |
180 | 198 | $this->composer->method('getRepositoryManager') |
@@ -222,6 +240,7 @@ public function testNtsOnlyPackageCannotBeInstalledOnZtsSystem(): void |
222 | 240 | $repoManager = $this->createMock(RepositoryManager::class); |
223 | 241 | $repoManager->method('getRepositories') |
224 | 242 | ->willReturn([new ArrayRepository([$pkg])]); |
| 243 | + $repoManager->method('getLocalRepository')->willReturn($this->localRepo); |
225 | 244 |
|
226 | 245 | $this->composer = $this->createMock(Composer::class); |
227 | 246 | $this->composer->method('getRepositoryManager') |
@@ -269,6 +288,7 @@ public function testExtensionCanOnlyBeInstalledIfOsFamilyIsCompatible(): void |
269 | 288 | $repoManager = $this->createMock(RepositoryManager::class); |
270 | 289 | $repoManager->method('getRepositories') |
271 | 290 | ->willReturn([new ArrayRepository([$pkg])]); |
| 291 | + $repoManager->method('getLocalRepository')->willReturn($this->localRepo); |
272 | 292 |
|
273 | 293 | $this->composer = $this->createMock(Composer::class); |
274 | 294 | $this->composer->method('getRepositoryManager') |
@@ -316,6 +336,7 @@ public function testExtensionCanOnlyBeInstalledIfOsFamilyIsNotInCompatible(): vo |
316 | 336 | $repoManager = $this->createMock(RepositoryManager::class); |
317 | 337 | $repoManager->method('getRepositories') |
318 | 338 | ->willReturn([new ArrayRepository([$pkg])]); |
| 339 | + $repoManager->method('getLocalRepository')->willReturn($this->localRepo); |
319 | 340 |
|
320 | 341 | $this->composer = $this->createMock(Composer::class); |
321 | 342 | $this->composer->method('getRepositoryManager') |
@@ -350,4 +371,35 @@ public function testExtensionCanOnlyBeInstalledIfOsFamilyIsNotInCompatible(): vo |
350 | 371 | false, |
351 | 372 | ); |
352 | 373 | } |
| 374 | + |
| 375 | + public function testPackageThatCanBeResolvedWithReplaceConflict(): void |
| 376 | + { |
| 377 | + $phpBinaryPath = $this->createMock(PhpBinaryPath::class); |
| 378 | + $phpBinaryPath->expects(self::any()) |
| 379 | + ->method('version') |
| 380 | + ->willReturn('8.3.0'); |
| 381 | + $phpBinaryPath->expects(self::any()) |
| 382 | + ->method('extensions') |
| 383 | + ->willReturn([ |
| 384 | + 'installed1' => '1.2.3', |
| 385 | + 'installed2' => '1.2.3', |
| 386 | + ]); |
| 387 | + |
| 388 | + $targetPlatform = new TargetPlatform( |
| 389 | + OperatingSystem::NonWindows, |
| 390 | + OperatingSystemFamily::Linux, |
| 391 | + $phpBinaryPath, |
| 392 | + Architecture::x86_64, |
| 393 | + ThreadSafetyMode::ThreadSafe, |
| 394 | + 1, |
| 395 | + null, |
| 396 | + ); |
| 397 | + |
| 398 | + $package = (new ResolveDependencyWithComposer( |
| 399 | + $this->createMock(QuieterConsoleIO::class), |
| 400 | + ))($this->composer, $targetPlatform, new RequestedPackageAndVersion('asgrim/example-pie-extension', '^1.0'), false); |
| 401 | + |
| 402 | + self::assertSame('asgrim/example-pie-extension', $package->name()); |
| 403 | + self::assertStringStartsWith('1.', $package->version()); |
| 404 | + } |
353 | 405 | } |
0 commit comments