You are here

public function EntityUnitTest::testCreate in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php \Drupal\Tests\Core\Entity\EntityUnitTest::testCreate()
  2. 9 core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php \Drupal\Tests\Core\Entity\EntityUnitTest::testCreate()

@covers ::create

File

core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php, line 314

Class

EntityUnitTest
@coversDefaultClass \Drupal\Core\Entity\EntityBase @group Entity @group Access

Namespace

Drupal\Tests\Core\Entity

Code

public function testCreate() {
  $this
    ->setupTestLoad();
  $class_name = get_class($this->entity);
  $entity_type_repository = $this
    ->getMockForAbstractClass(EntityTypeRepositoryInterface::class);
  $entity_type_repository
    ->expects($this
    ->once())
    ->method('getEntityTypeFromClass')
    ->with($class_name)
    ->willReturn($this->entityTypeId);
  $storage = $this
    ->createMock(EntityStorageInterface::class);
  $storage
    ->expects($this
    ->once())
    ->method('create')
    ->with([])
    ->will($this
    ->returnValue($this->entity));
  $this->entityTypeManager
    ->expects($this
    ->once())
    ->method('getStorage')
    ->with($this->entityTypeId)
    ->will($this
    ->returnValue($storage));
  \Drupal::getContainer()
    ->set('entity_type.repository', $entity_type_repository);

  // Call Entity::create() statically and check that it returns the mock
  // entity.
  $this
    ->assertSame($this->entity, $class_name::create([]));
}