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. 10 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 72

Class

EntityReferenceFieldItemNormalizerTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21serialization%21src%21Normalizer%21EntityReferenceFieldItemNormalizer.php/class/EntityReferenceFieldItemNormalizer/8.9.x" title="Adds the file URI to embedded file entities." class="local">\Drupal\serialization\Normalizer\EntityReferenceFieldItemNormalizer</a> @group serialization

Namespace

Drupal\Tests\serialization\Unit\Normalizer

Code

protected function 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.