You are here

public function ClientFactoryMock::getClient in Acquia Content Hub 8.2

Instantiates the content hub client.

Return value

\Acquia\ContentHubClient\ContentHubClient|bool The ContentHub Client

Overrides ClientFactory::getClient

File

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

Class

ClientFactoryMock
Mocks the client factory service.

Namespace

Drupal\acquia_contenthub_server_test\Client

Code

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;
}