function Fixtures::cloneFixtureProjects

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Fixtures.php \Drupal\Tests\Composer\Plugin\Scaffold\Fixtures::cloneFixtureProjects()
  2. 8.9.x core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Fixtures.php \Drupal\Tests\Composer\Plugin\Scaffold\Fixtures::cloneFixtureProjects()
  3. 11.x core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Fixtures.php \Drupal\Tests\Composer\Plugin\Scaffold\Fixtures::cloneFixtureProjects()

Creates a temporary copy of all of the fixtures projects into a temp dir.

The fixtures remain dirty if they already exist. Individual tests should first delete any fixture directory that needs to remain pristine. Since all temporary directories are removed in tearDown, this is only an issue when a) the FIXTURE_DIR environment variable has been set, or b) tests are calling cloneFixtureProjects more than once per test method.

Parameters

string $fixturesDir: The directory to place fixtures in.

array $replacements: Key : value mappings for placeholders to replace in composer.json templates.

File

core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Fixtures.php, line 334

Class

Fixtures
Convenience class for creating fixtures.

Namespace

Drupal\Tests\Composer\Plugin\Scaffold

Code

public function cloneFixtureProjects($fixturesDir, array $replacements = []) {
    $filesystem = new Filesystem();
    // We will replace 'SYMLINK' with the string 'true' in our composer.json
    // fixture.
    $replacements += [
        'SYMLINK' => 'true',
    ];
    $interpolator = new Interpolator('__', '__');
    $interpolator->setData($replacements);
    $filesystem->copy($this->allFixturesDir(), $fixturesDir);
    $composer_json_templates = glob($fixturesDir . "/*/composer.json.tmpl");
    foreach ($composer_json_templates as $composer_json_tmpl) {
        // Inject replacements into composer.json.
        if (file_exists($composer_json_tmpl)) {
            $composer_json_contents = file_get_contents($composer_json_tmpl);
            $composer_json_contents = $interpolator->interpolate($composer_json_contents, [], FALSE);
            file_put_contents(dirname($composer_json_tmpl) . "/composer.json", $composer_json_contents);
            @unlink($composer_json_tmpl);
        }
    }
}

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