You are here

public function DependencySerializationTest::testSerializationWithMissingService in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/DependencyInjection/DependencySerializationTest.php \Drupal\Tests\Core\DependencyInjection\DependencySerializationTest::testSerializationWithMissingService()
  2. 10 core/tests/Drupal/Tests/Core/DependencyInjection/DependencySerializationTest.php \Drupal\Tests\Core\DependencyInjection\DependencySerializationTest::testSerializationWithMissingService()

@covers ::__sleep @covers ::__wakeup

File

core/tests/Drupal/Tests/Core/DependencyInjection/DependencySerializationTest.php, line 51
Contains \Drupal\Tests\Core\DependencyInjection\DependencySerializationTest.

Class

DependencySerializationTest
@coversDefaultClass \Drupal\Core\DependencyInjection\DependencySerializationTrait @group DependencyInjection

Namespace

Drupal\Tests\Core\DependencyInjection

Code

public function testSerializationWithMissingService() {

  // Create a pseudo service and dependency injected object.
  $service = new \stdClass();
  $service->_serviceId = 'test_service_not_existing';
  $container = new Container();
  $container
    ->set('test_service', $service);
  $container
    ->set('service_container', $container);
  \Drupal::setContainer($container);
  $dependencySerialization = new DependencySerializationTestDummy($service);
  $dependencySerialization
    ->setContainer($container);
  $string = serialize($dependencySerialization);

  /** @var \Drupal\Tests\Core\DependencyInjection\DependencySerializationTestDummy $dependencySerialization */
  $dependencySerialization = unserialize($string);
  $this
    ->assertSame($container, $dependencySerialization->container);
}