forked from coenjacobs/mozart
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added integration test ensuring the existence of the orignal symlink
- Loading branch information
Showing
1 changed file
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |