|
| 1 | +<?php |
| 2 | +namespace WhiteOctober\BreadcrumbsBundle\Test; |
| 3 | + |
| 4 | +use Symfony\Bundle\FrameworkBundle\FrameworkBundle; |
| 5 | +use Symfony\Component\Config\Loader\LoaderInterface; |
| 6 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 7 | +use Symfony\Component\HttpKernel\Kernel; |
| 8 | + |
| 9 | +/** |
| 10 | + * Class AppKernel |
| 11 | + * It is needed to simulate an application to make some functional tests |
| 12 | + */ |
| 13 | +class AppKernel extends Kernel |
| 14 | +{ |
| 15 | + /** |
| 16 | + * @var string[] |
| 17 | + */ |
| 18 | + private $bundlesToRegister = []; |
| 19 | + |
| 20 | + /** |
| 21 | + * @var array |
| 22 | + */ |
| 23 | + private $configFiles = []; |
| 24 | + |
| 25 | + /** |
| 26 | + * @var string |
| 27 | + */ |
| 28 | + private $cachePrefix = ''; |
| 29 | + |
| 30 | + public function __construct($cachePrefix) |
| 31 | + { |
| 32 | + parent::__construct($cachePrefix, true); |
| 33 | + $this->cachePrefix = $cachePrefix; |
| 34 | + $this->addBundle(FrameworkBundle::class); |
| 35 | + $this->addConfigFile(__DIR__.'/config.xml'); |
| 36 | + $this->addConfigFile(__DIR__.'/../Resources/config/breadcrumbs.xml'); |
| 37 | + } |
| 38 | + |
| 39 | + public function addBundle($bundleClassName) |
| 40 | + { |
| 41 | + $this->bundlesToRegister[] = $bundleClassName; |
| 42 | + } |
| 43 | + |
| 44 | + public function registerBundles() |
| 45 | + { |
| 46 | + $this->bundlesToRegister = array_unique($this->bundlesToRegister); |
| 47 | + $bundles = []; |
| 48 | + foreach ($this->bundlesToRegister as $bundle) { |
| 49 | + $bundles[] = new $bundle(); |
| 50 | + } |
| 51 | + |
| 52 | + return $bundles; |
| 53 | + } |
| 54 | + /** |
| 55 | + * {@inheritdoc} |
| 56 | + */ |
| 57 | + public function registerContainerConfiguration(LoaderInterface $loader) |
| 58 | + { |
| 59 | + $loader->load(function (ContainerBuilder $container) use ($loader) { |
| 60 | + $this->configFiles = array_unique($this->configFiles); |
| 61 | + foreach ($this->configFiles as $path) { |
| 62 | + $loader->load($path); |
| 63 | + } |
| 64 | + |
| 65 | + $container->addObjectResource($this); |
| 66 | + $container->setParameter('white_october_breadcrumbs.options', []); |
| 67 | + }); |
| 68 | + } |
| 69 | + /** |
| 70 | + * @param string $configFile path to config file |
| 71 | + */ |
| 72 | + public function addConfigFile($configFile) |
| 73 | + { |
| 74 | + $this->configFiles[] = $configFile; |
| 75 | + } |
| 76 | +} |
0 commit comments