/
TestKernel.php
68 lines (57 loc) · 2.13 KB
/
TestKernel.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\Fixtures;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Psr\Log\NullLogger;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
class TestKernel extends Kernel
{
/** @var string|null */
private $projectDir;
public function __construct()
{
parent::__construct('test', true);
}
public function registerBundles() : iterable
{
return [
new FrameworkBundle(),
new DoctrineBundle(),
];
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(static function (ContainerBuilder $container) {
// @todo Setting the kernel.name parameter can be removed once the dependency on DoctrineCacheBundle has been dropped
$container->setParameter('kernel.name', 'foo');
$container->loadFromExtension('framework', ['secret' => 'F00']);
$container->loadFromExtension('doctrine', [
'dbal' => ['driver' => 'pdo_sqlite'],
'orm' => [
'mappings' => [
'RepositoryServiceBundle' => [
'type' => 'annotation',
'dir' => __DIR__ . '/Bundles/RepositoryServiceBundle/Entity',
'prefix' => 'Fixtures\Bundles\RepositoryServiceBundle\Entity',
],
],
],
]);
// Register a NullLogger to avoid getting the stderr default logger of FrameworkBundle
$container->register('logger', NullLogger::class);
});
}
public function getProjectDir() : string
{
if ($this->projectDir === null) {
$this->projectDir = sys_get_temp_dir() . '/sf_kernel_' . md5(mt_rand());
}
return $this->projectDir;
}
public function getRootDir() : string
{
return $this->getProjectDir();
}
}