ExtensionSerializationTest.php in Drupal 8
File
core/tests/Drupal/Tests/Core/Extension/ExtensionSerializationTest.php
View source
<?php
namespace Drupal\Tests\Core\Extension;
use Drupal\Tests\UnitTestCase;
use Drupal\Core\Extension\Extension;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use org\bovigo\vfs\vfsStream;
class ExtensionSerializationTest extends UnitTestCase {
protected function setUp() {
parent::setUp();
vfsStream::setup('dummy_app_root');
vfsStream::create([
'core' => [
'modules' => [
'system' => [
'system.info.yml' => file_get_contents($this->root . '/core/modules/system/system.info.yml'),
],
],
],
]);
}
public function testServiceAppRouteUsage() {
$this
->assertFalse(defined('DRUPAL_ROOT'), 'Constant DRUPAL_ROOT is defined.');
$container = new ContainerBuilder();
$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');
$extension = unserialize(serialize($extension));
$this
->assertEquals('vfs://dummy_app_root', $this
->readAttribute($extension, 'root'));
}
public function testPublicProperties() {
$container = new ContainerBuilder();
$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');
$extension->test = 'foo';
$extension = unserialize(serialize($extension));
$this
->assertSame('foo', $extension->test);
}
}