You are here

public function JsonApiDocumentTopLevelNormalizerTest::testNormalizeException in JSON:API 8.2

Same name and namespace in other branches
  1. 8 tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php \Drupal\Tests\jsonapi\Kernel\Normalizer\JsonApiDocumentTopLevelNormalizerTest::testNormalizeException()

@covers ::normalize

File

tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php, line 391

Class

JsonApiDocumentTopLevelNormalizerTest
@coversDefaultClass \Drupal\jsonapi\Normalizer\JsonApiDocumentTopLevelNormalizer @group jsonapi @group legacy

Namespace

Drupal\Tests\jsonapi\Kernel\Normalizer

Code

public function testNormalizeException() {
  $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' => 'http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.1',
    ],
    'via' => [
      'href' => 'http://localhost/',
    ],
  ], $normalized['errors'][0]['links']);
}