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
- class \Drupal\entity_share_client\Service\RemoteManager implements RemoteManagerInterface
- class \Drupal\entity_share_client_remote_manager_test\Service\TestRemoteManager
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\ServiceView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RemoteManager:: |
protected | property | HTTP clients prepared per remote. | |
RemoteManager:: |
protected | property | HTTP clients prepared for JSON:API endpoints per remotes. | |
RemoteManager:: |
protected | property | Logger. | |
RemoteManager:: |
protected | property | Data provided by entity_share entry point per remote. | |
RemoteManager:: |
public | function |
Get the channels infos of a remote website. Overrides RemoteManagerInterface:: |
|
RemoteManager:: |
public | function |
Get the field mappings of a remote website. Overrides RemoteManagerInterface:: |
|
RemoteManager:: |
protected | function | Prepares a client object from the auth plugin. | |
RemoteManager:: |
protected | function | Prepares a client object from the auth plugin. | |
RemoteManager:: |
public | function |
Performs a HTTP request on a JSON:API endpoint. Wraps the HTTP client. Overrides RemoteManagerInterface:: |
|
RemoteManager:: |
constant | A constant to document the call for a JSON:API client. | ||
RemoteManager:: |
public | function |
Performs a HTTP request. Wraps the HTTP client. Overrides RemoteManagerInterface:: |
|
RemoteManager:: |
constant | A constant to document the call for a standard client. | ||
RemoteManager:: |
public | function | RemoteManager constructor. | |
TestRemoteManager:: |
protected | property | A mapping, URL => response, from the GET requests made. | |
TestRemoteManager:: |
protected | function |
Performs a HTTP request. Overrides RemoteManager:: |
|
TestRemoteManager:: |
public | function | Clear the HTTP clients caching. | |
TestRemoteManager:: |
public | function | Clear the remote info caching. | |
TestRemoteManager:: |
public | function | Clear the response mapping. |