1 | <?php |
||
38 | class AppKernel extends Kernel |
||
39 | { |
||
40 | private $testCase; |
||
41 | private $rootConfig; |
||
42 | |||
43 | public function __construct($testCase, $rootConfig, $environment, $debug) |
||
44 | { |
||
45 | if (!is_dir(__DIR__.'/'.$testCase)) { |
||
46 | throw new \InvalidArgumentException(sprintf('The test case "%s" does not exist.', $testCase)); |
||
47 | } |
||
48 | $this->testCase = $testCase; |
||
49 | |||
50 | $fs = new Filesystem(); |
||
51 | if (!$fs->isAbsolutePath($rootConfig) && !file_exists($rootConfig = __DIR__.'/'.$testCase.'/'.$rootConfig)) { |
||
52 | throw new \InvalidArgumentException(sprintf('The root config "%s" does not exist.', $rootConfig)); |
||
53 | } |
||
54 | $this->rootConfig = $rootConfig; |
||
55 | |||
56 | parent::__construct($environment, $debug); |
||
57 | } |
||
58 | |||
59 | public function registerBundles() |
||
60 | { |
||
61 | if (!file_exists($filename = $this->getRootDir().'/'.$this->testCase.'/bundles.php')) { |
||
62 | throw new \RuntimeException(sprintf('The bundles file "%s" does not exist.', $filename)); |
||
63 | } |
||
64 | |||
65 | return include $filename; |
||
66 | } |
||
67 | |||
68 | public function getRootDir() |
||
69 | { |
||
70 | return __DIR__; |
||
71 | } |
||
72 | |||
73 | public function getCacheDir() |
||
74 | { |
||
75 | return sys_get_temp_dir().'/'.Kernel::VERSION.'/'.$this->testCase.'/cache/'.$this->environment; |
||
76 | } |
||
77 | |||
78 | public function getLogDir() |
||
79 | { |
||
80 | return sys_get_temp_dir().'/'.Kernel::VERSION.'/'.$this->testCase.'/logs'; |
||
81 | } |
||
82 | |||
83 | public function registerContainerConfiguration(LoaderInterface $loader) |
||
84 | { |
||
85 | $loader->load($this->rootConfig); |
||
86 | } |
||
87 | |||
88 | public function serialize() |
||
89 | { |
||
90 | return serialize([$this->testCase, $this->rootConfig, $this->getEnvironment(), $this->isDebug()]); |
||
91 | } |
||
92 | |||
93 | public function unserialize($str) |
||
94 | { |
||
95 | $a = unserialize($str); |
||
96 | $this->__construct($a[0], $a[1], $a[2], $a[3]); |
||
97 | } |
||
98 | |||
99 | protected function getKernelParameters() |
||
100 | { |
||
101 | $parameters = parent::getKernelParameters(); |
||
102 | $parameters['kernel.test_case'] = $this->testCase; |
||
103 | |||
104 | return $parameters; |
||
105 | } |
||
106 | } |
||
107 |