Skip to content
Latchkey

Symfony WebTestCase "Booting the kernel ... was already booted" client error in CI

A functional test extending WebTestCase must create its client before booting the kernel any other way. Calling bootKernel() (or self::getContainer() in a way that boots) before createClient() triggers "a kernel has been booted already".

What this error means

A test extending Symfony\Bundle\FrameworkBundle\Test\WebTestCase fails with "LogicException: Booting the kernel before calling ... is not supported, the kernel should only be booted once." or "a kernel has been booted already".

Symfony
LogicException: Booting the kernel before calling
"Symfony\Bundle\FrameworkBundle\Test\WebTestCase::createClient()" is not supported,
the kernel should only be booted once.

Diagnose it: version, extensions, limits

Terminal
php -v && php -m | head -30
php -i | grep -E "memory_limit|max_execution_time"
composer check-platform-reqs 2>/dev/null

Common causes

The kernel was booted before createClient()

Calling bootKernel() or fetching the container in a way that boots the kernel before createClient() leaves WebTestCase unable to create its own client.

createClient() called twice in one test

A second createClient() in the same test method tries to boot again after the first client already booted the kernel.

How to fix it

Create the client first, then get the container from it

  1. Call static::createClient() as the first kernel interaction.
  2. Access services via the client's container ($client->getContainer() or static::getContainer() after createClient).
  3. Do not call bootKernel() in a WebTestCase.
tests/Controller/HomeControllerTest.php
$client = static::createClient();
$em = static::getContainer()->get('doctrine')->getManager();
$client->request('GET', '/');

Ensure the kernel is shut down between tests

Let the base tearDown run so each test boots a fresh kernel and no prior boot leaks in.

tests/Controller/HomeControllerTest.php
protected function tearDown(): void
{
    parent::tearDown(); // shuts down the kernel
}

How to prevent it

  • Call createClient() before any other kernel interaction in a WebTestCase.
  • Fetch services through the test container after creating the client.
  • Do not boot the kernel twice in one test method.

Frequently asked questions

What causes Symfony WebTestCase "Booting the kernel ... was already booted" client error in CI?
There are 2 common causes: the kernel was booted before createclient() and createclient() called twice in one test. Calling bootKernel() or fetching the container in a way that boots the kernel before createClient() leaves WebTestCase unable to create its own client.
How do I fix Symfony WebTestCase "Booting the kernel ... was already booted" client error in CI?
There are 2 fixes depending on which cause you have: create the client first, then get the container from it and ensure the kernel is shut down between tests. Work through them in order, since the first is the most common.
What does Symfony WebTestCase "Booting the kernel ... was already booted" client error in CI actually mean?
A test extending Symfony\Bundle\FrameworkBundle\Test\WebTestCase fails with "LogicException: Booting the kernel before calling ...
How do I stop Symfony WebTestCase "Booting the kernel ... was already booted" client error in CI happening again?
Call createClient() before any other kernel interaction in a WebTestCase. The prevention section lists 3 changes that keep it from recurring.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card