function EntityTypeTest::testIsSerializable

Same name and namespace in other branches
  1. 9 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. 11.x 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 <a href="/api/drupal/core%21lib%21Drupal%21Core%21Entity%21EntityType.php/class/EntityType/8.9.x" title="Provides an implementation of an entity type and its metadata." class="local">\Drupal\Core\Entity\EntityType</a> @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.