Get the referred entities.
\Drupal\Core\Entity\ContentEntityInterface $entity: The parent entity.
string $field_name: The name of the entity revision reference field.
int $expected_count: The expected number of the referenced entities.
\Drupal\Core\Entity\EntityInterface[] An array of entity objects keyed by field item deltas.
protected function getReferencedEntities(ContentEntityInterface $entity, $field_name, int $expected_count) {
$entity_field = $entity
->hasField($field_name) ? $entity
->get($field_name) : NULL;
assert($entity_field instanceof EntityReferenceRevisionsFieldItemList);
$entity_field_entities = $entity_field
->referencedEntities();
$this
->assertCount($expected_count, $entity_field_entities);
return $entity_field_entities;
}