class TestExecutableFinder

A test-only executable finder that can be rigged to throw an exception.

Hierarchy

Expanded class hierarchy of TestExecutableFinder

1 file declares its use of TestExecutableFinder
ComposerRequirementTest.php in core/modules/package_manager/tests/src/Functional/ComposerRequirementTest.php

File

core/modules/package_manager/tests/modules/package_manager_test_validation/src/TestExecutableFinder.php, line 15

Namespace

Drupal\package_manager_test_validation
View source
final class TestExecutableFinder implements ExecutableFinderInterface {
  public function __construct(private readonly ExecutableFinderInterface $decorated, private readonly StateInterface $state) {
  }
  
  /**
   * Sets up an exception to throw when trying to find a specific executable.
   *
   * @param string $name
   *   The name of an executable to look for.
   */
  public static function throwFor(string $name) : void {
    \Drupal::state()->set("throw for {$name}", TRUE);
  }
  
  /**
   * {@inheritdoc}
   */
  public function find(string $name) : string {
    if ($this->state
      ->get("throw for {$name}")) {
      $message = new TranslatableStringAdapter("{$name} is not a thing");
      throw new LogicException($message);
    }
    return $this->decorated
      ->find($name);
  }

}

Members

Title Sort descending Modifiers Object type Summary
TestExecutableFinder::find public function
TestExecutableFinder::throwFor public static function Sets up an exception to throw when trying to find a specific executable.
TestExecutableFinder::__construct public function

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