$ref1->
save();
$ref2 = EntityTest::
create(['name' => 'baz', 'type' => 'bar'
]);
$ref2->
save();
\Drupal::
state()->
set('entity_test_reference_computed_target_ids',
[$ref1->
id(),
$ref2->
id()]);
$entity = EntityTestComputedField::
create([]);
$entity->
save();
/** @var \Drupal\entity_test\Plugin\Field\ComputedReferenceTestFieldItemList $field */
$field =
$entity->
get('computed_reference_field'
);
/** @var \Drupal\Core\Entity\EntityInterface[] $referenced_entities */
$referenced_entities =
$field->
referencedEntities();
// Check that ::referencedEntities() is working with computed fields.
$this->
assertEquals($ref1->
id(),
$referenced_entities[0
]->
id());
$this->
assertEquals($ref2->
id(),
$referenced_entities[1
]->
id());
} /**
* Executes the computed properties tests for the given entity type.
*
* @param string $entity_type
* The entity type to run the tests with.
*/