function DependencyTest::testSerialization
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Extension/DependencyTest.php \Drupal\Tests\Core\Extension\DependencyTest::testSerialization()
- 8.9.x core/tests/Drupal/Tests/Core/Extension/DependencyTest.php \Drupal\Tests\Core\Extension\DependencyTest::testSerialization()
- 11.x core/tests/Drupal/Tests/Core/Extension/DependencyTest.php \Drupal\Tests\Core\Extension\DependencyTest::testSerialization()
Ensures that constraint objects are not serialized.
@covers ::__sleep
File
-
core/
tests/ Drupal/ Tests/ Core/ Extension/ DependencyTest.php, line 54
Class
- DependencyTest
- @coversDefaultClass \Drupal\Core\Extension\Dependency @group Extension
Namespace
Drupal\Tests\Core\ExtensionCode
public function testSerialization() : void {
$dependency = new Dependency('paragraphs_demo', 'paragraphs', '>8.x-1.1');
$this->assertTrue($dependency->isCompatible('1.2'));
$reflected_constraint = (new \ReflectionObject($dependency))->getProperty('constraint');
$constraint = $reflected_constraint->getValue($dependency);
$this->assertInstanceOf(Constraint::class, $constraint);
$dependency = unserialize(serialize($dependency));
$reflected_constraint = (new \ReflectionObject($dependency))->getProperty('constraint');
$constraint = $reflected_constraint->getValue($dependency);
$this->assertNull($constraint);
$this->assertTrue($dependency->isCompatible('1.2'));
$constraint = $reflected_constraint->getValue($dependency);
$this->assertInstanceOf(Constraint::class, $constraint);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.