You are here

protected function ComposerProjectTemplatesTest::makeVendorPackage in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/BuildTests/Composer/Template/ComposerProjectTemplatesTest.php \Drupal\BuildTests\Composer\Template\ComposerProjectTemplatesTest::makeVendorPackage()

Creates a test package that points to all the projects in vendor.

Parameters

string $repository_path: The path where to create the test package.

1 call to ComposerProjectTemplatesTest::makeVendorPackage()
ComposerProjectTemplatesTest::testTemplateCreateProject in core/tests/Drupal/BuildTests/Composer/Template/ComposerProjectTemplatesTest.php
@dataProvider provideTemplateCreateProject

File

core/tests/Drupal/BuildTests/Composer/Template/ComposerProjectTemplatesTest.php, line 318

Class

ComposerProjectTemplatesTest
Demonstrate that Composer project templates are buildable as patched.

Namespace

Drupal\BuildTests\Composer\Template

Code

protected function makeVendorPackage($repository_path) {
  $root = $this
    ->getDrupalRoot();
  $process = $this
    ->executeCommand("composer --working-dir={$root} info --format=json");
  $this
    ->assertCommandSuccessful();
  $installed = json_decode($process
    ->getOutput(), TRUE);

  // Build out package definitions for everything installed in
  // the vendor directory.
  $packages = [];
  foreach ($installed['installed'] as $project) {
    $name = $project['name'];
    $version = $project['version'];
    $path = "vendor/{$name}";
    $full_path = "{$root}/{$path}";

    // We are building a set of path repositories to projects in the vendor
    // directory, so we will skip any project that does not exist in vendor.
    // Also skip the projects that are symlinked in vendor. These are in our
    // metapackage. They will be represented as path repositories in the test
    // project's composer.json.
    if (is_dir($full_path) && !is_link($full_path)) {
      $packages['packages'][$name] = [
        $version => [
          "name" => $name,
          "dist" => [
            "type" => "path",
            "url" => $full_path,
          ],
          "version" => $version,
        ],
      ];
    }
  }
  $json = json_encode($packages, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
  mkdir(dirname($repository_path));
  file_put_contents($repository_path, $json);
}