You are here

public function ExtensionSerializationTest::testPublicProperties in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Extension/ExtensionSerializationTest.php \Drupal\Tests\Core\Extension\ExtensionSerializationTest::testPublicProperties()
  2. 10 core/tests/Drupal/Tests/Core/Extension/ExtensionSerializationTest.php \Drupal\Tests\Core\Extension\ExtensionSerializationTest::testPublicProperties()

Tests dynamically assigned public properties kept when serialized.

@covers ::__sleep @covers ::__wakeup

File

core/tests/Drupal/Tests/Core/Extension/ExtensionSerializationTest.php, line 73

Class

ExtensionSerializationTest
Tests Extension serialization.

Namespace

Drupal\Tests\Core\Extension

Code

public function testPublicProperties() {
  $container = new ContainerBuilder();

  // Set a dummy container app.root to test against.
  $container
    ->setParameter('app.root', 'vfs://dummy_app_root');
  \Drupal::setContainer($container);
  $extension = new Extension($container
    ->getParameter('app.root'), 'module', 'core/modules/system/system.info.yml', 'system.module');

  // Assign a public property dynamically.
  $extension->test = 'foo';
  $extension = unserialize(serialize($extension));
  $this
    ->assertSame('foo', $extension->test);
}