function TestKernel::setContainerWithKernel

Same name in other branches
  1. 9 core/lib/Drupal/Core/Test/TestKernel.php \Drupal\Core\Test\TestKernel::setContainerWithKernel()
  2. 11.x core/lib/Drupal/Core/Test/TestKernel.php \Drupal\Core\Test\TestKernel::setContainerWithKernel()

Sets a container with a kernel service on the Drupal class.

Return value

\Drupal\Component\DependencyInjection\ContainerInterface A container with the kernel service set.

5 calls to TestKernel::setContainerWithKernel()
ConfigEntityBaseUnitTest::testSleepWithPluginCollections in core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php
@covers ::__sleep
ContextHandlerTest::setUp in core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php
DependencySerializationTest::testSerialization in core/tests/Drupal/Tests/Core/DependencyInjection/DependencySerializationTest.php
@covers ::__sleep @covers ::__wakeup
DrupalKernelTest::testGetServiceIdMapping in core/tests/Drupal/Tests/Core/DrupalKernel/DrupalKernelTest.php
@covers ::getServiceIdMapping @group legacy
SharedTempStoreTest::testSerialization in core/tests/Drupal/Tests/Core/TempStore/SharedTempStoreTest.php
Tests the serialization of a shared temp store.

File

core/lib/Drupal/Core/Test/TestKernel.php, line 33

Class

TestKernel
Kernel that is only used by mock front controllers.

Namespace

Drupal\Core\Test

Code

public static function setContainerWithKernel() {
    $container = new ContainerBuilder();
    $kernel = new DrupalKernel('test', NULL);
    // Objects of the same type will have access to each others private and
    // protected members even though they are not the same instances. This is
    // because the implementation specific details are already known when
    // inside those objects.
    $kernel->container = $container;
    $container->set('kernel', $kernel);
    $container->set(ReverseContainer::class, new ReverseContainer($container));
    \Drupal::setContainer($container);
    return $container;
}

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