You are here

protected function CommerceRecurringSubscriptionLifecycleTest::createEntity in Commerce License 8.2

Creates and saves 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, saved entity.

1 call to CommerceRecurringSubscriptionLifecycleTest::createEntity()
CommerceRecurringSubscriptionLifecycleTest::setUp in tests/src/Kernel/CommerceRecurringSubscriptionLifecycleTest.php

File

tests/src/Kernel/CommerceRecurringSubscriptionLifecycleTest.php, line 283

Class

CommerceRecurringSubscriptionLifecycleTest
Tests Commerce Recurring's subscription lifecycle with a license.

Namespace

Drupal\Tests\commerce_license\Kernel

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();
  $this
    ->assertEquals(SAVED_NEW, $status, new FormattableMarkup('Created %label entity %type.', [
    '%label' => $entity
      ->getEntityType()
      ->getLabel(),
    '%type' => $entity
      ->id(),
  ]));

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