You are here

public function DependencyTest::testSerialization in Drupal 8

Same name and namespace 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()

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'));
}