You are here

public static function MockHttpClientMiddleware::addUrlResponse in Thunder 6.2.x

Same name and namespace in other branches
  1. 8.5 tests/modules/thunder_test_mock_request/src/MockHttpClientMiddleware.php \Drupal\thunder_test_mock_request\MockHttpClientMiddleware::addUrlResponse()
  2. 6.1.x tests/modules/thunder_test_mock_request/src/MockHttpClientMiddleware.php \Drupal\thunder_test_mock_request\MockHttpClientMiddleware::addUrlResponse()

Add a mocked response.

Parameters

string $url: URL of the request.

string $body: The content body of the response.

array $headers: The response headers.

int $status: The response status code.

1 call to MockHttpClientMiddleware::addUrlResponse()
thunder_test_mock_request_install in tests/modules/thunder_test_mock_request/thunder_test_mock_request.install
Implements hook_install().

File

tests/modules/thunder_test_mock_request/src/MockHttpClientMiddleware.php, line 55

Class

MockHttpClientMiddleware
Sets the mocked responses.

Namespace

Drupal\thunder_test_mock_request

Code

public static function addUrlResponse($url, $body, array $headers = [], $status = 200) {
  $items = \Drupal::state()
    ->get(static::class, []);
  $items[$url] = [
    'body' => $body,
    'headers' => $headers,
    'status' => $status,
  ];
  \Drupal::state()
    ->set(static::class, $items);
}