diff --git a/src/Normalizer/JsonApiDocumentTopLevelNormalizer.php b/src/Normalizer/JsonApiDocumentTopLevelNormalizer.php index fc46e8e..45de4b9 100644 --- a/src/Normalizer/JsonApiDocumentTopLevelNormalizer.php +++ b/src/Normalizer/JsonApiDocumentTopLevelNormalizer.php @@ -317,7 +317,7 @@ class JsonApiDocumentTopLevelNormalizer extends NormalizerBase implements Denorm } // Ensure that the client provided ID is a valid UUID. if (isset($document['data']['id']) && !Uuid::isValid($document['data']['id'])) { - throw new AccessDeniedHttpException('IDs must by properly generated and formatted UUID as described in RFC 4122.'); + throw new AccessDeniedHttpException('IDs should be properly generated and formatted UUIDs as described in RFC 4122.'); } } diff --git a/tests/src/Unit/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php b/tests/src/Unit/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php index aedd797..f007c98 100644 --- a/tests/src/Unit/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php +++ b/tests/src/Unit/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php @@ -140,9 +140,9 @@ class JsonApiDocumentTopLevelNormalizerTest extends UnitTestCase { [ 'uuid' => '0676d1bf-55b3-4bbc-9fbc-3df10f4599d5', 'field_dummy' => [ - [ - 'target_id' => 1, - ], + [ + 'target_id' => 1, + ], ], ], ], @@ -170,12 +170,8 @@ class JsonApiDocumentTopLevelNormalizerTest extends UnitTestCase { [ 'uuid' => '535ba297-8d79-4fc1-b0d6-dc2f047765a1', 'field_dummy' => [ - [ - 'target_id' => 1, - ], - [ - 'target_id' => 2, - ], + ['target_id' => 1], + ['target_id' => 2], ], ], ], @@ -204,13 +200,11 @@ class JsonApiDocumentTopLevelNormalizerTest extends UnitTestCase { [ 'uuid' => '535ba297-8d79-4fc1-b0d6-dc2f047765a1', 'field_dummy' => [ - [ - 'target_id' => 1, - 'foo' => 'bar', - ], - [ - 'target_id' => 2, - ], + [ + 'target_id' => 1, + 'foo' => 'bar', + ], + ['target_id' => 2], ], ], ], @@ -229,17 +223,14 @@ class JsonApiDocumentTopLevelNormalizerTest extends UnitTestCase { * @dataProvider denormalizeUuidProvider */ public function testDenormalizeUuid($id, $expect_exception) { - $data = [ - 'data' => [ - 'type' => 'node--article', - 'id' => $id, - ], - ]; + $data['data'] = (isset($id)) ? + ['type' => 'node--article', 'id' => $id] : + ['type' => 'node--article']; if ($expect_exception) { $this->setExpectedException( AccessDeniedHttpException::class, - 'IDs must by properly generated and formatted UUID as described in RFC 4122.' + 'IDs should be properly generated and formatted UUIDs as described in RFC 4122.' ); } @@ -251,7 +242,12 @@ class JsonApiDocumentTopLevelNormalizerTest extends UnitTestCase { ), ]); - $this->assertSame($id, $denormalized['uuid']); + if (isset($id)) { + $this->assertSame($id, $denormalized['uuid']); + } + else { + $this->assertArrayNotHasKey('uuid', $denormalized); + } } /** @@ -260,7 +256,8 @@ class JsonApiDocumentTopLevelNormalizerTest extends UnitTestCase { public function denormalizeUuidProvider() { return [ 'valid' => ['76dd5c18-ea1b-4150-9e75-b21958a2b836', FALSE], - 'empty' => ['', TRUE], + 'missing' => [NULL, FALSE], + 'invalid_empty' => ['', TRUE], 'invalid_alpha' => ['invalid', TRUE], 'invalid_numeric' => [1234, TRUE], 'invalid_alphanumeric' => ['abc123', TRUE],