You are here

public static function MockHttpClientMiddleware::addUrlResponse in Thunder 8.5

Same name and namespace in other branches
  1. 6.2.x 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.

2 calls to MockHttpClientMiddleware::addUrlResponse()
RiddleTest::testRiddle in tests/src/FunctionalJavascript/Integration/RiddleTest.php
Testing integration of "thunder_riddle" module.
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);
}