function EntityTypeTest::testIsSerializable
Same name in other branches
- 8.9.x core/tests/Drupal/Tests/Core/Entity/EntityTypeTest.php \Drupal\Tests\Core\Entity\EntityTypeTest::testIsSerializable()
- 10 core/tests/Drupal/KernelTests/Core/Entity/EntityTypeTest.php \Drupal\KernelTests\Core\Entity\EntityTypeTest::testIsSerializable()
- 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/ KernelTests/ Core/ Entity/ EntityTypeTest.php, line 34
Class
- EntityTypeTest
- Tests general features of entity types.
Namespace
Drupal\KernelTests\Core\EntityCode
public function testIsSerializable() {
$entity_type = $this->setUpEntityType([]);
$translation_service = new class extends TranslationManager {
/**
* Constructs a UnserializableTranslationManager object.
*/
public function __construct() {
}
/**
* @return array
*/
public function __serialize() : array {
throw new \Exception();
}
};
$this->container
->set('bar', $translation_service);
$entity_type->setStringTranslation($this->container
->get('string_translation'));
// This should not throw an exception.
$tmp = serialize($entity_type);
$entity_type = unserialize($tmp);
// And this should have the correct id.
$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.