function EntityReferenceFieldItemNormalizerTest::setUp

Same name and namespace in other branches
  1. 9 core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\EntityReferenceFieldItemNormalizerTest::setUp()
  2. 8.9.x core/modules/serialization/tests/src/Unit/Normalizer/EntityReferenceFieldItemNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\EntityReferenceFieldItemNormalizerTest::setUp()
  3. 11.x 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 74

Class

EntityReferenceFieldItemNormalizerTest
@coversDefaultClass \Drupal\serialization\Normalizer\EntityReferenceFieldItemNormalizer[[api-linebreak]] @group serialization

Namespace

Drupal\Tests\serialization\Unit\Normalizer

Code

protected function setUp() : void {
  parent::setUp();
  $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());
}

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