public function EntityReferenceFieldItemNormalizerTest::testNormalizeWithNoEntity in Drupal 10
Same name and namespace in other branches
- 8 core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\EntityReferenceFieldItemNormalizerTest::testNormalizeWithNoEntity()
- 9 core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\EntityReferenceFieldItemNormalizerTest::testNormalizeWithNoEntity()
@covers ::normalize
File
- core/modules/ serialization/ tests/ src/ Unit/ Normalizer/ EntityReferenceFieldItemNormalizerTest.php, line 266 
Class
- EntityReferenceFieldItemNormalizerTest
- @coversDefaultClass \Drupal\serialization\Normalizer\EntityReferenceFieldItemNormalizer @group serialization
Namespace
Drupal\Tests\serialization\Unit\NormalizerCode
public function testNormalizeWithNoEntity() {
  $entity_reference = $this
    ->prophesize(TypedDataInterface::class);
  $entity_reference
    ->getValue()
    ->willReturn(NULL)
    ->shouldBeCalled();
  $field_definition = $this
    ->prophesize(FieldDefinitionInterface::class);
  $field_definition
    ->getSetting('target_type')
    ->willReturn('test_type');
  $this->fieldItem
    ->getFieldDefinition()
    ->willReturn($field_definition
    ->reveal());
  $this->fieldItem
    ->get('entity')
    ->willReturn($entity_reference
    ->reveal())
    ->shouldBeCalled();
  $this->fieldItem
    ->getProperties(TRUE)
    ->willReturn([
    'target_id' => $this
      ->getTypedDataProperty(FALSE),
  ])
    ->shouldBeCalled();
  $normalized = $this->normalizer
    ->normalize($this->fieldItem
    ->reveal());
  $expected = [
    'target_id' => 'test',
  ];
  $this
    ->assertSame($expected, $normalized);
}