function LegacyScriptsTest::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 LegacyScriptsTest::makeVendorPackage()
LegacyScriptsTest::testVendorTestCodeCleanup in core/tests/Drupal/BuildTests/Composer/LegacyScriptsTest.php
@covers ::vendorTestCodeCleanup

File

core/tests/Drupal/BuildTests/Composer/LegacyScriptsTest.php, line 97

Class

LegacyScriptsTest
@group Composer @group legacy @requires externalCommand composer @coversDefaultClass \Drupal\Core\Composer\Composer

Namespace

Drupal\BuildTests\Composer

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);
}

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