|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
namespace VirCom\Behat3ZendFramework3Extension\ServiceContainer; |
|
4
|
|
|
|
|
5
|
|
|
use VirCom\Behat3ZendFramework3Extension\Services\ZendFramework3Initializer; |
|
6
|
|
|
use VirCom\Behat3ZendFramework3Extension\Context\Initializer\KernelAwareInitializer; |
|
7
|
|
|
use VirCom\Behat3ZendFramework3Extension\Context\Argument\ArgumentResolver; |
|
8
|
|
|
|
|
9
|
|
|
use Behat\Testwork\ServiceContainer\Extension; |
|
10
|
|
|
use Behat\Testwork\ServiceContainer\ExtensionManager; |
|
11
|
|
|
use Behat\Behat\Context\ServiceContainer\ContextExtension; |
|
12
|
|
|
use Behat\Testwork\EventDispatcher\ServiceContainer\EventDispatcherExtension; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
17
|
|
|
|
|
18
|
|
|
use Zend\Mvc\ApplicationInterface; |
|
19
|
|
|
|
|
20
|
|
|
class Behat3ZendFramework3Extension implements |
|
21
|
|
|
Extension |
|
22
|
|
|
{ |
|
23
|
|
|
const SERVICE_CONTAINER_NAME = "behat3_zendframework3_extension"; |
|
24
|
|
|
const APPLICATION_CONTAINER_NAME = "zendframework3.application"; |
|
25
|
|
|
const ARGUMENT_RESOLVER_CONTAINER_NAME = "zendframework3.argument_resolver"; |
|
26
|
|
|
|
|
27
|
|
|
const BASE_PATH_PARAMETER_NAME = "paths.base"; |
|
28
|
|
|
|
|
29
|
|
|
const CONFIGURATION_PATH_ARGUMENT_NAME = "configuration_path"; |
|
30
|
|
|
const CONFIGURATION_PATH_DEFAULT_ARGUMENT_VALUE = "/config/application.config.php"; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritdoc} |
|
34
|
|
|
*/ |
|
35
|
|
|
public function configure( |
|
36
|
|
|
ArrayNodeDefinition $builder |
|
37
|
|
|
) { |
|
38
|
|
|
$builder |
|
39
|
|
|
->children() |
|
40
|
|
|
->scalarNode(self::CONFIGURATION_PATH_ARGUMENT_NAME) |
|
41
|
|
|
->info("Zend Framework 3 configuration file path") |
|
42
|
|
|
->defaultValue(self::CONFIGURATION_PATH_DEFAULT_ARGUMENT_VALUE) |
|
43
|
|
|
->end() |
|
44
|
|
|
->end() |
|
45
|
|
|
->end() |
|
46
|
|
|
->end(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritdoc} |
|
51
|
|
|
*/ |
|
52
|
1 |
|
public function getConfigKey(): string |
|
53
|
|
|
{ |
|
54
|
1 |
|
return self::SERVICE_CONTAINER_NAME; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* {@inheritdoc} |
|
59
|
|
|
*/ |
|
60
|
|
|
public function initialize( |
|
61
|
|
|
ExtensionManager $extensionManager |
|
62
|
|
|
) { |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* {@inheritdoc} |
|
67
|
|
|
*/ |
|
68
|
|
|
public function load( |
|
69
|
|
|
ContainerBuilder $container, |
|
70
|
|
|
array $config |
|
71
|
|
|
) { |
|
72
|
|
|
$this->loadInitializer($container, $config); |
|
73
|
|
|
$this->loadArgumentResolver($container); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param ContainerBuilder $container |
|
78
|
|
|
* @param array $config |
|
79
|
|
|
* @return void |
|
80
|
|
|
*/ |
|
81
|
|
|
protected function loadInitializer( |
|
82
|
|
|
ContainerBuilder $container, |
|
83
|
|
|
array $config |
|
84
|
|
|
) { |
|
85
|
|
|
$configurationFilePath = $this->mergeConfigurationFilePath( |
|
86
|
|
|
$container->getParameter(self::BASE_PATH_PARAMETER_NAME), |
|
87
|
|
|
$config[self::CONFIGURATION_PATH_ARGUMENT_NAME] |
|
88
|
|
|
); |
|
89
|
|
|
|
|
90
|
|
|
$application = (new ZendFramework3Initializer($configurationFilePath))->boot(); |
|
91
|
|
|
$container->set(self::APPLICATION_CONTAINER_NAME, $application); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @param string $basePath |
|
96
|
|
|
* @param string $configurationFilePath |
|
97
|
|
|
* @return string |
|
98
|
|
|
*/ |
|
99
|
|
|
protected function mergeConfigurationFilePath( |
|
100
|
|
|
string $basePath, |
|
101
|
|
|
string $configurationFilePath |
|
102
|
|
|
): string { |
|
103
|
|
|
return $basePath . $configurationFilePath; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @param ContainerBuilder $container |
|
108
|
|
|
* @return void |
|
109
|
|
|
*/ |
|
110
|
|
|
protected function loadArgumentResolver( |
|
111
|
|
|
ContainerBuilder $container |
|
112
|
|
|
) { |
|
113
|
|
|
$definition = new Definition( |
|
114
|
|
|
ArgumentResolver::class, |
|
115
|
|
|
[ |
|
116
|
|
|
$container->get(self::APPLICATION_CONTAINER_NAME), |
|
117
|
|
|
] |
|
118
|
|
|
); |
|
119
|
|
|
|
|
120
|
|
|
$definition->addTag(ContextExtension::ARGUMENT_RESOLVER_TAG, ['priority' => 0]); |
|
121
|
|
|
$container->setDefinition(self::ARGUMENT_RESOLVER_CONTAINER_NAME, $definition); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* {@inheritdoc} |
|
126
|
|
|
*/ |
|
127
|
|
|
public function process( |
|
128
|
|
|
ContainerBuilder $container |
|
129
|
|
|
) { |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|