You are here

public function DateTimeNormalizerTest::testDenormalizeUserFormats in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/serialization/tests/src/Unit/Normalizer/DateTimeNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\DateTimeNormalizerTest::testDenormalizeUserFormats()

Tests the denormalize function with a user supplied format.

@covers ::denormalize @dataProvider providerTestDenormalizeUserFormats

File

core/modules/serialization/tests/src/Unit/Normalizer/DateTimeNormalizerTest.php, line 142

Class

DateTimeNormalizerTest
Unit test coverage for @DataTypes implementing DateTimeInterface.

Namespace

Drupal\Tests\serialization\Unit\Normalizer

Code

public function testDenormalizeUserFormats($normalized, $format, $expected) {
  $denormalized = $this->normalizer
    ->denormalize($normalized, DateTimeInterface::class, NULL, [
    'datetime_allowed_formats' => [
      $format,
    ],
  ]);
  $this
    ->assertSame(0, $denormalized
    ->getTimestamp() - $expected
    ->getTimestamp());
  $this
    ->assertEquals($expected, $denormalized);
}