function DateTimeIso8601NormalizerTest::testDenormalizeDateOnlyException

Same name in other branches
  1. 9 core/modules/serialization/tests/src/Unit/Normalizer/DateTimeIso8601NormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\DateTimeIso8601NormalizerTest::testDenormalizeDateOnlyException()
  2. 10 core/modules/serialization/tests/src/Unit/Normalizer/DateTimeIso8601NormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\DateTimeIso8601NormalizerTest::testDenormalizeDateOnlyException()
  3. 11.x core/modules/serialization/tests/src/Unit/Normalizer/DateTimeIso8601NormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\DateTimeIso8601NormalizerTest::testDenormalizeDateOnlyException()

Tests the denormalize function with bad data for the date-only case.

@covers ::denormalize

File

core/modules/serialization/tests/src/Unit/Normalizer/DateTimeIso8601NormalizerTest.php, line 233

Class

DateTimeIso8601NormalizerTest
Unit test coverage for the "datetime_iso8601" @DataType.

Namespace

Drupal\Tests\serialization\Unit\Normalizer

Code

public function testDenormalizeDateOnlyException() {
    $this->expectException(UnexpectedValueException::class);
    $this->expectExceptionMessage('The specified date "2016/11/06" is not in an accepted format: "Y-m-d" (date-only).');
    $normalized = '2016/11/06';
    $field_definition = $this->prophesize(FieldDefinitionInterface::class);
    $field_definition->getSetting('datetime_type')
        ->willReturn(DateTimeItem::DATETIME_TYPE_DATE);
    $this->normalizer
        ->denormalize($normalized, DateTimeIso8601::class, NULL, [
        'field_definition' => $field_definition->reveal(),
    ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.