From 87ac2634b3fe625684b695fca3d3218429940a17 Mon Sep 17 00:00:00 2001 From: Coen Jacobs Date: Sat, 7 Sep 2024 14:58:58 +0200 Subject: [PATCH] Test to verify excluded package classes aren't rewritten in included packages --- tests/Integration/ExcludedPackagesTest.php | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/Integration/ExcludedPackagesTest.php b/tests/Integration/ExcludedPackagesTest.php index d2a09d49..646f5dba 100644 --- a/tests/Integration/ExcludedPackagesTest.php +++ b/tests/Integration/ExcludedPackagesTest.php @@ -21,6 +21,13 @@ public function setUp(): void } /** + * Verifies that the explicitely excluded packages from the Mozart config + * are _not_ being moved to the provided dependency directory and the files + * will stay present in the vendor directory. At the same time, the other + * package is being moved to the dependency directory and after that the + * originating directory in the vendor directory is deleted (as the + * `delete_vendor_directories` parameter is set to `true`). + * * @test */ #[Test] @@ -39,6 +46,7 @@ public function it_excludes_moving_specified_packages(): void $result = $mozartCompose->run($inputInterfaceMock, $outputInterfaceMock); $this->assertEquals(0, $result); + $this->assertDirectoryDoesNotExist($this->testsWorkingDir . '/vendor/pimple/pimple'); $this->assertDirectoryExists($this->testsWorkingDir . '/src/dependencies/Pimple'); @@ -46,6 +54,37 @@ public function it_excludes_moving_specified_packages(): void $this->assertDirectoryDoesNotExist($this->testsWorkingDir . '/src/dependencies/Psr'); } + /** + * Verifies that the excluded package `psr/container` is _not_ having its + * classes replaced in the implementing `pimple/pimple` package when the + * former is explicitely excluded and the latter is added to the list of + * packages for Mozart to rewrite. + * + * @test + */ + #[Test] + public function it_excludes_replacing_classes_from_specified_packages(): void + { + copy(__DIR__ . '/excluded-packages.json', $this->testsWorkingDir . '/composer.json'); + + chdir($this->testsWorkingDir); + + exec('composer update'); + + $inputInterfaceMock = $this->createMock(InputInterface::class); + $outputInterfaceMock = $this->createMock(OutputInterface::class); + + $mozartCompose = new Compose(); + + $result = $mozartCompose->run($inputInterfaceMock, $outputInterfaceMock); + $this->assertEquals(0, $result); + + $testFile = file_get_contents($this->testsWorkingDir . '/src/dependencies/Pimple/Psr11/Container.php'); + $this->assertStringContainsString('namespace Mozart\TestProject\Dependencies\Pimple\Psr11;', $testFile); + $this->assertStringContainsString('use Mozart\TestProject\Dependencies\Pimple\Container as PimpleContainer;', $testFile); + $this->assertStringContainsString('use Psr\Container\ContainerInterface;', $testFile); + } + public function tearDown(): void { parent::tearDown();