Skip to content

Commit

Permalink
Test to verify excluded package classes aren't rewritten in included …
Browse files Browse the repository at this point in the history
…packages
  • Loading branch information
coenjacobs committed Sep 7, 2024
1 parent 59f1f69 commit 87ac263
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/Integration/ExcludedPackagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -39,13 +46,45 @@ 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');

$this->assertDirectoryExists($this->testsWorkingDir . '/vendor/psr/container');
$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();
Expand Down

0 comments on commit 87ac263

Please sign in to comment.