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

Created on 7 May 2024, 7 months ago
Updated 14 August 2024, 3 months 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

Closed: outdated

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 5 months 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.

  • Status changed to Closed: outdated 3 months ago
  • 🇦🇲Armenia murz Yerevan, Armenia

    Closing due to lack of response.

Production build 0.71.5 2024