Description
Symfony version(s) affected: 4.2.0-beta2
Description
In Symfony 4.2.0-beta2, it is not possible anymore to boot the kernel from an anonymous class. Having an anonymous kernel class can be helpful for functional tests on bundles, if one were to test if a bundle produces the correct services for a given configuration.
How to reproduce
Initialize a new project with http-kernel
, debug
and framework-bundle
. Run the following script:
<?php
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Debug\Debug;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
require __DIR__.'/vendor/autoload.php';
Debug::enable();
$kernel = new class('prod', false) extends Kernel {
public function registerBundles()
{
return [new FrameworkBundle()];
}
/**
* Loads the container configuration.
*/
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(function (ContainerBuilder $container) use ($loader) {
$container->loadFromExtension('framework', [
'secret' => 'foo',
]);
});
}
public function getRootDir()
{
if (!$this->rootDir) {
$this->rootDir = __DIR__.'/temp';
}
return parent::getRootDir();
}
};
$kernel->boot();
With Symfony 4.1, this produces a dumped container inside the tmp
subdirectory.
With Symfony 4.2, this produces the following error:
PHP Fatal error: Uncaught ErrorException: Warning: is_file() expects parameter 1 to be a valid path, string given in <dir>/vendor/symfony/config/ConfigCache.php:56
Stack trace:
#0 <dir>/vendor/symfony/http-kernel/Kernel.php(473): Symfony\Component\Config\ConfigCache->isFresh()
#1 <dir>/vendor/symfony/http-kernel/Kernel.php(133): Symfony\Component\HttpKernel\Kernel->initializeContainer()
#2 <dir>/test.php(41): Symfony\Component\HttpKernel\Kernel->boot()
#3 {main}
thrown in <dir>/vendor/symfony/config/ConfigCache.php on line 56
Possible Solution
Either the previous behavior is restored or (if allowing anonymous kernel classes is not desired) a more helpful error message is thrown.