private function ApiTest::decodeResponse in Lightning API 8.4
Same name and namespace in other branches
- 8.3 tests/src/Functional/ApiTest.php \Drupal\Tests\lightning_api\Functional\ApiTest::decodeResponse()
Decodes a JSON response from the server.
Parameters
\Psr\Http\Message\ResponseInterface $response: The response object.
Return value
mixed The decoded response data. If the JSON parser raises an error, the test will fail, with the bad input as the failure message.
4 calls to ApiTest::decodeResponse()
- ApiTest::createApiUser in tests/
src/ Functional/ ApiTest.php - Creates a user account with privileged API access.
- ApiTest::testAllowed in tests/
src/ Functional/ ApiTest.php - Tests Getting data as anon and authenticated user.
- ApiTest::testEntities in tests/
src/ Functional/ ApiTest.php - Tests create, read, and update of content entities via the API.
- ApiTest::testForbidden in tests/
src/ Functional/ ApiTest.php - Tests access to unauthorized data is denied, regardless of authentication.
File
- tests/
src/ Functional/ ApiTest.php, line 339
Class
- ApiTest
- Tests that OAuth and JSON:API authenticate and authorize entity operations.
Namespace
Drupal\Tests\lightning_api\FunctionalCode
private function decodeResponse(ResponseInterface $response) {
$body = (string) $response
->getBody();
$data = Json::decode($body);
if (json_last_error() === JSON_ERROR_NONE) {
return $data;
}
else {
$this
->fail($body);
}
}