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
DirectWriteTest.php in core/modules/package_manager/tests/src/Kernel/DirectWriteTest.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) {
  }
  
  /**
   * Throws an exception when finding a specific executable, for testing.
   *
   * @param string $name
   *   The name of the executable for which ::find() will throw an exception.
   */
  public static function throwFor(string $name) : void {
    \Drupal::keyValue('package_manager_test.executable_errors')->set($name, TRUE);
  }
  
  /**
   * {@inheritdoc}
   */
  public function find(string $name) : string {
    $should_throw = \Drupal::keyValue('package_manager_test.executable_errors')->get($name);
    if ($should_throw) {
      throw new LogicException(new class  implements TranslatableInterface {
        
        /**
         * {@inheritdoc}
         */
        public function trans(?TranslatorInterface $translator = NULL, ?string $locale = NULL) : string {
          return 'Not found!';
        }
        
        /**
         * {@inheritdoc}
         */
        public function __toString() : string {
          return $this->trans();
        }

});
    }
    return $this->decorated
      ->find($name);
  }

}

Members

Title Sort descending Modifiers Object type Summary
TestExecutableFinder::find public function
TestExecutableFinder::throwFor public static function Throws an exception when finding a specific executable, for testing.
TestExecutableFinder::__construct public function

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