1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Global Trading Technologies Ltd workflow-extension-bundle package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* Author: Alex Medvedev |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Gtt\Bundle\WorkflowExtensionsBundle\Tests\Functional\Kernel; |
12
|
|
|
|
13
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
14
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
15
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Kernel for functional / integration tests |
19
|
|
|
*/ |
20
|
|
|
class BaseTestKernel extends Kernel implements TestKernelInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Directory name where kernel configs are stored |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $testCase; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Root directory of the kernel. Contains testCase directories |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $rootConfig; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Name of the application config |
38
|
|
|
* |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
protected $configDir; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Raw kernel name used for generating kernel directories (cache, logs etc) |
45
|
|
|
* General name should contain information about test case in order to |
46
|
|
|
* generate unique cache classes for all th test cases |
47
|
|
|
* |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
protected $rawName; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* If $rootDir is not provided, it would be set to $configDir |
54
|
|
|
* Attention! If $rootDir is provided but is not exists, it would be created |
55
|
|
|
* just like cacheDir and logDir |
56
|
|
|
* |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
*/ |
59
|
|
|
public function setTestKernelConfiguration($appName, $testCase, $configDir, $rootConfig, $rootDir = false) |
60
|
|
|
{ |
61
|
|
|
if (!$rootDir) { |
62
|
|
|
$rootDir = $configDir; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$this->setRootDir($rootDir); |
|
|
|
|
66
|
|
|
|
67
|
|
|
$this->configDir = realpath($configDir); |
68
|
|
|
if (!is_dir($this->configDir . '/' . $testCase)) { |
69
|
|
|
throw new \InvalidArgumentException(sprintf('The test case "%s" does not exist.', $testCase)); |
70
|
|
|
} |
71
|
|
|
$this->testCase = $testCase; |
72
|
|
|
|
73
|
|
|
$fs = new Filesystem(); |
74
|
|
|
if (!$fs->isAbsolutePath($rootConfig) && |
75
|
|
|
!file_exists($rootConfig = $this->configDir . '/' . $testCase . '/' . $rootConfig)) { |
76
|
|
|
throw new \InvalidArgumentException(sprintf('The root config "%s" does not exist.', $rootConfig)); |
77
|
|
|
} |
78
|
|
|
$this->rootConfig = $rootConfig; |
79
|
|
|
$this->rawName = $appName; |
80
|
|
|
$this->name = preg_replace('/[^a-zA-Z0-9_]+/', '', $this->rawName)."_". |
81
|
|
|
preg_replace('/[^a-zA-Z0-9_]+/', '', str_replace(DIRECTORY_SEPARATOR, "_", $testCase)); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Sets kernel root directory |
86
|
|
|
* |
87
|
|
|
* @param string $rootDir kernel root dir |
88
|
|
|
* |
89
|
|
|
* @throws \RuntimeException if directory does not exist and can not be created |
90
|
|
|
* |
91
|
|
|
* @return void |
92
|
|
|
*/ |
93
|
|
|
protected function setRootDir($rootDir) |
94
|
|
|
{ |
95
|
|
|
if (!is_dir($rootDir)) { |
96
|
|
|
if (false === @mkdir($rootDir, 0777, true)) { |
97
|
|
|
throw new \RuntimeException(sprintf('Unable to create test kernel root directory %s ', $rootDir)); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
$this->rootDir = realpath($rootDir); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* {@inheritdoc} |
105
|
|
|
*/ |
106
|
|
|
public function getRootDir() |
107
|
|
|
{ |
108
|
|
|
return $this->rootDir; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Returns base bundle list |
113
|
|
|
* |
114
|
|
|
* @return array |
115
|
|
|
*/ |
116
|
|
|
protected function getBaseBundles() |
117
|
|
|
{ |
118
|
|
|
return array( |
119
|
|
|
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(), |
120
|
|
|
); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* {@inheritdoc} |
125
|
|
|
*/ |
126
|
|
|
public function registerBundles() |
127
|
|
|
{ |
128
|
|
|
$bundles = array(); |
129
|
|
|
$baseBundles = $this->getBaseBundles(); |
130
|
|
|
if (file_exists($filename = $this->configDir . '/' . $this->testCase . '/bundles.php')) { |
131
|
|
|
$bundles = include $filename; |
132
|
|
|
} |
133
|
|
|
return array_merge($baseBundles, $bundles); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* {@inheritdoc} |
138
|
|
|
*/ |
139
|
|
|
public function init() |
140
|
|
|
{ |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* {@inheritdoc} |
145
|
|
|
*/ |
146
|
|
|
public function getCacheDir() |
147
|
|
|
{ |
148
|
|
|
return $this->getTempAppDir()."/".$this->testCase.'/cache/'.$this->environment; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* {@inheritdoc} |
153
|
|
|
*/ |
154
|
|
|
public function getLogDir() |
155
|
|
|
{ |
156
|
|
|
return $this->getTempAppDir()."/".$this->testCase.'/logs'; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* {@inheritdoc} |
161
|
|
|
*/ |
162
|
|
|
public function getTempAppDir() |
163
|
|
|
{ |
164
|
|
|
return sys_get_temp_dir().'/'.$this->rawName; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* {@inheritdoc} |
169
|
|
|
*/ |
170
|
|
|
public function registerContainerConfiguration(LoaderInterface $loader) |
171
|
|
|
{ |
172
|
|
|
$loader->load($this->rootConfig); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* {@inheritdoc} |
177
|
|
|
*/ |
178
|
|
|
public function serialize() |
179
|
|
|
{ |
180
|
|
|
return serialize( |
181
|
|
|
array( |
182
|
|
|
$this->getEnvironment(), |
183
|
|
|
$this->isDebug(), |
184
|
|
|
$this->rawName, |
185
|
|
|
$this->testCase, |
186
|
|
|
$this->configDir, |
187
|
|
|
$this->rootConfig, |
188
|
|
|
$this->rootDir)); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* {@inheritdoc} |
193
|
|
|
*/ |
194
|
|
|
public function unserialize($str) |
195
|
|
|
{ |
196
|
|
|
list($env, $debug, $appName, $testCase, $configDir, $rootConfig, $rootDir) = unserialize($str); |
197
|
|
|
$this->__construct($env, $debug); |
198
|
|
|
$this->setTestKernelConfiguration($appName, $testCase, $configDir, $rootConfig, $rootDir); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* {@inheritdoc} |
203
|
|
|
*/ |
204
|
|
|
protected function getKernelParameters() |
205
|
|
|
{ |
206
|
|
|
$parameters = parent::getKernelParameters(); |
207
|
|
|
|
208
|
|
|
$parameters['kernel.test_case'] = $this->testCase; |
209
|
|
|
$parameters['kernel.config_dir'] = $this->configDir; |
210
|
|
|
|
211
|
|
|
return $parameters; |
212
|
|
|
} |
213
|
|
|
} |
214
|
|
|
|
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.