You are here

class ComposerDependenciesCheckMock in CloudFlare 8

Tests that composer dependencies are met.

Hierarchy

Expanded class hierarchy of ComposerDependenciesCheckMock

3 files declare their use of ComposerDependenciesCheckMock
CloudFlareAdminSettingsFormTest.php in tests/src/Functional/CloudFlareAdminSettingsFormTest.php
CloudFlareAdminSettingsInvalidFormTest.php in tests/src/Functional/CloudFlareAdminSettingsInvalidFormTest.php
ComposerDependencyTest.php in tests/src/Functional/ComposerDependencyTest.php
1 string reference to 'ComposerDependenciesCheckMock'
cloudflare_form_tester.services.yml in tests/modules/cloudflare_form_tester/cloudflare_form_tester.services.yml
tests/modules/cloudflare_form_tester/cloudflare_form_tester.services.yml
1 service uses ComposerDependenciesCheckMock
cloudflare.composer_dependency_checkmock in tests/modules/cloudflare_form_tester/cloudflare_form_tester.services.yml
Drupal\cloudflare_form_tester\Mocks\ComposerDependenciesCheckMock

File

tests/modules/cloudflare_form_tester/src/Mocks/ComposerDependenciesCheckMock.php, line 12

Namespace

Drupal\cloudflare_form_tester\Mocks
View source
class ComposerDependenciesCheckMock implements CloudFlareComposerDependenciesCheckInterface {

  /**
   * Set the first time that this function is called in a bootstrap.
   *
   * @var bool
   */
  public static $areDependenciesMet = NULL;

  /**
   * A logger instance.
   *
   * @var \Psr\Log\LoggerInterface
   */
  protected $logger;

  /**
   * {@inheritdoc}
   */
  public static function create(LoggerInterface $logger) {
    return new static($logger);
  }

  /**
   * ComposerDependenciesCheck constructor.
   *
   * @param \Psr\Log\LoggerInterface $logger
   *   A logger instance.
   */
  public function __construct(LoggerInterface $logger) {
    $this->logger = $logger;
  }

  /**
   * {@inheritdoc}
   */
  public function check() {
    $are_dependencies_met = \Drupal::state()
      ->get('cloudflaretesting.assertComposerDependenciesMet');
    if (!$are_dependencies_met) {
      $this->logger
        ->critical(self::ERROR_MESSAGE);
    }
    return $are_dependencies_met;
  }

  /**
   * {@inheritdoc}
   */
  public function assert() {
    if (!$this
      ->check()) {
      throw new ComposerDependencyException(self::ERROR_MESSAGE);
    }
  }

  /**
   * Tells the mock to assert if dependencies are met or not.
   *
   * @param bool $are_dependencies_met
   *   TRUE to mock dependencies are met.  FALSE otherwise.
   */
  public static function mockComposerDependenciesMet($are_dependencies_met) {
    \Drupal::state()
      ->set('cloudflaretesting.assertComposerDependenciesMet', $are_dependencies_met);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CloudFlareComposerDependenciesCheckInterface::ERROR_MESSAGE constant
ComposerDependenciesCheckMock::$areDependenciesMet public static property Set the first time that this function is called in a bootstrap.
ComposerDependenciesCheckMock::$logger protected property A logger instance.
ComposerDependenciesCheckMock::assert public function Asserts that composer dependencies for CloudFlare are met. Overrides CloudFlareComposerDependenciesCheckInterface::assert
ComposerDependenciesCheckMock::check public function Tests that composer dependencies for CloudFlare are met. Overrides CloudFlareComposerDependenciesCheckInterface::check
ComposerDependenciesCheckMock::create public static function
ComposerDependenciesCheckMock::mockComposerDependenciesMet public static function Tells the mock to assert if dependencies are met or not.
ComposerDependenciesCheckMock::__construct public function ComposerDependenciesCheck constructor.