You are here

ClientFactoryMock.php in Acquia Content Hub 8.2

File

tests/modules/acquia_contenthub_server_test/src/Client/ClientFactoryMock.php
View source
<?php

namespace Drupal\acquia_contenthub_server_test\Client;

use Acquia\ContentHubClient\Settings;
use Drupal\acquia_contenthub\Client\ClientFactory;
use Drupal\Component\Uuid\Uuid;

/**
 * Mocks the client factory service.
 */
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;
  }

}

Classes

Namesort descending Description
ClientFactoryMock Mocks the client factory service.