private function ApiTest::decodeResponse in Lightning API 8.3
Same name and namespace in other branches
- 8.4 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 that authenticated and anonymous users cannot get unauthorized data.
File
- tests/
src/ Functional/ ApiTest.php, line 332
Class
- ApiTest
- Tests OAuth and JSON:API authentication and interactions with entities.
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);
}
}