function ComposerProjectTemplatesTest::makeVendorPackage

Same name in other branches
  1. 9 core/tests/Drupal/BuildTests/Composer/Template/ComposerProjectTemplatesTest.php \Drupal\BuildTests\Composer\Template\ComposerProjectTemplatesTest::makeVendorPackage()
  2. 10 core/tests/Drupal/BuildTests/Composer/Template/ComposerProjectTemplatesTest.php \Drupal\BuildTests\Composer\Template\ComposerProjectTemplatesTest::makeVendorPackage()
  3. 11.x 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 253

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.
        if (is_dir($full_path)) {
            $packages['packages'][$name] = [
                $version => [
                    "name" => $name,
                    "dist" => [
                        "type" => "path",
                        "url" => $path,
                    ],
                    "version" => $version,
                ],
            ];
        }
    }
    $json = json_encode($packages, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
    mkdir(dirname($repository_path));
    file_put_contents($repository_path, $json);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.