class Fixtures

Same name in this branch
  1. 11.x core/tests/Drupal/Tests/Composer/Generator/Fixtures.php \Drupal\Tests\Composer\Generator\Fixtures
  2. 11.x core/tests/Drupal/Tests/Composer/Plugin/Unpack/Fixtures.php \Drupal\Tests\Composer\Plugin\Unpack\Fixtures
Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Composer/Generator/Fixtures.php \Drupal\Tests\Composer\Generator\Fixtures
  2. 9 core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Fixtures.php \Drupal\Tests\Composer\Plugin\Scaffold\Fixtures
  3. 8.9.x core/tests/Drupal/Tests/Composer/Generator/Fixtures.php \Drupal\Tests\Composer\Generator\Fixtures
  4. 8.9.x core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Fixtures.php \Drupal\Tests\Composer\Plugin\Scaffold\Fixtures
  5. 10 core/tests/Drupal/Tests/Composer/Generator/Fixtures.php \Drupal\Tests\Composer\Generator\Fixtures
  6. 10 core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Fixtures.php \Drupal\Tests\Composer\Plugin\Scaffold\Fixtures

Convenience class for creating fixtures.

Hierarchy

Expanded class hierarchy of Fixtures

8 files declare their use of Fixtures
AppendOpTest.php in core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Integration/AppendOpTest.php
ComposerHookTest.php in core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ComposerHookTest.php
ManageGitIgnoreTest.php in core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Functional/ManageGitIgnoreTest.php
ReplaceOpTest.php in core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Integration/ReplaceOpTest.php
ScaffoldFileCollectionTest.php in core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Integration/ScaffoldFileCollectionTest.php

... See full list

4 string references to 'Fixtures'
FileCacheTest::testDelete in core/tests/Drupal/Tests/Component/FileCache/FileCacheTest.php
@covers ::delete[[api-linebreak]]
FileCacheTest::testGet in core/tests/Drupal/Tests/Component/FileCache/FileCacheTest.php
@covers ::get[[api-linebreak]] @covers ::__construct[[api-linebreak]]
FileCacheTest::testGetMultiple in core/tests/Drupal/Tests/Component/FileCache/FileCacheTest.php
@covers ::getMultiple[[api-linebreak]]
FileCacheTest::testSet in core/tests/Drupal/Tests/Component/FileCache/FileCacheTest.php
@covers ::set[[api-linebreak]]

File

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

Namespace

Drupal\Tests\Composer\Plugin\Scaffold
View source
class Fixtures extends FixturesBase {
  
  /**
   * {@inheritdoc}
   */
  public function projectRoot() : string {
    return realpath(__DIR__) . '/../../../../../../../composer/Plugin/Scaffold';
  }
  
  /**
   * {@inheritdoc}
   */
  public function allFixturesDir() : string {
    return realpath(__DIR__ . '/fixtures');
  }
  
  /**
   * Gets a path to a source scaffold fixture.
   *
   * Use in place of ScaffoldFilePath::sourcePath().
   *
   * @param string $project_name
   *   The name of the project to fetch; $package_name is
   *   "fixtures/$project_name".
   * @param string $source
   *   The name of the asset; path is "assets/$source".
   *
   * @return \Drupal\Composer\Plugin\Scaffold\ScaffoldFilePath
   *   The full and relative path to the desired asset
   *
   * @see \Drupal\Composer\Plugin\Scaffold\ScaffoldFilePath::sourcePath()
   */
  public function sourcePath($project_name, $source) {
    $package_name = "fixtures/{$project_name}";
    $source_rel_path = "assets/{$source}";
    $package_path = $this->projectFixtureDir($project_name);
    return ScaffoldFilePath::sourcePath($package_name, $package_path, 'unknown', $source_rel_path);
  }
  
  /**
   * Gets an Interpolator with 'web-root' and 'package-name' set.
   *
   * Use in place of ManageOptions::getLocationReplacements().
   *
   * @return \Drupal\Composer\Plugin\Scaffold\Interpolator
   *   An interpolator with location replacements, including 'web-root'.
   *
   * @see \Drupal\Composer\Plugin\Scaffold\ManageOptions::getLocationReplacements()
   */
  public function getLocationReplacements() {
    $destinationTmpDir = $this->mkTmpDir('location-replacements');
    $interpolator = new Interpolator();
    $interpolator->setData([
      'web-root' => $destinationTmpDir,
      'package-name' => 'fixtures/tmp-destination',
    ]);
    return $interpolator;
  }
  
  /**
   * Creates a ReplaceOp fixture.
   *
   * @param string $project_name
   *   The name of the project to fetch; $package_name is
   *   "fixtures/$project_name".
   * @param string $source
   *   The name of the asset; path is "assets/$source".
   *
   * @return \Drupal\Composer\Plugin\Scaffold\Operations\ReplaceOp
   *   A replace operation object.
   */
  public function replaceOp($project_name, $source) {
    $source_path = $this->sourcePath($project_name, $source);
    return new ReplaceOp($source_path, TRUE);
  }
  
  /**
   * Creates an AppendOp fixture.
   *
   * @param string $project_name
   *   The name of the project to fetch; $package_name is
   *   "fixtures/$project_name".
   * @param string $source
   *   The name of the asset; path is "assets/$source".
   *
   * @return \Drupal\Composer\Plugin\Scaffold\Operations\AppendOp
   *   An append operation object.
   */
  public function appendOp($project_name, $source) {
    $source_path = $this->sourcePath($project_name, $source);
    return new AppendOp(NULL, $source_path);
  }
  
  /**
   * Gets a destination path in a tmp dir.
   *
   * Use in place of ScaffoldFilePath::destinationPath().
   *
   * @param string $destination
   *   Destination path; should be in the form '[web-root]/robots.txt', where
   *   '[web-root]' is always literally '[web-root]', with any arbitrarily
   *   desired filename following.
   * @param \Drupal\Composer\Plugin\Scaffold\Interpolator $interpolator
   *   Location replacements. Obtain via Fixtures::getLocationReplacements()
   *   when creating multiple scaffold destinations.
   * @param string $package_name
   *   (optional) The name of the fixture package that this path came from.
   *   Taken from interpolator if not provided.
   *
   * @return \Drupal\Composer\Plugin\Scaffold\ScaffoldFilePath
   *   A destination scaffold file backed by temporary storage.
   *
   * @see \Drupal\Composer\Plugin\Scaffold\ScaffoldFilePath::destinationPath()
   */
  public function destinationPath($destination, ?Interpolator $interpolator = NULL, $package_name = NULL) {
    $interpolator = $interpolator ?: $this->getLocationReplacements();
    $package_name = $package_name ?: $interpolator->interpolate('[package-name]');
    return ScaffoldFilePath::destinationPath($package_name, $destination, $interpolator);
  }
  
  /**
   * Runs the scaffold operation.
   *
   * This is equivalent to running `composer composer-scaffold`, but we do the
   * equivalent operation by instantiating a Handler object in order to continue
   * running in the same process, so that coverage may be calculated for the
   * code executed by these tests.
   *
   * @param string $cwd
   *   The working directory to run the scaffold command in.
   *
   * @return string
   *   Output captured from tests that write to Fixtures::io().
   */
  public function runScaffold($cwd) {
    chdir($cwd);
    $handler = new Handler($this->getComposer(), $this->io());
    $handler->scaffold();
    return $this->getOutput();
  }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
Fixtures::allFixturesDir public function Gets the path to the project fixtures. Overrides FixturesBase::allFixturesDir
Fixtures::appendOp public function Creates an AppendOp fixture.
Fixtures::destinationPath public function Gets a destination path in a tmp dir.
Fixtures::getLocationReplacements public function Gets an Interpolator with 'web-root' and 'package-name' set.
Fixtures::projectRoot public function Gets the path to Scaffold component. Overrides FixturesBase::projectRoot
Fixtures::replaceOp public function Creates a ReplaceOp fixture.
Fixtures::runScaffold public function Runs the scaffold operation.
Fixtures::sourcePath public function Gets a path to a source scaffold fixture.
FixturesBase::$composer protected property The composer object.
FixturesBase::$io protected property A Composer IOInterface to write to.
FixturesBase::$randomPrefix protected static property Keep a persistent prefix to help group our tmp directories together.
FixturesBase::$tmpDirs protected property Directories to delete when we are done.
FixturesBase::binFixtureDir public function Gets the path to one particular bin path.
FixturesBase::cloneFixtureProjects public function Creates a temporary copy of all of the fixtures projects into a temp dir.
FixturesBase::createIsolatedComposerCacheDir public function Creates an isolated cache directory for Composer.
FixturesBase::getComposer public function Gets the Composer object.
FixturesBase::getOutput public function Gets the output from the io() fixture.
FixturesBase::io public function Gets an IO fixture.
FixturesBase::mkTmpDir public function Creates a temporary directory.
FixturesBase::persistentPrefix protected static function Generates a persistent prefix to use with all of our temporary directories.
FixturesBase::projectFixtureDir public function Gets the path to one particular project fixture.
FixturesBase::runComposer public function Runs a `composer` command.
FixturesBase::tearDown public function Calls 'tearDown' in any test that copies fixtures to transient locations.
FixturesBase::tmpDir public function Generates a path to a temporary location, but do not create the directory. 1

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