protected function LinkProviderTest::getJsonapiDocument in JSON:API Hypermedia 8
Performs a JSON:API request and returns its deserialized document response.
Parameters
string $uri: The URI of the JSON:API document to be fetched.
int $expected_status: The expected status of the response to be fetched.
Return value
array The fetched and deserialized JSON:API document.
1 call to LinkProviderTest::getJsonapiDocument()
- LinkProviderTest::getLink in tests/
src/ Functional/ LinkProviderTest.php - Requests a document from which to assert & extract an expected link.
File
- tests/
src/ Functional/ LinkProviderTest.php, line 353
Class
- LinkProviderTest
- Class LinkProviderTest.
Namespace
Drupal\Tests\jsonapi_hypermedia\FunctionalCode
protected function getJsonapiDocument($uri, $expected_status = 200) {
$headers = [
'accept' => 'application/vnd.api+json',
];
$options = [
RequestOptions::HEADERS => $headers,
];
$url = Url::fromUri($uri);
$response = $this
->request('GET', $url, $options);
$this
->assertSame($expected_status, $response
->getStatusCode(), "URL: {$url->setAbsolute()->toString()}");
$body = (string) $response
->getBody();
$document = Json::decode($body);
$this
->assertNotNull($document, "Response Body: {$body}");
return $document;
}