diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 67038561c1da832dcd18e21a0953819ab8041cdc..401c13e337b3b36deb730fd0c66e0c34cca1b9f8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -134,7 +134,9 @@ phpunit: - package_manager TEST_TYPE: - PHPUnit-Unit + - PHPUnit-Kernel variables: + COMPOSER_HOME: '$CI_PROJECT_DIR/.composer' _PHPUNIT_CONCURRENT: '1' _PHPUNIT_EXTRA: '--types $TEST_TYPE --module $MODULE' _PHPUNIT_TESTGROUPS: '--verbose' diff --git a/package_manager/tests/fixtures/fake_site/composer.json b/package_manager/tests/fixtures/fake_site/composer.json index a7f2b4cd69dff7efcf68ea89ce63ac81412e19a6..c67ca797d17e9c19e056f059c39243136a9f3330 100644 --- a/package_manager/tests/fixtures/fake_site/composer.json +++ b/package_manager/tests/fixtures/fake_site/composer.json @@ -20,7 +20,12 @@ "bar": 134, "foo-bar": null }, - "baz": null + "baz": null, + "installer-paths": { + "modules/contrib/{$name}": ["type:drupal-module"], + "profiles/contrib/{$name}": ["type:drupal-profile"], + "themes/contrib/{$name}": ["type:drupal-theme"] + } }, "repositories": { "fake-packages": { diff --git a/package_manager/tests/fixtures/fake_site/composer.lock b/package_manager/tests/fixtures/fake_site/composer.lock index c0a62b3d7336121fb1c5a21f81a070c0db23676b..08a1146dd547de0926997af3f56e071357bb2c39 100644 --- a/package_manager/tests/fixtures/fake_site/composer.lock +++ b/package_manager/tests/fixtures/fake_site/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0235f8f2d3ef91d87864b76e12838e89", + "content-hash": "17cd7e695939dc97e22d10fa4efbe10b", "packages": [ { "name": "drupal/core", diff --git a/package_manager/tests/modules/fixture_manipulator/src/FixtureManipulator.php b/package_manager/tests/modules/fixture_manipulator/src/FixtureManipulator.php index af72eca2b2838421f8d4925622318e55eb0d6de7..00ea699db1f1b08367975005f75c332c86d3013a 100644 --- a/package_manager/tests/modules/fixture_manipulator/src/FixtureManipulator.php +++ b/package_manager/tests/modules/fixture_manipulator/src/FixtureManipulator.php @@ -138,7 +138,7 @@ class FixtureManipulator { $fs->mkdir($file_dir); } } - file_put_contents("$repo_path/$file_name", $file_contents); + assert(file_put_contents("$repo_path/$file_name", $file_contents) !== FALSE); } } return $this->requirePackage($package['name'], $package['version'], $is_dev_requirement, $allow_plugins); @@ -277,7 +277,7 @@ class FixtureManipulator { if ($file_name === NULL) { $file_name = "$project_name.info.yml"; } - file_put_contents("$path/$file_name", Yaml::encode(['project' => $project_name])); + assert(file_put_contents("$path/$file_name", Yaml::encode(['project' => $project_name])) !== FALSE); return $this; } @@ -586,7 +586,7 @@ class FixtureManipulator { 'url' => $repo_path, ]; $packages_data['packages'][$name][$version] = $package; - file_put_contents($packages_json, json_encode($packages_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); + assert(file_put_contents($packages_json, json_encode($packages_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)) !== FALSE); return $repo_path; } @@ -607,7 +607,7 @@ class FixtureManipulator { // Update all the repos in the composer.json file to point to the new // repos at the absolute path. $composer_json = file_get_contents($this->dir . '/packages.json'); - file_put_contents($this->dir . '/packages.json', str_replace('../path_repos/', "$path_repo_base/", $composer_json)); + assert(file_put_contents($this->dir . '/packages.json', str_replace('../path_repos/', "$path_repo_base/", $composer_json)) !== FALSE); $this->runComposerCommand(['update', '--lock']); $this->runComposerCommand(['install']); } diff --git a/package_manager/tests/src/Kernel/ComposerInspectorTest.php b/package_manager/tests/src/Kernel/ComposerInspectorTest.php index 835a76d1d7677f8df754370a97a0e7a1d6affda2..bf5d8c8c42be34cd37470d25a774093fdbe4b5d4 100644 --- a/package_manager/tests/src/Kernel/ComposerInspectorTest.php +++ b/package_manager/tests/src/Kernel/ComposerInspectorTest.php @@ -51,6 +51,11 @@ class ComposerInspectorTest extends PackageManagerKernelTestBase { "foo-bar" => NULL, ], 'baz' => NULL, + 'installer-paths' => [ + 'modules/contrib/{$name}' => ['type:drupal-module'], + 'profiles/contrib/{$name}' => ['type:drupal-profile'], + 'themes/contrib/{$name}' => ['type:drupal-theme'], + ], ], Json::decode($inspector->getConfig('extra', $dir))); try { diff --git a/package_manager/tests/src/Traits/ComposerInstallersTrait.php b/package_manager/tests/src/Traits/ComposerInstallersTrait.php index 4eb1d6ba09db159793ba8aabbfc84ab1268df754..3531b7d40f54cf6f06295e6aa418ce374d85e7c5 100644 --- a/package_manager/tests/src/Traits/ComposerInstallersTrait.php +++ b/package_manager/tests/src/Traits/ComposerInstallersTrait.php @@ -61,14 +61,14 @@ trait ComposerInstallersTrait { * The fixture directory. */ private function setInstallerPaths(array $installer_paths, string $directory):void { - // Ensure Drupal core's default installer paths are also respected. + // Respect any existing installer paths. $extra = $this->container->get(ComposerInspector::class) - ->getConfig('extra', $this->getDrupalRoot() . '/composer.json'); - $core_project_installer_paths = json_decode($extra, TRUE, flags: JSON_THROW_ON_ERROR)['installer-paths']; + ->getConfig('extra', $directory . '/composer.json'); + $existing_installer_paths = json_decode($extra, TRUE, flags: JSON_THROW_ON_ERROR)['installer-paths'] ?? []; (new FixtureManipulator()) ->addConfig([ - 'extra.installer-paths' => $installer_paths + $core_project_installer_paths, + 'extra.installer-paths' => $installer_paths + $existing_installer_paths, ]) ->commitChanges($directory); }