1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. |
5
|
|
|
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace SprykerTest\Service\Container\Helper; |
9
|
|
|
|
10
|
|
|
use Codeception\Module; |
11
|
|
|
use Codeception\TestInterface; |
12
|
|
|
use ReflectionProperty; |
13
|
|
|
use Spryker\Service\Container\Container; |
14
|
|
|
use Spryker\Service\Container\ContainerInterface; |
15
|
|
|
use Spryker\Shared\Kernel\Container\ContainerProxy; |
16
|
|
|
use SprykerTest\Shared\Testify\Helper\ModuleHelperConfigTrait; |
17
|
|
|
|
18
|
|
|
class ContainerHelper extends Module |
19
|
|
|
{ |
20
|
|
|
use ModuleHelperConfigTrait; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected const CONFIG_KEY_DEBUG = 'debug'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var \Spryker\Service\Container\ContainerInterface|null |
29
|
|
|
*/ |
30
|
|
|
protected $container; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @return \Spryker\Service\Container\ContainerInterface |
34
|
|
|
*/ |
35
|
|
|
public function getContainer(): ContainerInterface |
36
|
|
|
{ |
37
|
|
|
if ($this->container === null) { |
38
|
|
|
$this->container = new ContainerProxy(['logger' => null, 'debug' => $this->config[static::CONFIG_KEY_DEBUG], 'charset' => 'UTF-8']); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return $this->container; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param \Codeception\TestInterface $test |
46
|
|
|
* |
47
|
|
|
* @return void |
48
|
|
|
*/ |
49
|
|
|
public function _before(TestInterface $test): void |
50
|
|
|
{ |
51
|
|
|
parent::_before($test); |
52
|
|
|
|
53
|
|
|
$this->resetStaticProperties(); |
54
|
|
|
|
55
|
|
|
$this->container = null; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param \Codeception\TestInterface $test |
60
|
|
|
* |
61
|
|
|
* @return void |
62
|
|
|
*/ |
63
|
|
|
public function _after(TestInterface $test): void |
64
|
|
|
{ |
65
|
|
|
if ($this->container !== null) { |
66
|
|
|
$this->resetStaticProperties(); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return void |
72
|
|
|
*/ |
73
|
|
|
protected function setDefaultConfig(): void |
74
|
|
|
{ |
75
|
|
|
$this->config = [ |
|
|
|
|
76
|
|
|
static::CONFIG_KEY_DEBUG => false, |
77
|
|
|
]; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return void |
82
|
|
|
*/ |
83
|
|
|
protected function resetStaticProperties(): void |
84
|
|
|
{ |
85
|
|
|
$staticProperties = [ |
86
|
|
|
'globalServices', |
87
|
|
|
'globalServiceIdentifier', |
88
|
|
|
'globalFrozenServices', |
89
|
|
|
]; |
90
|
|
|
|
91
|
|
|
foreach ($staticProperties as $staticProperty) { |
92
|
|
|
$reflectedProperty = new ReflectionProperty(Container::class, $staticProperty); |
93
|
|
|
$reflectedProperty->setAccessible(true); |
94
|
|
|
$reflectedProperty->setValue([]); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|