Completed
Push — master ( f1e1ae...7e3292 )
by Denis
10:20 queued 02:02
created

AppKernel   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 14
eloc 27
dl 0
loc 74
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Tests\Artprima\PrometheusMetricsBundle\Fixtures\App;
4
5
use Psr\Log\NullLogger;
6
use Symfony\Component\Config\Loader\LoaderInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\Filesystem\Filesystem;
9
use Symfony\Component\HttpKernel\Kernel;
10
11
/**
12
 * App Test Kernel for functional tests.
13
 *
14
 * @author Johannes M. Schmitt <[email protected]>
15
 */
16
class AppKernel extends Kernel
17
{
18
    private $varDir;
19
    private $testCase;
20
    private $rootConfig;
21
22
    public function __construct($varDir, $testCase, $rootConfig, $environment, $debug)
23
    {
24
        if (!is_dir(__DIR__.'/'.$testCase)) {
25
            throw new \InvalidArgumentException(sprintf('The test case "%s" does not exist.', $testCase));
26
        }
27
        $this->varDir = $varDir;
28
        $this->testCase = $testCase;
29
30
        $fs = new Filesystem();
31
        if (!$fs->isAbsolutePath($rootConfig) && !file_exists($rootConfig = __DIR__.'/'.$testCase.'/'.$rootConfig)) {
32
            throw new \InvalidArgumentException(sprintf('The root config "%s" does not exist.', $rootConfig));
33
        }
34
        $this->rootConfig = $rootConfig;
35
36
        parent::__construct($environment, $debug);
37
    }
38
39
    public function registerBundles()
40
    {
41
        if (!file_exists($filename = $this->getRootDir().'/'.$this->testCase.'/bundles.php')) {
42
            throw new \RuntimeException(sprintf('The bundles file "%s" does not exist.', $filename));
43
        }
44
45
        return include $filename;
46
    }
47
48
    public function getRootDir()
49
    {
50
        return __DIR__;
51
    }
52
53
    public function getCacheDir()
54
    {
55
        return sys_get_temp_dir().'/'.$this->varDir.'/'.$this->testCase.'/cache/'.$this->environment;
56
    }
57
58
    public function getLogDir()
59
    {
60
        return sys_get_temp_dir().'/'.$this->varDir.'/'.$this->testCase.'/logs';
61
    }
62
63
    public function registerContainerConfiguration(LoaderInterface $loader)
64
    {
65
        $loader->load($this->rootConfig);
66
    }
67
68
    protected function build(ContainerBuilder $container)
69
    {
70
        $container->register('logger', NullLogger::class);
71
    }
72
73
    public function serialize()
74
    {
75
        return serialize(array($this->varDir, $this->testCase, $this->rootConfig, $this->getEnvironment(), $this->isDebug()));
76
    }
77
78
    public function unserialize($str)
79
    {
80
        $a = unserialize($str);
81
        $this->__construct($a[0], $a[1], $a[2], $a[3], $a[4]);
82
    }
83
84
    protected function getKernelParameters()
85
    {
86
        $parameters = parent::getKernelParameters();
87
        $parameters['kernel.test_case'] = $this->testCase;
88
89
        return $parameters;
90
    }
91
}
92