function DependencySerializationTest::testSerializationWithoutReverseContainer
@covers ::__sleep @covers ::__wakeup
File
-
core/
tests/ Drupal/ Tests/ Core/ DependencyInjection/ DependencySerializationTest.php, line 52
Class
- DependencySerializationTest
- @coversDefaultClass \Drupal\Core\DependencyInjection\DependencySerializationTrait @group DependencyInjection
Namespace
Drupal\Tests\Core\DependencyInjectionCode
public function testSerializationWithoutReverseContainer() {
$container = new ContainerBuilder();
\Drupal::setContainer($container);
// Create a pseudo service and dependency injected object.
$service = new \stdClass();
$container->set('test_service', $service);
$this->assertSame($container, $container->get('service_container'));
$dependencySerialization = new DependencySerializationTestDummy($service);
$dependencySerialization->setContainer($container);
$string = serialize($dependencySerialization);
/** @var \Drupal\Tests\Core\DependencyInjection\DependencySerializationTestDummy $dependencySerialization */
$dependencySerialization = unserialize($string);
$this->assertFalse($container->has(ReverseContainer::class));
$this->assertSame($service, $dependencySerialization->service);
$this->assertSame($container, $dependencySerialization->container);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.