1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of php-task library. |
5
|
|
|
* |
6
|
|
|
* (c) php-task |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; |
13
|
|
|
use Symfony\Bundle\FrameworkBundle\FrameworkBundle; |
14
|
|
|
use Symfony\Component\Config\FileLocator; |
15
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
16
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
17
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
18
|
|
|
use Task\TaskBundle\TaskBundle; |
19
|
|
|
|
20
|
|
|
class TestKernel extends Kernel |
21
|
|
|
{ |
22
|
|
|
const STORAGE_VAR_NAME = 'STORAGE'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
private $storage; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
|
|
public function registerBundles() |
33
|
|
|
{ |
34
|
|
|
return [ |
35
|
|
|
new FrameworkBundle(), |
36
|
|
|
new DoctrineBundle(), |
37
|
|
|
new TaskBundle(), |
38
|
|
|
]; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
public function registerContainerConfiguration(LoaderInterface $loader) |
45
|
|
|
{ |
46
|
|
|
$this->storage = getenv(self::STORAGE_VAR_NAME); |
47
|
|
|
if (false === $this->storage) { |
48
|
|
|
$this->storage = 'array'; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$loader->load(sprintf('%s/config/config.yml', __DIR__)); |
52
|
|
|
$loader->load(sprintf('%s/config/config.%s.yml', __DIR__, $this->storage)); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritdoc} |
57
|
|
|
*/ |
58
|
|
|
protected function buildContainer() |
59
|
|
|
{ |
60
|
|
|
$container = parent::buildContainer(); |
61
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/config')); |
62
|
|
|
$loader->load('services.xml'); |
63
|
|
|
|
64
|
|
|
$container->setParameter('kernel.storage', $this->storage); |
65
|
|
|
$container->setParameter('container.build_id', hash('crc32', 'Abc123423456789')); |
66
|
|
|
|
67
|
|
|
return $container; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* {@inheritdoc} |
72
|
|
|
*/ |
73
|
|
|
protected function initializeContainer() |
74
|
|
|
{ |
75
|
|
|
static $first = true; |
76
|
|
|
|
77
|
|
|
if ('test' !== $this->getEnvironment()) { |
78
|
|
|
parent::initializeContainer(); |
79
|
|
|
|
80
|
|
|
return; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$debug = $this->debug; |
84
|
|
|
|
85
|
|
|
if (!$first) { |
86
|
|
|
// disable debug mode on all but the first initialization |
87
|
|
|
$this->debug = false; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
// will not work with --process-isolation |
91
|
|
|
$first = false; |
92
|
|
|
|
93
|
|
|
try { |
94
|
|
|
parent::initializeContainer(); |
95
|
|
|
} catch (\Exception $e) { |
96
|
|
|
$this->debug = $debug; |
97
|
|
|
|
98
|
|
|
throw $e; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
$this->debug = $debug; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
protected function getKernelParameters() |
105
|
|
|
{ |
106
|
|
|
return array_merge( |
107
|
|
|
parent::getKernelParameters(), |
108
|
|
|
[ |
109
|
|
|
'kernel.test_root_dir' => __DIR__, |
110
|
|
|
] |
111
|
|
|
); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|