|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Reddogs\Test; |
|
6
|
|
|
|
|
7
|
|
|
use Interop\Container\ContainerInterface; |
|
8
|
|
|
use Zend\Expressive\ConfigManager\ConfigManager; |
|
9
|
|
|
use Zend\ServiceManager\Config; |
|
10
|
|
|
use Zend\ServiceManager\ServiceManager; |
|
11
|
|
|
|
|
12
|
|
|
abstract class ServiceManagerAwareTestCase extends \PHPUnit_Framework_TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* Array |
|
16
|
|
|
* |
|
17
|
|
|
* @var array |
|
18
|
|
|
*/ |
|
19
|
|
|
private $configProviders = []; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Container |
|
23
|
|
|
* |
|
24
|
|
|
* @var ContainerInterface |
|
25
|
|
|
*/ |
|
26
|
|
|
private $container; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Set up |
|
30
|
|
|
* {@inheritDoc} |
|
31
|
|
|
* @see PHPUnit_Framework_TestCase::setUp() |
|
32
|
|
|
*/ |
|
33
|
|
|
protected function setUp() |
|
34
|
|
|
{ |
|
35
|
|
|
$container = new ServiceManager(); |
|
36
|
|
|
$this->setContainer($container); |
|
37
|
|
|
|
|
38
|
|
|
$configManager = new ConfigManager($this->getConfigProviders()); |
|
39
|
|
|
$config = new \ArrayObject($configManager->getMergedConfig()); |
|
40
|
|
|
if (isset($config['dependencies'])) { |
|
41
|
|
|
(new Config($config['dependencies']))->configureServiceManager($container); |
|
42
|
|
|
} |
|
43
|
|
|
$container->setService('config', $config); |
|
44
|
|
|
parent::setUp(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Get config providers |
|
49
|
|
|
* |
|
50
|
|
|
* @return array |
|
51
|
|
|
*/ |
|
52
|
|
|
public function getConfigProviders() : array |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->configProviders; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Set config providers |
|
59
|
|
|
* |
|
60
|
|
|
* @param array $configProviders |
|
61
|
|
|
*/ |
|
62
|
|
|
public function setConfigProviders(array $configProviders) |
|
63
|
|
|
{ |
|
64
|
|
|
$this->configProviders = $configProviders; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Get container |
|
69
|
|
|
* |
|
70
|
|
|
* @return ContainerInterface |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getContainer() : ContainerInterface |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->container; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Set container |
|
79
|
|
|
* |
|
80
|
|
|
* @param ContainerInterface $container |
|
81
|
|
|
*/ |
|
82
|
|
|
public function setContainer(ContainerInterface $container) |
|
83
|
|
|
{ |
|
84
|
|
|
$this->container = $container; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Get config |
|
89
|
|
|
* |
|
90
|
|
|
* @return array |
|
91
|
|
|
*/ |
|
92
|
|
|
public function getConfig() : \ArrayObject |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->getContainer()->get('config'); |
|
95
|
|
|
} |
|
96
|
|
|
} |