function ComposerInstallersTrait::installComposerInstallers

Installs the composer/installers package.

Parameters

string $dir: The fixture directory to install into.

3 calls to ComposerInstallersTrait::installComposerInstallers()
EnabledExtensionsValidatorTest::testExtensionRemoved in core/modules/package_manager/tests/src/Kernel/EnabledExtensionsValidatorTest.php
Tests that error is raised if Drupal modules, profiles or themes are removed.
GitExcluderTest::setUp in core/modules/package_manager/tests/src/Kernel/PathExcluder/GitExcluderTest.php
OverwriteExistingPackagesValidatorTest::setUp in core/modules/package_manager/tests/src/Kernel/OverwriteExistingPackagesValidatorTest.php

File

core/modules/package_manager/tests/src/Traits/ComposerInstallersTrait.php, line 25

Class

ComposerInstallersTrait
A utility for kernel tests that need to use 'composer/installers'.

Namespace

Drupal\Tests\package_manager\Traits

Code

private function installComposerInstallers(string $dir) : void {
  $package_name = 'composer/installers';
  $this->assertTrue(InstalledVersions::isInstalled($package_name));
  $repository = json_encode([
    'type' => 'path',
    'url' => InstalledVersions::getInstallPath($package_name),
    'options' => [
      'symlink' => FALSE,
      'versions' => [
        // Explicitly state the version contained by this path repository,
        // otherwise Composer will infer the version based on the git clone or
        // fall back to `dev-master`.
        // @see https://getcomposer.org/doc/05-repositories.md#path
'composer/installers' => InstalledVersions::getVersion($package_name),
      ],
    ],
  ], JSON_UNESCAPED_SLASHES);
  $working_dir_option = "--working-dir={$dir}";
  (new Process([
    'composer',
    'config',
    'repo.composer-installers-real',
    $repository,
    $working_dir_option,
  ]))->mustRun();
  (new FixtureManipulator())->addConfig([
    'allow-plugins.composer/installers' => TRUE,
  ])
    ->commitChanges($dir);
  (new Process([
    'composer',
    'require',
    'composer/installers:@dev',
    $working_dir_option,
  ]))->mustRun();
  // Use the default installer paths for Drupal core and extensions.
  $this->setInstallerPaths([], $dir);
}

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