class ComponentsIsolatedBuildTest

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/BuildTests/Composer/Component/ComponentsIsolatedBuildTest.php \Drupal\BuildTests\Composer\Component\ComponentsIsolatedBuildTest
  2. 10 core/tests/Drupal/BuildTests/Composer/Component/ComponentsIsolatedBuildTest.php \Drupal\BuildTests\Composer\Component\ComponentsIsolatedBuildTest

Try to install dependencies per component, using Composer.

@group #slow @group Composer @group Component

@coversNothing

@requires externalCommand composer

Hierarchy

Expanded class hierarchy of ComponentsIsolatedBuildTest

File

core/tests/Drupal/BuildTests/Composer/Component/ComponentsIsolatedBuildTest.php, line 19

Namespace

Drupal\BuildTests\Composer\Component
View source
class ComponentsIsolatedBuildTest extends ComposerBuildTestBase {
  
  /**
   * Provides an array with relative paths to the component paths.
   *
   * @return array
   *   An array with relative paths to the component paths.
   */
  public function provideComponentPaths() : array {
    $data = [];
    // During the dataProvider phase, there is not a workspace directory yet.
    // So we will find relative paths and assemble them with the workspace
    // path later.
    $drupal_root = $this->getDrupalRoot();
    $composer_json_finder = $this->getComponentPathsFinder($drupal_root);
    /** @var \Symfony\Component\Finder\SplFileInfo $path */
    foreach ($composer_json_finder->getIterator() as $path) {
      $data[] = [
        '/' . $path->getRelativePath(),
      ];
    }
    return $data;
  }
  
  /**
   * Test whether components' composer.json can be installed in isolation.
   *
   * @dataProvider provideComponentPaths
   */
  public function testComponentComposerJson(string $component_path) : void {
    // Only copy the components. Copy all of them because some of them depend on
    // each other.
    $finder = $this->getCodebaseFinder();
    $finder->in($this->getDrupalRoot() . static::$componentsPath);
    $this->copyCodebase($finder->getIterator());
    $working_dir = $this->getWorkingPath() . static::$componentsPath . $component_path;
    // We add path repositories so we can wire internal dependencies together.
    $this->addExpectedRepositories($working_dir);
    // Perform the installation.
    $this->executeCommand("composer install --working-dir={$working_dir} --no-interaction --no-progress");
    $this->assertCommandSuccessful();
  }
  
  /**
   * Adds expected repositories as path repositories to package under test.
   *
   * @param string $working_dir
   *   The working directory.
   */
  protected function addExpectedRepositories(string $working_dir) : void {
    $repo_paths = [
      'Render' => 'drupal/core-render',
      'Utility' => 'drupal/core-utility',
    ];
    foreach ($repo_paths as $path => $package_name) {
      $path_repo = $this->getWorkingPath() . static::$componentsPath . '/' . $path;
      $repo_name = strtolower($path);
      // Add path repositories with the current version number to the current
      // package under test.
      $drupal_version = Composer::drupalVersionBranch();
      $this->executeCommand("composer config repositories.{$repo_name} " . "'{\"type\": \"path\",\"url\": \"{$path_repo}\",\"options\": {\"versions\": {\"{$package_name}\": \"{$drupal_version}\"}}}' --working-dir={$working_dir}");
    }
  }

}

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