You are here

protected function EntityReferenceFieldItemNormalizerTest::assertDenormalize in Drupal 10

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

Asserts denormalization process is correct for give data.

@internal

Parameters

array $data: The data to denormalize.

7 calls to EntityReferenceFieldItemNormalizerTest::assertDenormalize()
EntityReferenceFieldItemNormalizerTest::testConstructValueProperties in core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php
@covers ::constructValue
EntityReferenceFieldItemNormalizerTest::testDenormalizeWithEmptyUuid in core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php
@covers ::denormalize
EntityReferenceFieldItemNormalizerTest::testDenormalizeWithId in core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php
@covers ::denormalize
EntityReferenceFieldItemNormalizerTest::testDenormalizeWithTypeAndUuid in core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php
@covers ::denormalize
EntityReferenceFieldItemNormalizerTest::testDenormalizeWithTypeWithIncorrectUuid in core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php
@covers ::denormalize

... See full list

File

core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php, line 433

Class

EntityReferenceFieldItemNormalizerTest
@coversDefaultClass \Drupal\serialization\Normalizer\EntityReferenceFieldItemNormalizer @group serialization

Namespace

Drupal\Tests\serialization\Unit\Normalizer

Code

protected function assertDenormalize(array $data) : void {
  $this->fieldItem
    ->getParent()
    ->willReturn($this
    ->prophesize(FieldItemListInterface::class)
    ->reveal());
  $this->fieldItem
    ->getFieldDefinition()
    ->willReturn($this->fieldDefinition
    ->reveal());
  if (!empty($data['target_uuid'])) {
    $this->fieldDefinition
      ->getSetting('target_type')
      ->willReturn('test_type')
      ->shouldBeCalled();
  }

  // Avoid a static method call by returning dummy serialized property data.
  $this->fieldDefinition
    ->getFieldStorageDefinition()
    ->willReturn()
    ->shouldBeCalled();
  $this->fieldDefinition
    ->getName()
    ->willReturn('field_reference')
    ->shouldBeCalled();
  $entity = $this
    ->prophesize(EntityInterface::class);
  $entity_type = $this
    ->prophesize(EntityTypeInterface::class);
  $entity
    ->getEntityType()
    ->willReturn($entity_type
    ->reveal())
    ->shouldBeCalled();
  $this->fieldItem
    ->getPluginDefinition()
    ->willReturn([
    'serialized_property_names' => [
      'foo' => 'bar',
    ],
  ])
    ->shouldBeCalled();
  $this->fieldItem
    ->getEntity()
    ->willReturn($entity
    ->reveal())
    ->shouldBeCalled();
  $context = [
    'target_instance' => $this->fieldItem
      ->reveal(),
  ];
  $denormalized = $this->normalizer
    ->denormalize($data, EntityReferenceItem::class, 'json', $context);
  $this
    ->assertSame($context['target_instance'], $denormalized);
}