Permalink
Fetching contributors…
Cannot retrieve contributors at this time
executable file 79 lines (73 sloc) 2.21 KB
<?php
namespace BernhardWebstudio\PlaceholderBundle\Tests;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use BernhardWebstudio\PlaceholderBundle\BernhardWebstudioPlaceholderBundle;
/**
* Class AppKernel
* It is needed to simulate an application to make some functional tests
*/
class AppKernel extends Kernel
{
/**
* @var string[]
*/
private $bundlesToRegister = [];
/**
* @var array
*/
private $configFiles = [];
/**
* @var string
*/
private $cachePrefix = '';
public function __construct($cachePrefix = 'test')
{
parent::__construct($cachePrefix, true);
$this->cachePrefix = $cachePrefix;
$this->addBundle(FrameworkBundle::class);
$this->addBundle(TwigBundle::class);
$this->addBundle(BernhardWebstudioPlaceholderBundle::class);
$this->addConfigFile(__DIR__ . '/config.yaml');
$this->addConfigFile(__DIR__ . '/../src/Resources/config/services.yaml');
}
/**
* @param string $bundleClassName class name of bundle
*/
public function addBundle($bundleClassName)
{
$this->bundlesToRegister[] = $bundleClassName;
}
/**
* @param string $configFile path to config file
*/
public function addConfigFile($configFile)
{
$this->configFiles[] = $configFile;
}
public function registerBundles()
{
$this->bundlesToRegister = array_unique($this->bundlesToRegister);
$bundles = [];
foreach ($this->bundlesToRegister as $bundle) {
$bundles[] = new $bundle();
}
return $bundles;
}
/**
* {@inheritdoc}
*/
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(function (ContainerBuilder $container) use ($loader) {
$this->configFiles = array_unique($this->configFiles);
foreach ($this->configFiles as $path) {
$loader->load($path);
}
$container->addObjectResource($this);
});
}
}