You are here

class TestRemoteManager in Entity Share 8.3

Service that allows to emulate another website in tests.

@package Drupal\entity_share_client_remote_manager_test\Service

Hierarchy

Expanded class hierarchy of TestRemoteManager

1 string reference to 'TestRemoteManager'
entity_share_client_remote_manager_test.services.yml in modules/entity_share_client/tests/modules/entity_share_client_remote_manager_test/entity_share_client_remote_manager_test.services.yml
modules/entity_share_client/tests/modules/entity_share_client_remote_manager_test/entity_share_client_remote_manager_test.services.yml
1 service uses TestRemoteManager
entity_share_client_remote_manager_test.remote_manager in modules/entity_share_client/tests/modules/entity_share_client_remote_manager_test/entity_share_client_remote_manager_test.services.yml
Drupal\entity_share_client_remote_manager_test\Service\TestRemoteManager

File

modules/entity_share_client/tests/modules/entity_share_client_remote_manager_test/src/Service/TestRemoteManager.php, line 15

Namespace

Drupal\entity_share_client_remote_manager_test\Service
View source
class TestRemoteManager extends RemoteManager {

  /**
   * A mapping, URL => response, from the GET requests made.
   *
   * @var \Psr\Http\Message\ResponseInterface[]
   */
  protected $responseMapping = [];

  /**
   * {@inheritdoc}
   */
  protected function doRequest(ClientInterface $client, $method, $url) {

    // It it is a GET request store the result to be able to re-obtain the
    // result to simulate another website.
    if ($method == 'GET') {
      if (!isset($this->responseMapping[$url])) {
        $this->responseMapping[$url] = parent::doRequest($client, $method, $url);
      }
      return $this->responseMapping[$url];
    }
    return parent::doRequest($client, $method, $url);
  }

  /**
   * Clear the response mapping.
   *
   * This is useful if it is needed to emulate a runtime change of content
   * on server.
   */
  public function resetResponseMapping() {
    $this->responseMapping = [];
  }

  /**
   * Clear the HTTP clients caching.
   *
   * This is useful if it is needed to emulate a runtime change of remote.
   *
   * @param string $type
   *   Whether to reset JSON:API or regular HTTP clients cache.
   */
  public function resetHttpClientsCache(string $type) {
    switch ($type) {
      case 'json_api':
        $this->jsonApiHttpClients = [];
        break;
      default:
        $this->httpClients = [];
        break;
    }
  }

  /**
   * Clear the remote info caching.
   *
   * This is useful if it is needed to emulate a runtime change of remote.
   */
  public function resetRemoteInfos() {
    $this->remoteInfos = [];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RemoteManager::$httpClients protected property HTTP clients prepared per remote.
RemoteManager::$jsonApiHttpClients protected property HTTP clients prepared for JSON:API endpoints per remotes.
RemoteManager::$logger protected property Logger.
RemoteManager::$remoteInfos protected property Data provided by entity_share entry point per remote.
RemoteManager::getChannelsInfos public function Get the channels infos of a remote website. Overrides RemoteManagerInterface::getChannelsInfos
RemoteManager::getfieldMappings public function Get the field mappings of a remote website. Overrides RemoteManagerInterface::getfieldMappings
RemoteManager::getHttpClient protected function Prepares a client object from the auth plugin.
RemoteManager::getJsonApiHttpClient protected function Prepares a client object from the auth plugin.
RemoteManager::jsonApiRequest public function Performs a HTTP request on a JSON:API endpoint. Wraps the HTTP client. Overrides RemoteManagerInterface::jsonApiRequest
RemoteManager::JSON_API_CLIENT constant A constant to document the call for a JSON:API client.
RemoteManager::request public function Performs a HTTP request. Wraps the HTTP client. Overrides RemoteManagerInterface::request
RemoteManager::STANDARD_CLIENT constant A constant to document the call for a standard client.
RemoteManager::__construct public function RemoteManager constructor.
TestRemoteManager::$responseMapping protected property A mapping, URL => response, from the GET requests made.
TestRemoteManager::doRequest protected function Performs a HTTP request. Overrides RemoteManager::doRequest
TestRemoteManager::resetHttpClientsCache public function Clear the HTTP clients caching.
TestRemoteManager::resetRemoteInfos public function Clear the remote info caching.
TestRemoteManager::resetResponseMapping public function Clear the response mapping.