class StageFixtureManipulator

A fixture manipulator service that commits changes after begin.

Hierarchy

Expanded class hierarchy of StageFixtureManipulator

2 files declare their use of StageFixtureManipulator
FixtureManipulatorTrait.php in core/modules/package_manager/tests/src/Traits/FixtureManipulatorTrait.php
PackageManagerKernelTestBase.php in core/modules/package_manager/tests/src/Kernel/PackageManagerKernelTestBase.php

File

core/modules/package_manager/tests/modules/fixture_manipulator/src/StageFixtureManipulator.php, line 17

Namespace

Drupal\fixture_manipulator
View source
final class StageFixtureManipulator extends FixtureManipulator implements BeginnerInterface {
  
  /**
   * The state key to use.
   */
  private const STATE_KEY = __CLASS__ . 'MANIPULATOR_ARGUMENTS';
  
  /**
   * The state service.
   *
   * @var \Drupal\Core\State\StateInterface
   */
  private StateInterface $state;
  
  /**
   * The decorated service.
   *
   * @var \PhpTuf\ComposerStager\API\Core\BeginnerInterface
   */
  private BeginnerInterface $inner;
  
  /**
   * Constructions a StageFixtureManipulator object.
   *
   * @param \Drupal\Core\State\StateInterface $state
   *   The state service.
   * @param \PhpTuf\ComposerStager\API\Core\BeginnerInterface $inner
   *   The decorated beginner service.
   */
  public function __construct(StateInterface $state, BeginnerInterface $inner) {
    $this->state = $state;
    $this->inner = $inner;
  }
  
  /**
   * {@inheritdoc}
   */
  public function begin(PathInterface $activeDir, PathInterface $stagingDir, ?PathListInterface $exclusions = NULL, ?OutputCallbackInterface $callback = NULL, ?int $timeout = ProcessInterface::DEFAULT_TIMEOUT) : void {
    $this->inner
      ->begin($activeDir, $stagingDir, $exclusions, $callback, $timeout);
    if ($this->getQueuedManipulationItems()) {
      $this->doCommitChanges($stagingDir->absolute());
    }
  }
  
  /**
   * {@inheritdoc}
   */
  public function commitChanges(string $dir, bool $validate_composer = FALSE) : self {
    throw new \BadMethodCallException('::commitChanges() should not be called directly in StageFixtureManipulator().');
  }
  
  /**
   * {@inheritdoc}
   */
  public function __destruct() {
    // Overrides `__destruct` because the staged fixture manipulator service
    // will be destroyed after every request.
    // @see \Drupal\fixture_manipulator\StageFixtureManipulator::handleTearDown()
  }
  
  /**
   * Handles test tear down to ensure all changes were committed.
   */
  public static function handleTearDown() : void {
    if (!empty(\Drupal::state()->get(self::STATE_KEY))) {
      throw new \LogicException('The StageFixtureManipulator has arguments that were not cleared. This likely means that the PostCreateEvent was never fired.');
    }
  }
  
  /**
   * {@inheritdoc}
   */
  protected function queueManipulation(string $method, array $arguments) : void {
    $stored_arguments = $this->getQueuedManipulationItems();
    $stored_arguments[$method][] = $arguments;
    $this->state
      ->set(self::STATE_KEY, $stored_arguments);
  }
  
  /**
   * {@inheritdoc}
   */
  protected function clearQueuedManipulationItems() : void {
    $this->state
      ->delete(self::STATE_KEY);
  }
  
  /**
   * {@inheritdoc}
   */
  protected function getQueuedManipulationItems() : array {
    return $this->state
      ->get(self::STATE_KEY, []);
  }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
FixtureManipulator::$committed protected property Whether changes have been committed.
FixtureManipulator::$committingChanges private property Whether changes are currently being committed.
FixtureManipulator::$dir protected property The fixture directory.
FixtureManipulator::$manipulatorArguments private property Arguments to manipulator functions.
FixtureManipulator::addConfig public function Modifies the project root's composer.json properties.
FixtureManipulator::addDotGitFolder public function Creates an empty .git folder after being provided a path.
FixtureManipulator::addPackage public function Adds a package.
FixtureManipulator::addProjectAtPath public function Adds a project at a path.
FixtureManipulator::addRepository private function Adds a path repository.
FixtureManipulator::createPathRepo private function Creates a path repo.
FixtureManipulator::doCommitChanges final protected function Commits all the changes.
FixtureManipulator::getComposerInitOptionsForPackage private static function Transform the received $package into options for `composer init`.
FixtureManipulator::modifyPackageConfig public function Modifies a package's composer.json properties.
FixtureManipulator::PATH_REPO_STATE_KEY protected constant
FixtureManipulator::removePackage public function Removes a package.
FixtureManipulator::requirePackage public function Requires a package.
FixtureManipulator::runComposerCommand protected function
FixtureManipulator::setCorePackageVersion public function Modifies core packages.
FixtureManipulator::setUpRepos public function Sets up the path repos at absolute paths.
FixtureManipulator::setVersion public function Sets a package version.
FixtureManipulator::updateLock public function
FixtureManipulator::validateComposer private function Validate the fixtures still passes `composer validate`.
StageFixtureManipulator::$inner private property The decorated service.
StageFixtureManipulator::$state private property The state service.
StageFixtureManipulator::begin public function
StageFixtureManipulator::clearQueuedManipulationItems protected function Clears all queued manipulation items. Overrides FixtureManipulator::clearQueuedManipulationItems
StageFixtureManipulator::commitChanges public function Commits the changes to the directory. Overrides FixtureManipulator::commitChanges
StageFixtureManipulator::getQueuedManipulationItems protected function Gets all queued manipulation items. Overrides FixtureManipulator::getQueuedManipulationItems
StageFixtureManipulator::handleTearDown public static function Handles test tear down to ensure all changes were committed.
StageFixtureManipulator::queueManipulation protected function Queues manipulation arguments to be called in ::doCommitChanges(). Overrides FixtureManipulator::queueManipulation
StageFixtureManipulator::STATE_KEY private constant The state key to use.
StageFixtureManipulator::__construct public function Constructions a StageFixtureManipulator object.
StageFixtureManipulator::__destruct public function Ensure that changes were committed before object is destroyed. Overrides FixtureManipulator::__destruct

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