You are here

class ClientFactoryMock in Acquia Content Hub 8.2

Mocks the client factory service.

Hierarchy

Expanded class hierarchy of ClientFactoryMock

File

tests/modules/acquia_contenthub_server_test/src/Client/ClientFactoryMock.php, line 12

Namespace

Drupal\acquia_contenthub_server_test\Client
View source
class ClientFactoryMock extends ClientFactory {

  /**
   * Override original, and replace Conent Hub client with mock.
   */
  public function registerClient(string $name, string $url, string $api_key, string $secret, string $api_version = 'v2') {
    return ContentHubClientMock::register($this->loggerFactory
      ->get('acquia_contenthub'), $this->dispatcher, $name, $url, $api_key, $secret);
  }

  /**
   * {@inheritdoc}
   */
  public function getClient(Settings $settings = NULL) {
    if (isset($this->client)) {
      return $this->client;
    }
    if (!$this->settings || !Uuid::isValid($this->settings
      ->getUuid()) || empty($this->settings
      ->getName()) || empty($this->settings
      ->getUrl()) || empty($this->settings
      ->getApiKey()) || empty($this->settings
      ->getSecretKey())) {
      return FALSE;
    }

    // Override configuration.
    $config = [
      'base_url' => $this->settings
        ->getUrl(),
      'client-user-agent' => $this
        ->getClientUserAgent(),
    ];
    $this->client = new ContentHubClientMock($config, $this->loggerFactory
      ->get('acquia_contenthub'), $this->settings, $this->settings
      ->getMiddleware(), $this->dispatcher);
    return $this->client;
  }

  /**
   * {@inheritDoc}
   */
  public function isConfigurationSet(Settings $settings = NULL) : bool {
    return TRUE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ClientFactory::$client protected property The contenthub client object.
ClientFactory::$clientCDFObject protected property Client CDF object.
ClientFactory::$config protected property Acquia ContentHub Admin Settings Config.
ClientFactory::$dispatcher protected property The event dispatcher.
ClientFactory::$loggerFactory protected property Logger Factory.
ClientFactory::$moduleList protected property The module extension list.
ClientFactory::$settings protected property Settings object.
ClientFactory::$settingsProvider protected property Settings Provider.
ClientFactory::authenticate public function Makes a call to get a client response based on the client name.
ClientFactory::getClientUserAgent protected function Returns Client's user agent.
ClientFactory::getProvider public function Gets the settings provider from the settings event for contenthub settings.
ClientFactory::getSettings public function Returns a settings object containing CH credentials and other related info.
ClientFactory::populateSettings protected function Call the event to populate contenthub settings.
ClientFactory::updateClientCdf public function Update Client CDF.
ClientFactory::__construct public function ClientManagerFactory constructor.
ClientFactoryMock::getClient public function Instantiates the content hub client. Overrides ClientFactory::getClient
ClientFactoryMock::isConfigurationSet public function Verifies whether Content Hub has been configured or not. Overrides ClientFactory::isConfigurationSet
ClientFactoryMock::registerClient public function Override original, and replace Conent Hub client with mock. Overrides ClientFactory::registerClient