You are here

protected function CommerceProductBundleKernelTestBase::createEntity in Commerce Product Bundle 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.

Throws

\Drupal\Core\Entity\EntityStorageException

1 call to CommerceProductBundleKernelTestBase::createEntity()
CommerceProductBundleItemTest::testVariationsAndProductMethods in tests/src/Kernel/Entity/CommerceProductBundleItemTest.php
Test the setters, getters and valdiation methods around the reference product and variations.

File

tests/src/Kernel/CommerceProductBundleKernelTestBase.php, line 93

Class

CommerceProductBundleKernelTestBase
Provides a base class for Commerce Product Bundle tests.

Namespace

Drupal\Tests\commerce_product_bundle\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;
}