You are here

protected function CartResourceTestBase::createEntity in Commerce Cart API 8

Creates a new entity.

Parameters

string $entity_type: The entity type to be created.

array $values: An array of settings. Example: 'id' => 'foo'.

Return value

\Drupal\Core\Entity\EntityInterface A new entity.

2 calls to CartResourceTestBase::createEntity()
CartAccessApiResourceTest::testInvalidCart in tests/src/Functional/CartAccessApiResourceTest.php
Check no access for non-draft/non-cart cart.
CartResourceTestBase::setUp in tests/src/Functional/CartResourceTestBase.php

File

tests/src/Functional/CartResourceTestBase.php, line 178

Class

CartResourceTestBase
Defines base class for commerce_cart_api test cases.

Namespace

Drupal\Tests\commerce_cart_api\Functional

Code

protected function createEntity($entity_type, array $values) {

  /** @var \Drupal\Core\Entity\EntityStorageInterface $storage */
  $storage = \Drupal::service('entity_type.manager')
    ->getStorage($entity_type);
  $entity = $storage
    ->create($values);
  $status = $entity
    ->save();

  // The newly saved entity isn't identical to a loaded one, and would fail
  // comparisons.
  $entity = $storage
    ->load($entity
    ->id());
  return $entity;
}