dir = sys_get_temp_dir().'/twig-extra-bundle/'.bin2hex(random_bytes(6)); parent::__construct('test', false); } public function getCacheDir(): string { return $this->dir.'/cache'; } public function getLogDir(): string { return $this->dir.'/log'; } public function getProjectDir(): string { return __DIR__; } public function getTempDir(): string { return $this->dir; } public function registerBundles(): iterable { yield new FrameworkBundle(); yield new TwigBundle(); yield new TwigExtraBundle(); } protected function build(ContainerBuilder $container): void { $container->addCompilerPass(new class implements CompilerPassInterface { public function process(ContainerBuilder $container): void { $pools = []; foreach (['twig.cache', '.twig.cache.inner', 'cache.app'] as $id) { if ($container->hasAlias($id)) { $pools[$id] = '@'.$container->getAlias($id); continue; } $definition = $container->getDefinition($id); $pools[$id] = $definition->getClass(); // cache adapters take their namespace as their first string argument foreach ($definition->getArguments() as $argument) { if (\is_string($argument)) { $pools[$id.'.namespace'] = $argument; break; } } } $container->setParameter('twig_extra.test.cache_pools', $pools); } }, PassConfig::TYPE_BEFORE_REMOVING, -1000); } protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader): void { $config = [ 'secret' => 'S3CRET', 'router' => ['utf8' => true], 'http_method_override' => false, 'php_errors' => [ 'log' => true, ], ]; // the "handle_all_throwables" option was introduced in FrameworkBundle 6.2 (and so was the NotificationAssertionsTrait) if (trait_exists(NotificationAssertionsTrait::class)) { $config['handle_all_throwables'] = true; } if (null !== $this->cacheAdapter) { $config['cache'] = ['app' => $this->cacheAdapter]; } $c->loadFromExtension('framework', $config); $c->loadFromExtension('twig', [ 'default_path' => __DIR__.'/views', ]); } protected function configureRoutes($routes): void { } }