protected function createContainerBuilder()
    {
        $builder = new ContainerBuilder();
        $this->kernel->boot();
        foreach ($this->kernel->getBundles() as $bundle) {
            // Register all extensions, otherwise there might be config parts that cannot be processed.
            $extension = $bundle->getContainerExtension();
            if ($extension !== null) {
                $builder->registerExtension($extension);
            }
        }
        // Load the application configuration, which might affect the loaded services.
        /* @var $locator FileLocatorInterface */
        $locator = $this->kernel->getContainer()->get('file_locator');
        $loaders = array(
            new XmlFileLoader($builder, $locator),
            new YamlFileLoader($builder, $locator),
            new IniFileLoader($builder, $locator),
            new PhpFileLoader($builder, $locator),
            (class_exists(DirectoryLoader::class) ? new DirectoryLoader($builder, $locator) : null),
            new ClosureLoader($builder),
        );
        $loaders = array_filter($loaders);
        $resolver = new LoaderResolver($loaders);
        $loader = new DelegatingLoader($resolver);
        $this->kernel->registerContainerConfiguration($loader);
        return $builder;
    }