You are here

class TestRequestService in Entity Share 8.2

Class TestRequestService.

@package Drupal\entity_share_client_request_test\Service

Hierarchy

Expanded class hierarchy of TestRequestService

1 string reference to 'TestRequestService'
entity_share_client_request_test.services.yml in modules/entity_share_client/tests/modules/entity_share_client_request_test/entity_share_client_request_test.services.yml
modules/entity_share_client/tests/modules/entity_share_client_request_test/entity_share_client_request_test.services.yml
1 service uses TestRequestService
entity_share_client_request_test.request in modules/entity_share_client/tests/modules/entity_share_client_request_test/entity_share_client_request_test.services.yml
Drupal\entity_share_client_request_test\Service\TestRequestService

File

modules/entity_share_client/tests/modules/entity_share_client_request_test/src/Service/TestRequestService.php, line 15

Namespace

Drupal\entity_share_client_request_test\Service
View source
class TestRequestService extends RequestService {

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

  /**
   * {@inheritdoc}
   */
  public function request(Client $http_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::request($http_client, $method, $url);
      }
      return $this->responseMapping[$url];
    }
    return parent::request($http_client, $method, $url);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TestRequestService::$responseMapping protected property A mapping, URL => response, from the GET requests made.
TestRequestService::request public function Performs a HTTP request. Wraps the Guzzle HTTP client. Overrides RequestService::request