.../serialization/src/Normalizer/DateTimeNormalizer.php | 6 +++--- .../serialization/src/Normalizer/TimestampItemNormalizer.php | 2 +- .../serialization/src/Normalizer/TimestampNormalizer.php | 2 +- .../src/Unit/Normalizer/DateTimeIso8601NormalizerTest.php | 6 ++---- .../tests/src/Unit/Normalizer/DateTimeNormalizerTest.php | 10 +++------- .../tests/src/Unit/Normalizer/TimestampItemNormalizerTest.php | 8 +++----- .../tests/src/Unit/Normalizer/TimestampNormalizerTest.php | 8 +++----- 7 files changed, 16 insertions(+), 26 deletions(-) diff --git a/core/modules/serialization/src/Normalizer/DateTimeNormalizer.php b/core/modules/serialization/src/Normalizer/DateTimeNormalizer.php index ab56714..59ca022 100644 --- a/core/modules/serialization/src/Normalizer/DateTimeNormalizer.php +++ b/core/modules/serialization/src/Normalizer/DateTimeNormalizer.php @@ -76,7 +76,7 @@ public function denormalize($data, $class, $format = NULL, array $context = []) // First check for a provided format, and if provided, create \DateTime // object using it. if (!empty($context['datetime_format'])) { - return \DateTime::createFromFormat($context['datetime_format'], $data['value']); + return \DateTime::createFromFormat($context['datetime_format'], $data); } // Loop through the allowed formats and create a \DateTime from the @@ -84,7 +84,7 @@ public function denormalize($data, $class, $format = NULL, array $context = []) // unambiguous (i.e., they reference an absolute time with a defined time // zone), only one will ever match. foreach ($this->allowedFormats as $format) { - $date = \DateTime::createFromFormat($format, $data['value']); + $date = \DateTime::createFromFormat($format, $data); if ($date !== FALSE) { return $date; } @@ -97,7 +97,7 @@ public function denormalize($data, $class, $format = NULL, array $context = []) } $formats = implode(', ', $format_strings); - throw new UnexpectedValueException(sprintf('The specified date "%s" is not in an accepted format: %s.', $data['value'], $formats)); + throw new UnexpectedValueException(sprintf('The specified date "%s" is not in an accepted format: %s.', $data, $formats)); } } diff --git a/core/modules/serialization/src/Normalizer/TimestampItemNormalizer.php b/core/modules/serialization/src/Normalizer/TimestampItemNormalizer.php index 23c32ab..cf0f8ac 100644 --- a/core/modules/serialization/src/Normalizer/TimestampItemNormalizer.php +++ b/core/modules/serialization/src/Normalizer/TimestampItemNormalizer.php @@ -41,7 +41,7 @@ protected function constructValue($data, $context) { if (!empty($data['format'])) { $context['datetime_format'] = $data['format']; } - return $this->serializer->denormalize($data, Timestamp::class, NULL, $context); + return ['value' => $this->serializer->denormalize($data['value'], Timestamp::class, NULL, $context)]; } } diff --git a/core/modules/serialization/src/Normalizer/TimestampNormalizer.php b/core/modules/serialization/src/Normalizer/TimestampNormalizer.php index e4638d2..9be4d6e 100644 --- a/core/modules/serialization/src/Normalizer/TimestampNormalizer.php +++ b/core/modules/serialization/src/Normalizer/TimestampNormalizer.php @@ -41,7 +41,7 @@ protected function getNormalizationTimezone() { */ public function denormalize($data, $class, $format = NULL, array $context = []) { $denormalized = parent::denormalize($data, $class, $format, $context); - return ['value' => $denormalized->getTimestamp()]; + return $denormalized->getTimestamp(); } } diff --git a/core/modules/serialization/tests/src/Unit/Normalizer/DateTimeIso8601NormalizerTest.php b/core/modules/serialization/tests/src/Unit/Normalizer/DateTimeIso8601NormalizerTest.php index e22b2155..9a63d3d 100644 --- a/core/modules/serialization/tests/src/Unit/Normalizer/DateTimeIso8601NormalizerTest.php +++ b/core/modules/serialization/tests/src/Unit/Normalizer/DateTimeIso8601NormalizerTest.php @@ -157,9 +157,7 @@ public function providerTestNormalize() { * @covers ::denormalize * @dataProvider providerTestDenormalizeValidFormats */ - public function testDenormalizeValidFormats($value, $expected) { - $normalized = ['value' => $value]; - + public function testDenormalizeValidFormats($normalized, $expected) { $denormalized = $this->normalizer->denormalize($normalized, DateTimeIso8601::class, NULL, []); $this->assertInstanceOf(\DateTime::class, $denormalized); $this->assertEquals('UTC', $denormalized->getTimezone()->getName()); @@ -186,7 +184,7 @@ public function providerTestDenormalizeValidFormats() { public function testDenormalizeException() { $this->setExpectedException(UnexpectedValueException::class, 'The specified date "2016/11/06" is not in an accepted format: "Y-m-d" (date-only).'); - $normalized = ['value' => '2016/11/06']; + $normalized = '2016/11/06'; $this->normalizer->denormalize($normalized, DateTimeIso8601::class, NULL, []); } diff --git a/core/modules/serialization/tests/src/Unit/Normalizer/DateTimeNormalizerTest.php b/core/modules/serialization/tests/src/Unit/Normalizer/DateTimeNormalizerTest.php index 3c98aec..f37f75d 100644 --- a/core/modules/serialization/tests/src/Unit/Normalizer/DateTimeNormalizerTest.php +++ b/core/modules/serialization/tests/src/Unit/Normalizer/DateTimeNormalizerTest.php @@ -100,9 +100,7 @@ public function testNormalize() { * @covers ::denormalize * @dataProvider providerTestDenormalizeValidFormats */ - public function testDenormalizeValidFormats($value, $expected) { - $normalized = ['value' => $value]; - + public function testDenormalizeValidFormats($normalized, $expected) { $denormalized = $this->normalizer->denormalize($normalized, DateTimeInterface::class, NULL, []); $this->assertSame(0, $denormalized->getTimestamp() - $expected->getTimestamp()); $this->assertEquals($expected, $denormalized); @@ -133,9 +131,7 @@ public function providerTestDenormalizeValidFormats() { * @covers ::denormalize * @dataProvider providerTestDenormalizeUserFormats */ - public function testDenormalizeUserFormats($value, $format, $expected) { - $normalized = ['value' => $value]; - + public function testDenormalizeUserFormats($normalized, $format, $expected) { $denormalized = $this->normalizer->denormalize($normalized, DateTimeInterface::class, NULL, ['datetime_format' => $format]); $this->assertSame(0, $denormalized->getTimestamp() - $expected->getTimestamp()); $this->assertEquals($expected, $denormalized); @@ -164,7 +160,7 @@ public function providerTestDenormalizeUserFormats() { public function testDenormalizeException() { $this->setExpectedException(UnexpectedValueException::class, 'The specified date "2016/11/06 09:02am GMT" is not in an accepted format: "Y-m-d\TH:i:sP" (RFC 3339), "Y-m-d\TH:i:sO" (ISO 8601).'); - $normalized = ['value' => '2016/11/06 09:02am GMT']; + $normalized = '2016/11/06 09:02am GMT'; $this->normalizer->denormalize($normalized, DateTimeInterface::class, NULL, []); } diff --git a/core/modules/serialization/tests/src/Unit/Normalizer/TimestampItemNormalizerTest.php b/core/modules/serialization/tests/src/Unit/Normalizer/TimestampItemNormalizerTest.php index 626b766..8575501 100644 --- a/core/modules/serialization/tests/src/Unit/Normalizer/TimestampItemNormalizerTest.php +++ b/core/modules/serialization/tests/src/Unit/Normalizer/TimestampItemNormalizerTest.php @@ -112,14 +112,12 @@ public function testDenormalize() { 'value' => $this->randomMachineName(), 'format' => \DateTime::RFC3339, ]; - $timestamp_data_denormalization = [ - 'value' => $this->randomMachineName(), - ]; + $timestamp_data_denormalization = $this->randomMachineName(); $timestamp_item = $this->createTimestampItemProphecy(); // The field item should get the Timestamp @DataType denormalization set as // a value, in FieldItemNormalizer::denormalize(). - $timestamp_item->setValue($timestamp_data_denormalization) + $timestamp_item->setValue(['value' => $timestamp_data_denormalization]) ->shouldBeCalled(); $context = [ @@ -132,7 +130,7 @@ public function testDenormalize() { $serializer_prophecy = $this->prophesize(Serializer::class); // This is where \Drupal\serialization\Normalizer\TimestampNormalizer would // be called. - $serializer_prophecy->denormalize($timestamp_item_normalization, Timestamp::class, NULL, $context) + $serializer_prophecy->denormalize($timestamp_item_normalization['value'], Timestamp::class, NULL, $context) ->willReturn($timestamp_data_denormalization) ->shouldBeCalled(); diff --git a/core/modules/serialization/tests/src/Unit/Normalizer/TimestampNormalizerTest.php b/core/modules/serialization/tests/src/Unit/Normalizer/TimestampNormalizerTest.php index d96f9a8..a2a8130 100644 --- a/core/modules/serialization/tests/src/Unit/Normalizer/TimestampNormalizerTest.php +++ b/core/modules/serialization/tests/src/Unit/Normalizer/TimestampNormalizerTest.php @@ -88,11 +88,9 @@ public function testNormalize() { * @covers ::denormalize * @dataProvider providerTestDenormalizeValidFormats */ - public function testDenormalizeValidFormats($value, $expected) { - $normalized = ['value' => $value]; - + public function testDenormalizeValidFormats($normalized, $expected) { $denormalized = $this->normalizer->denormalize($normalized, Timestamp::class, NULL, []); - $this->assertSame(['value' => $expected], $denormalized); + $this->assertSame($expected, $denormalized); } /** @@ -125,7 +123,7 @@ public function providerTestDenormalizeValidFormats() { public function testDenormalizeException() { $this->setExpectedException(UnexpectedValueException::class, 'The specified date "2016/11/06 09:02am GMT" is not in an accepted format: "U" (UNIX timestamp), "Y-m-d\TH:i:sO" (ISO 8601), "Y-m-d\TH:i:sP" (RFC 3339).'); - $normalized = ['value' => '2016/11/06 09:02am GMT']; + $normalized = '2016/11/06 09:02am GMT'; $this->normalizer->denormalize($normalized, Timestamp::class, NULL, []); }