From f6ff7cf9b9efc8bb4c1089d9a50a0215ef5299e0 Mon Sep 17 00:00:00 2001 From: Jerry Radwick Date: Mon, 23 Dec 2024 18:03:06 -0500 Subject: [PATCH] Create test for symlink package See https://github.com/webflo/drupal-finder/issues/74 --- .gitignore | 4 +- composer.json | 11 +++-- tests/DrupalFinderComposerRuntimeTest.php | 26 +++++++++++ .../symlink-package/drupal/composer.json | 44 +++++++++++++++++++ .../symlink-package/package/composer.json | 17 +++++++ .../symlink-package/package/symlink-package | 14 ++++++ 6 files changed, 112 insertions(+), 4 deletions(-) create mode 100644 tests/fixtures/symlink-package/drupal/composer.json create mode 100644 tests/fixtures/symlink-package/package/composer.json create mode 100755 tests/fixtures/symlink-package/package/symlink-package diff --git a/.gitignore b/.gitignore index 4ece3d5..94fc9aa 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ /tests/fixtures/custom-vendor/foo /tests/fixtures/default/web /tests/fixtures/default/vendor -/tests/fixtures/*/composer.lock +/tests/fixtures/**/composer.lock +/tests/fixtures/symlink-package/drupal/* +/tests/fixtures/symlink-package/package/vendor diff --git a/composer.json b/composer.json index b6a2015..425364e 100644 --- a/composer.json +++ b/composer.json @@ -36,13 +36,18 @@ "scripts": { "install-fixtures": [ "cd tests/fixtures/custom-vendor && composer install", - "cd tests/fixtures/default && composer install" + "cd tests/fixtures/default && composer install", + "cd tests/fixtures/symlink-package/drupal && composer install", + "cd tests/fixtures/symlink-package/package && composer install" ], "uninstall-fixtures": [ - "rm -rf tests/fixtures/*/composer.lock", + "rm -rf tests/fixtures/**/composer.lock", "rm -rf tests/fixtures/custom-vendor/foo", "rm -rf tests/fixtures/default/web", - "rm -rf tests/fixtures/default/vendor" + "rm -rf tests/fixtures/default/vendor", + "rm -rf tests/fixtures/symlink-package/drupal/web", + "rm -rf tests/fixtures/symlink-package/drupal/vendor", + "rm -rf tests/fixtures/symlink-package/package/vendor" ], "reinstall-fixtures": [ "@uninstall-fixtures", diff --git a/tests/DrupalFinderComposerRuntimeTest.php b/tests/DrupalFinderComposerRuntimeTest.php index 59d0599..b46ae98 100644 --- a/tests/DrupalFinderComposerRuntimeTest.php +++ b/tests/DrupalFinderComposerRuntimeTest.php @@ -60,4 +60,30 @@ public function testCustomVendor() { $this->assertSame($result['getDrupalRoot'], $basePath . '/foo/bar/drupal'); } + /** + * @runInSeparateProcess + */ + public function testSymlinkPackage() { + $drupalPath = realpath(__DIR__ . '/fixtures/symlink-package/drupal'); + $this->assertDirectoryExists("$drupalPath/vendor", static::installFixtures); + $this->assertDirectoryExists("$drupalPath/web", static::installFixtures); + + $packagePath = realpath(__DIR__ . '/fixtures/symlink-package/package'); + $this->assertDirectoryExists("$packagePath/vendor", static::installFixtures); + + $process = new Process(['composer', 'exec', 'symlink-package'], $drupalPath); + $process->run(); + + // executes after the command finishes + if (!$process->isSuccessful()) { + throw new ProcessFailedException($process); + } + + $result = json_decode($process->getOutput(), TRUE); + var_dump($result); +// $this->assertSame($result['getComposerRoot'], $drupalPath); +// $this->assertSame($result['getVendorDir'], $drupalPath . '/vendor'); +// $this->assertSame($result['getDrupalRoot'], $drupalPath . '/web'); + } + } diff --git a/tests/fixtures/symlink-package/drupal/composer.json b/tests/fixtures/symlink-package/drupal/composer.json new file mode 100644 index 0000000..22cf815 --- /dev/null +++ b/tests/fixtures/symlink-package/drupal/composer.json @@ -0,0 +1,44 @@ +{ + "description": "A Drupal project that refers to the local package 'webflo/foo'.", + "type": "project", + "license": "GPL-2.0-or-later", + "repositories": { + "drupal": { + "type": "composer", + "url": "https://packages.drupal.org/8" + }, + "drupal-finder": { + "type": "path", + "url": "../../../" + }, + "symlink-package": { + "type": "path", + "url": "../package", + "options": { + "symlink": true + } + } + }, + "require": { + "composer/installers": "^2.0", + "drupal/core": "^10", + "webflo/foo": "*" + }, + "conflict": { + "drupal/drupal": "*" + }, + "minimum-stability": "dev", + "prefer-stable": true, + "config": { + "allow-plugins": { + "composer/installers": true + } + }, + "extra": { + "installer-paths": { + "web/core": [ + "type:drupal-core" + ] + } + } +} diff --git a/tests/fixtures/symlink-package/package/composer.json b/tests/fixtures/symlink-package/package/composer.json new file mode 100644 index 0000000..5ced5f2 --- /dev/null +++ b/tests/fixtures/symlink-package/package/composer.json @@ -0,0 +1,17 @@ +{ + "name": "webflo/foo", + "description": "The package that depends on Drupal Finder.", + "repositories": { + "drupal-finder": { + "type": "path", + "url": "../../../" + } + }, + "require": { + "webflo/drupal-finder": "*" + }, + "bin": [ + "symlink-package" + ], + "minimum-stability": "dev" +} diff --git a/tests/fixtures/symlink-package/package/symlink-package b/tests/fixtures/symlink-package/package/symlink-package new file mode 100755 index 0000000..92f8b1d --- /dev/null +++ b/tests/fixtures/symlink-package/package/symlink-package @@ -0,0 +1,14 @@ +#!/usr/bin/env php + $finder->getComposerRoot(), + 'getVendorDir' => $finder->getVendorDir(), + 'getDrupalRoot' => $finder->getDrupalRoot(), +]);