function JsonApiTopLevelResourceNormalizerTest::testNormalizeException
@covers ::normalize
File
-
core/
modules/ jsonapi/ tests/ src/ Kernel/ Normalizer/ JsonApiTopLevelResourceNormalizerTest.php, line 452
Class
- JsonApiTopLevelResourceNormalizerTest
- @coversDefaultClass \Drupal\jsonapi\Normalizer\JsonApiDocumentTopLevelNormalizer @group jsonapi
Namespace
Drupal\Tests\jsonapi\Kernel\NormalizerCode
public function testNormalizeException() : void {
$normalized = $this->container
->get('jsonapi.serializer')
->normalize(new JsonApiDocumentTopLevel(new ErrorCollection([
new BadRequestHttpException('Lorem'),
]), new NullIncludedData(), new LinkCollection([])), 'api_json', [])
->getNormalization();
$this->assertNotEmpty($normalized['errors']);
$this->assertArrayNotHasKey('data', $normalized);
$this->assertEquals(400, $normalized['errors'][0]['status']);
$this->assertEquals('Lorem', $normalized['errors'][0]['detail']);
$this->assertEquals([
'info' => [
'href' => 'https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.1',
],
'via' => [
'href' => 'http://localhost/',
],
], $normalized['errors'][0]['links']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.