You are here

public function EntityTypeTest::testIsSerializable in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php \Drupal\Tests\Core\Entity\EntityTypeTest::testIsSerializable()
  2. 10 core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php \Drupal\Tests\Core\Entity\EntityTypeTest::testIsSerializable()

Tests that the EntityType object can be serialized.

File

core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php, line 515

Class

EntityTypeTest
@coversDefaultClass \Drupal\Core\Entity\EntityType @group Entity

Namespace

Drupal\Tests\Core\Entity

Code

public function testIsSerializable() {
  $entity_type = $this
    ->setUpEntityType([]);
  $translation = $this
    ->prophesize(TranslationInterface::class);
  $translation
    ->willImplement(\Serializable::class);
  $translation
    ->serialize()
    ->willThrow(\Exception::class);
  $translation_service = $translation
    ->reveal();
  $translation_service->_serviceId = 'string_translation';
  $entity_type
    ->setStringTranslation($translation_service);
  $entity_type = unserialize(serialize($entity_type));
  $this
    ->assertEquals('example_entity_type', $entity_type
    ->id());
}