cloneFixtureProjects example

/** * Tests upgrading the Composer Scaffold plugin. */
  public function testScaffoldUpgrade() {
    $composerVersionLine = exec('composer --version');
    if (str_contains($composerVersionLine, 'Composer version 2')) {
      $this->markTestSkipped('We cannot run the scaffold upgrade test with Composer 2 until we have a stable version of drupal/core-composer-scaffold to start from that we can install with Composer 2.x.');
    }
    $this->fixturesDir = $this->fixtures->tmpDir($this->getName());
    $replacements = ['SYMLINK' => 'false', 'PROJECT_ROOT' => $this->fixtures->projectRoot()];
    $this->fixtures->cloneFixtureProjects($this->fixturesDir, $replacements);
    $topLevelProjectDir = 'drupal-drupal';
    $sut = $this->fixturesDir . '/' . $topLevelProjectDir;

    // First step: set up the Scaffold plug in. Ensure that scaffold operation     // ran. This is more of a control than a test.     $this->mustExec("composer install --no-ansi", $sut);
    $this->assertScaffoldedFile($sut . '/sites/default/default.settings.php', FALSE, 'A settings.php fixture file scaffolded from the scaffold-override-fixture');

    // Next, bring back packagist.org and install core-composer-scaffold:8.8.0.     // Packagist is disabled in the fixture; we bring it back by removing the     // line that disables it.

  protected function createSut($fixture_name, array $replacements = []) {
    $sut = $this->fixturesDir . '/' . $fixture_name;
    // Erase just our sut, to ensure it is clean. Recopy all of the fixtures.     $this->fileSystem->remove($sut);
    $replacements += ['PROJECT_ROOT' => $this->projectRoot];
    $this->fixtures->cloneFixtureProjects($this->fixturesDir, $replacements);
    return $sut;
  }

  /** * Creates the system-under-test and runs a scaffold operation on it. * * @param string $fixture_name * The name of the fixture to use from * core/tests/Drupal/Tests/Component/Scaffold/fixtures. * @param bool $is_link * Whether to use symlinks for 'replace' operations. * @param bool $relocated_docroot * Whether the named fixture has a relocated document root. */
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->fileSystem = new Filesystem();
    $this->fixtures = new Fixtures();
    $this->fixtures->createIsolatedComposerCacheDir();
    $this->fixturesDir = $this->fixtures->tmpDir($this->getName());
    $replacements = ['SYMLINK' => 'false', 'PROJECT_ROOT' => $this->fixtures->projectRoot()];
    $this->fixtures->cloneFixtureProjects($this->fixturesDir, $replacements);
  }

  /** * {@inheritdoc} */
  protected function tearDown(): void {
    // Remove any temporary directories et. al. that were created.     $this->fixtures->tearDown();

    parent::tearDown();
  }

  

  protected function createSutWithGit($fixture_name) {
    $this->fixturesDir = $this->fixtures->tmpDir($this->getName());
    $sut = $this->fixturesDir . '/' . $fixture_name;
    $replacements = ['SYMLINK' => 'false', 'PROJECT_ROOT' => $this->projectRoot];
    $this->fixtures->cloneFixtureProjects($this->fixturesDir, $replacements);
    // .gitignore files will not be managed unless there is a git repository.     $this->mustExec('git init', $sut);
    // Add some user info so git does not complain.     $this->mustExec('git config user.email "test@example.com"', $sut);
    $this->mustExec('git config user.name "Test User"', $sut);
    $this->mustExec('git add .', $sut);
    $this->mustExec('git commit -m "Initial commit."', $sut);
    // Run composer install, but suppress scaffolding.     $this->fixtures->runComposer("install --no-ansi --no-scripts --no-plugins", $sut);
    return $sut;
  }

  
Home | Imprint | This part of the site doesn't use cookies.