Completed
Push — master ( 4a844a...bb1ac0 )
by Andreas
14:48 queued 19s
created

TestKernel::getProjectDir()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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