Repository: symfony/symfony
File: src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php (PHP)

Code before:
        }

        if (!class_exists($class = $_ENV['KERNEL_CLASS'] ?? $_SERVER['KERNEL_CLASS'])) {
            throw new \RuntimeException(\sprintf('Class "%s" doesn\'t exist or cannot be autoloaded. Check that the KERNEL_CLASS value in phpunit.xml matches the fully-qualified class name of your Kernel or override the "%s::createKernel()" method.', $class, static::class));
        }

        return $class;
    }

    /**
     * Boots the Kernel for this test.
     */
    protected static function bootKernel(array $options = []): KernelInterface
    {
        static::ensureKernelShutdown();

        $kernel = static::createKernel($options);
        $kernel->boot();
        static::$kernel = $kernel;
        static::$booted = true;

        // If the cache warmer is registered, it means that the cache has been
        // warmed up, so the current container is not fresh anymore. Let's
        // reboot a fresh one.
        if (self::getContainer()->initialized('cache_warmer')) {
            return static::bootKernel($options);
        }

        return static::$kernel;
    }

    /**
     * Provides a dedicated test container with access to both public and private
     * services. The container will not include private services that have been
     * inlined or removed. Private services will be removed when they are not
     * used by other services.
     *
     * Using this method is the best way to get a container from your test code.
     *
     * @return Container
     */
    protected static function getContainer(): ContainerInterface
    {
        if (!static::$booted) {
            static::bootKernel();
        }

        try {
            return self::$kernel->getContainer()->get('test.service_container');
        } catch (ServiceNotFoundException $e) {
            throw new \LogicException('Could not find service "test.service_container". Try updating the "framework.test" config to "true".', 0, $e);

Review comment (bug):
is it sure that there will be never a case where `cache_warmer` would be initialized each time on boot and then do a infinite loop here ? i'm not sure if this is possible, but if it can it will be hard to debug when it happens (because it will probably segfault)

Maybe adding an extra parameter so that we cannot do more than 2 recursive call would be nice IMO

Code after:
        }

        if (!class_exists($class = $_ENV['KERNEL_CLASS'] ?? $_SERVER['KERNEL_CLASS'])) {
            throw new \RuntimeException(\sprintf('Class "%s" doesn\'t exist or cannot be autoloaded. Check that the KERNEL_CLASS value in phpunit.xml matches the fully-qualified class name of your Kernel or override the "%s::createKernel()" method.', $class, static::class));
        }

        return $class;
    }

    /**
     * Boots the Kernel for this test.
     */
    protected static function bootKernel(array $options = []): KernelInterface
    {
        static::ensureKernelShutdown();

        $kernel = static::createKernel($options);
        $kernel->boot();
        static::$kernel = $kernel;
        static::$booted = true;

        // If the cache warmer is registered, it means that the cache has been
        // warmed up, so the current container is not fresh anymore. Let's
        // reboot a fresh one.
        if (self::getContainer()->initialized('cache_warmer')) {
            static::ensureKernelShutdown();

            $kernel = static::createKernel($options);
            $kernel->boot();
            static::$kernel = $kernel;
            static::$booted = true;
        }

        return static::$kernel;
    }

    /**
     * Provides a dedicated test container with access to both public and private
     * services. The container will not include private services that have been
     * inlined or removed. Private services will be removed when they are not
     * used by other services.
     *
     * Using this method is the best way to get a container from your test code.
     *
     * @return Container
     */
    protected static function getContainer(): ContainerInterface
    {
        if (!static::$booted) {
            static::bootKernel();
        }