Unverified Commit 193bcef1 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3525727 by alexpott, mxr576, grimreaper, phenaproxima, b_sharpe: Recipe...

Issue #3525727 by alexpott, mxr576, grimreaper, phenaproxima, b_sharpe: Recipe Composer plugin: support wikimedia/composer-merge-plugin

(cherry picked from commit 276fb1ab)
parent c0255e86
Loading
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -143,7 +143,7 @@ public function writeFiles(): void {
  }

  /**
   * Checks that the composer content and root package match.
   * Checks that the composer content exists in the root package.
   *
   * @param string $composer_content
   *   The root composer content.
@@ -155,7 +155,8 @@ public function writeFiles(): void {
   */
  private static function checkRootPackage(string $composer_content, RootPackageInterface $root_package): bool {
    $composer = JsonFile::parseJson($composer_content);
    return empty(array_diff_key($root_package->getRequires(), $composer['require'] ?? [])) && empty(array_diff_key($root_package->getDevRequires(), $composer['require-dev'] ?? []));
    return empty(array_diff_key($composer['require'] ?? [], $root_package->getRequires()))
      && empty(array_diff_key($composer['require-dev'] ?? [], $root_package->getDevRequires()));
  }

}
+49 −0
Original line number Diff line number Diff line
@@ -584,6 +584,55 @@ public function testComposerCreateProject(): void {
    $this->doTestRecipeAUnpacked($this->fixturesDir . '/composer-root2', $stdOut);
  }

  /**
   * Tests unpacking with the wikimedia/composer-merge-plugin installed.
   */
  public function testUnpackWithComposerMergePlugin(): void {
    $root_project_path = $this->fixturesDir . '/composer-root';
    $this->runComposer('install');

    // Copy the merge plugin composer file fixture into the root project so the
    // merge plugin can include it.
    $merge_fixture_source = $this->fixturesDir . '/merge/composer.merge.json';
    $merge_fixture_dest = $root_project_path . '/composer.merge.json';
    copy($merge_fixture_source, $merge_fixture_dest);

    // Allow packagist since we need to require the merge plugin.
    $this->runComposer('config --unset repositories.packagist.org');

    // Configure and install the merge plugin.
    $this->runComposer('config --no-plugins allow-plugins.wikimedia/composer-merge-plugin true');
    $this->runComposer('require wikimedia/composer-merge-plugin:*');
    $this->runComposer("config --merge --json extra.merge-plugin.include '[\"composer.merge.json\"]'");

    // Require recipe A, which should cause it to be unpacked automatically and
    // also merge in any dependencies from composer.merge.json (module C).
    $stdout = $this->runComposer('require fixtures/recipe-a');

    // Confirm unpack occurred as expected.
    $this->assertStringContainsString("fixtures/recipe-a unpacked.", $stdout);
    $this->assertStringContainsString("fixtures/recipe-b unpacked.", $stdout);

    // Validate composer files are still valid.
    $this->runComposer('validate');

    // Ensure recipe files exist.
    $this->assertFileExists($root_project_path . '/recipes/recipe-a/recipe.yml');
    $this->assertFileExists($root_project_path . '/recipes/recipe-b/recipe.yml');

    // Check the lock for the merged dependencies.
    $root_composer_lock = $this->getFileContents($root_project_path . '/composer.lock');
    $this->assertSame([
      'composer/installers',
      'drupal/core-recipe-unpack',
      'fixtures/module-a',
      'fixtures/module-b',
      'fixtures/module-c',
      'fixtures/theme-a',
      'wikimedia/composer-merge-plugin',
    ], array_column($root_composer_lock['packages'], 'name'));
  }

  /**
   * Tests Recipe A is unpacked correctly.
   *
+7 −0
Original line number Diff line number Diff line
@@ -62,6 +62,13 @@
        "symlink": true
      }
    },
    "modules/module-c": {
      "type": "path",
      "url": "../modules/composer-module-c",
      "options": {
        "symlink": true
      }
    },
    "themes/theme-a": {
      "type": "path",
      "url": "../themes/composer-theme-a",
+5 −0
Original line number Diff line number Diff line
{
  "require": {
    "fixtures/module-c": "1.0.0"
  }
}
+6 −0
Original line number Diff line number Diff line
{
  "name": "fixtures/module-c",
  "version": "1.0.0",
  "type": "drupal-module",
  "description": "A Drupal module's composer for testing."
}