protected function ApiTestBase::decodeResponse in Lightning API 8
Same name and namespace in other branches
- 8.2 modules/api_test/tests/src/Functional/ApiTestBase.php \Drupal\Tests\api_test\Functional\ApiTestBase::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 ApiTestBase::decodeResponse()
- ApiTest::testAllowed in modules/
api_test/ tests/ src/ Functional/ ApiTest.php - Tests Getting data as anon and authenticated user.
- ApiTest::testNotAllowed in modules/
api_test/ tests/ src/ Functional/ ApiTest.php - Tests that authenticated and anonymous requests cannot get unauthorized data.
- ApiTestBase::getToken in modules/
api_test/ tests/ src/ Functional/ ApiTestBase.php - Gets a token from the oauth endpoint for use in requests that require authorization.
- EntityCrudTest::testEntities in modules/
api_test/ tests/ src/ Functional/ EntityCrudTest.php - Tests create, read, and update of content entities via the API.
File
- modules/
api_test/ tests/ src/ Functional/ ApiTestBase.php, line 123
Class
Namespace
Drupal\Tests\api_test\FunctionalCode
protected 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);
}
}