function ExtensionSerializationTest::testPublicProperties

Same name in other branches
  1. 9 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()
  3. 11.x 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 65

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->set('app.root', 'vfs://dummy_app_root');
    \Drupal::setContainer($container);
    $extension = new Extension($container->get('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);
}

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