Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. TestKernel.php

function 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.

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal