Skip to content

Commit

Permalink
added integration test ensuring the existence of the orignal symlink
Browse files Browse the repository at this point in the history
  • Loading branch information
doekenorg committed Feb 1, 2024
1 parent 8c6e0a0 commit 5d13c77
Showing 1 changed file with 127 additions and 0 deletions.
127 changes: 127 additions & 0 deletions tests/Integration/CleanupSymlinkIntegrationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php

namespace BrianHenryIE\Strauss\Tests\Integration;

use BrianHenryIE\Strauss\Console\Commands\Compose;
use BrianHenryIE\Strauss\Tests\Integration\Util\IntegrationTestCase;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

final class CleanupSymlinkIntegrationTest extends IntegrationTestCase
{
/**
* Test case that ensures a symlinked package is not removed or cleared out by the strauss command.
*/
public function testEnsureNoRemovalOfSymlinks(): void
{
$paths = [
$main_package_dir = $this->testsWorkingDir . '/main-package',
$symlinked_package_dir = $this->testsWorkingDir . '/symlinked-package',
];

$this->removePaths($paths);

mkdir($main_package_dir);
mkdir($symlinked_package_dir . '/src/', 0777, true);

file_put_contents($main_package_dir . '/composer.json', $this->packageComposerFile());
file_put_contents($symlinked_package_dir . '/composer.json', $this->symlinkedComposerFile());
file_put_contents($symlinked_package_dir . '/src/File.php', $this->symlinkedPhpFile());

chdir($main_package_dir);
exec('composer install');

$inputInterfaceMock = $this->createMock(InputInterface::class);
$outputInterfaceMock = $this->createMock(OutputInterface::class);

$relative_symlinked_package_dir = $main_package_dir . '/vendor/strauss-test/symlinked-package';
try {
self::assertDirectoryExists($relative_symlinked_package_dir);
$strauss = new Compose();

$strauss->run($inputInterfaceMock, $outputInterfaceMock);

self::assertDirectoryExists($symlinked_package_dir);
self::assertFileExists($symlinked_package_dir . '/composer.json');
self::assertFileExists($symlinked_package_dir . '/src/File.php');

self::assertDirectoryDoesNotExist($relative_symlinked_package_dir);
self::assertFileExists(
$file = $main_package_dir . '/vendor_prefixed/strauss-test/symlinked-package/src/File.php'
);
self::assertStringContainsString('Prefixed\\Internal\\Package', file_get_contents($file) ?: '');
} finally {
$this->removePaths($paths);
}
}

/**
* Clean up after the tests.
* @param string[] $paths
*/
private function removePaths(array $paths): void
{
foreach ($paths as $path) {
if (!is_dir($path)) {
continue;
}
exec("rm -rf " . $path);
}
}

private function packageComposerFile(): string
{
return <<<JSON
{
"repositories": [
{
"type": "path",
"url": "../symlinked-package",
"options": {
"symlink": true
}
}
],
"name": "strauss-test/main-package",
"require": {
"strauss-test/symlinked-package": "@dev"
},
"extra": {
"strauss": {
"target_directory": "vendor_prefixed",
"namespace_prefix": "Prefixed\\\\",
"classmap_prefix": "Prefixed_",
"delete_vendor_packages": true
}
}
}
JSON;
}

private function symlinkedComposerFile(): string
{
return <<<JSON
{
"name": "strauss-test/symlinked-package",
"autoload": {
"psr-4": {
"Internal\\\\Package\\\\": "src/"
}
}
}
JSON;
}

private function symlinkedPhpFile(): string
{
return <<<PHP
<?php
namespace Internal\Package;
final class File {
}
PHP;
}
}

0 comments on commit 5d13c77

Please sign in to comment.