From 849277cb9187bbb1e61a227c91ea0e8bb8895c8f Mon Sep 17 00:00:00 2001 From: Ted Bowman <41201-tedbow@users.noreply.drupalcode.org> Date: Wed, 20 Dec 2023 16:45:48 +0000 Subject: [PATCH] Issue #3409774 by phenaproxima, tedbow: Run kernel tests on GitLab CI after module is converted to core version --- .gitlab-ci.yml | 2 ++ package_manager/tests/fixtures/fake_site/composer.json | 7 ++++++- package_manager/tests/fixtures/fake_site/composer.lock | 2 +- .../fixture_manipulator/src/FixtureManipulator.php | 8 ++++---- .../tests/src/Kernel/ComposerInspectorTest.php | 5 +++++ .../tests/src/Traits/ComposerInstallersTrait.php | 8 ++++---- 6 files changed, 22 insertions(+), 10 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 67038561c1..401c13e337 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 a7f2b4cd69..c67ca797d1 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 c0a62b3d73..08a1146dd5 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 af72eca2b2..00ea699db1 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 835a76d1d7..bf5d8c8c42 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 4eb1d6ba09..3531b7d40f 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); } -- GitLab