/**
  * @covers ::normalize
  */
 public function testNormalizeWithNoEntity()
 {
     $entity_reference = $this->prophesize(TypedDataInterface::class);
     $entity_reference->getValue()->willReturn(NULL)->shouldBeCalled();
     $this->fieldItem->get('entity')->willReturn($entity_reference->reveal())->shouldBeCalled();
     $normalized = $this->normalizer->normalize($this->fieldItem->reveal());
     $expected = ['target_id' => ['value' => 'test']];
     $this->assertSame($expected, $normalized);
 }
 public function normalize($field_item, $format = NULL, array $context = array())
 {
     $values = parent::normalize($field_item, $format, $context);
     if (($entity = $field_item->get('entity')->getValue()) && $entity->url('canonical')) {
         $values['target_id'] = $entity->id();
         if (!is_null($entity->name) && $entity->name->value) {
             $values['name'] = $entity->name->value;
         }
     }
     return $values;
 }