function EntityTypeTest::testIsSerializable

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Entity/EntityTypeTest.php \Drupal\KernelTests\Core\Entity\EntityTypeTest::testIsSerializable()
  2. 10 core/tests/Drupal/KernelTests/Core/Entity/EntityTypeTest.php \Drupal\KernelTests\Core\Entity\EntityTypeTest::testIsSerializable()
  3. 9 core/tests/Drupal/KernelTests/Core/Entity/EntityTypeTest.php \Drupal\KernelTests\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[[api-linebreak]] @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());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.