function DateTimeIso8601NormalizerTest::testNormalizeWhenNull

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

@covers ::normalize @dataProvider providerTestNormalize

File

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

Class

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

Namespace

Drupal\Tests\serialization\Unit\Normalizer

Code

public function testNormalizeWhenNull($parent_field_item_class, $datetime_type, $expected_format) : void {
    $field_item = $this->prophesize($parent_field_item_class);
    if ($parent_field_item_class === DateTimeItem::class) {
        $field_storage_definition = $this->prophesize(FieldStorageDefinitionInterface::class);
        $field_storage_definition->getSetting('datetime_type')
            ->willReturn($datetime_type);
        $field_definition = $this->prophesize(FieldDefinitionInterface::class);
        $field_definition->getFieldStorageDefinition()
            ->willReturn($field_storage_definition);
        $field_item->getFieldDefinition()
            ->willReturn($field_definition);
    }
    else {
        $field_item->getFieldDefinition(Argument::any())
            ->shouldNotBeCalled();
    }
    $this->data
        ->getParent()
        ->willReturn($field_item);
    $this->data
        ->getDateTime()
        ->willReturn(NULL);
    $normalized = $this->normalizer
        ->normalize($this->data
        ->reveal());
    $this->assertNull($normalized);
}

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