Call to undefined method Drupal\Core\Entity\EntityTypeManager::stubGetOrCreateStorage()

Created on 7 May 2024, about 2 months ago
Updated 21 June 2024, 7 days ago

Problem/Motivation

When trying to create a new entity within a test I get this error:
Call to undefined method Drupal\Core\Entity\EntityTypeManager::stubGetOrCreateStorage()

    $node = TestHelpers::saveEntity(Node::class, [
      'type' => 'van_booking',
      'title' => 'New van booking',
      'status' => 1,
      'uid' => 1,
      'created' => 1672574400,
      'field_notes' => 'Testing notes'
      ]);

I don't understand why it is using Drupal\Core\Entity\EntityTypeManager instead of Drupal\test_helpers\Stub\EntityTypeManagerStub

πŸ’¬ Support request
Status

Postponed: needs info

Version

1.3

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom Alina Basarabeanu

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Alina Basarabeanu
  • Status changed to Postponed: needs info 7 days ago
  • πŸ‡¦πŸ‡²Armenia Murz Yerevan, Armenia

    Seems this happens because the 'entity_type.manager' is already initiated somewhere with the Drupal Core class, instead of the TestHelpers stub.
    Try to add this line at the very start of your unit test:

    \Drupal::service('entity_type.manager');
    

    It should initiate the TestHelpers stub.

Production build 0.69.0 2024