|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Majora\Bundle\FrameworkExtraBundle\Tests\Functional\app; |
|
4
|
|
|
|
|
5
|
|
|
// get the autoload file |
|
6
|
|
|
$dir = __DIR__; |
|
7
|
|
|
$lastDir = null; |
|
8
|
|
|
while ($dir !== $lastDir) { |
|
9
|
|
|
$lastDir = $dir; |
|
10
|
|
|
|
|
11
|
|
|
if (file_exists($dir.'/autoload.php')) { |
|
12
|
|
|
require_once $dir.'/autoload.php'; |
|
13
|
|
|
break; |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
if (file_exists($dir.'/autoload.php.dist')) { |
|
17
|
|
|
require_once $dir.'/autoload.php.dist'; |
|
18
|
|
|
break; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
if (file_exists($dir.'/vendor/autoload.php')) { |
|
22
|
|
|
require_once $dir.'/vendor/autoload.php'; |
|
23
|
|
|
break; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
$dir = dirname($dir); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
|
30
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
|
31
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* App Test Kernel for functional tests. |
|
35
|
|
|
* |
|
36
|
|
|
* @author Johannes M. Schmitt <[email protected]> |
|
37
|
|
|
*/ |
|
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
|
|
|
|