function DependencyTest::testSerialization

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Extension/DependencyTest.php \Drupal\Tests\Core\Extension\DependencyTest::testSerialization()
  2. 10 core/tests/Drupal/Tests/Core/Extension/DependencyTest.php \Drupal\Tests\Core\Extension\DependencyTest::testSerialization()
  3. 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 112

Class

DependencyTest
@coversDefaultClass \Drupal\Core\Extension\Dependency @group Extension

Namespace

Drupal\Tests\Core\Extension

Code

public function testSerialization() {
    $dependency = new Dependency('paragraphs_demo', 'paragraphs', '>8.x-1.1');
    $this->assertTrue($dependency->isCompatible('1.2'));
    $this->assertInstanceOf(Constraint::class, $this->getObjectAttribute($dependency, 'constraint'));
    $dependency = unserialize(serialize($dependency));
    $this->assertNull($this->getObjectAttribute($dependency, 'constraint'));
    $this->assertTrue($dependency->isCompatible('1.2'));
    $this->assertInstanceOf(Constraint::class, $this->getObjectAttribute($dependency, 'constraint'));
}

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