You are here

protected function EntityReferenceFieldItemNormalizerTest::setUp 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::setUp()
  2. 9 core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\EntityReferenceFieldItemNormalizerTest::setUp()

Overrides UnitTestCase::setUp

File

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

Class

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

Namespace

Drupal\Tests\serialization\Unit\Normalizer

Code

protected function setUp() : void {
  $this->entityRepository = $this
    ->prophesize(EntityRepositoryInterface::class);
  $this->normalizer = new EntityReferenceFieldItemNormalizer($this->entityRepository
    ->reveal());
  $this->serializer = $this
    ->prophesize(Serializer::class);

  // Set up the serializer to return an entity property.
  $this->serializer
    ->normalize(Argument::cetera())
    ->willReturn('test');
  $this->normalizer
    ->setSerializer($this->serializer
    ->reveal());
  $this->fieldItem = $this
    ->prophesize(EntityReferenceItem::class);
  $this->fieldItem
    ->getIterator()
    ->willReturn(new \ArrayIterator([
    'target_id' => [],
  ]));
  $this->fieldDefinition = $this
    ->prophesize(FieldDefinitionInterface::class);
  $this->fieldDefinition
    ->getItemDefinition()
    ->willReturn($this
    ->prophesize(FieldItemDataDefinition::class)
    ->reveal());
}