1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the ScenarioStateBehatExtension project. |
5
|
|
|
* |
6
|
|
|
* (c) Rodrigue Villetard <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Gorghoa\ScenarioStateBehatExtension\ServiceContainer; |
13
|
|
|
|
14
|
|
|
use Behat\Behat\Context\ServiceContainer\ContextExtension; |
15
|
|
|
use Behat\Testwork\Argument\ServiceContainer\ArgumentExtension; |
16
|
|
|
use Behat\Testwork\Call\ServiceContainer\CallExtension; |
17
|
|
|
use Behat\Testwork\EventDispatcher\ServiceContainer\EventDispatcherExtension; |
18
|
|
|
use Behat\Testwork\Hook\ServiceContainer\HookExtension; |
19
|
|
|
use Behat\Testwork\ServiceContainer\Extension as ExtensionInterface; |
20
|
|
|
use Behat\Testwork\ServiceContainer\ExtensionManager; |
21
|
|
|
use Doctrine\Common\Annotations\AnnotationReader; |
22
|
|
|
use Doctrine\Common\Annotations\AnnotationRegistry; |
23
|
|
|
use Gorghoa\ScenarioStateBehatExtension\Context\Initializer\ScenarioStateInitializer; |
24
|
|
|
use Gorghoa\ScenarioStateBehatExtension\ScenarioStateArgumentOrganiser; |
25
|
|
|
use Gorghoa\ScenarioStateBehatExtension\ScenarioStateHookDispatcher; |
26
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
27
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
28
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
29
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Behat store for Behat contexts. |
33
|
|
|
* |
34
|
|
|
* @author Rodrigue Villetard <[email protected]> |
35
|
|
|
* @author Vincent Chalamon <[email protected]> |
36
|
|
|
*/ |
37
|
|
|
class ScenarioStateExtension implements ExtensionInterface |
38
|
|
|
{ |
39
|
|
|
const SCENARIO_STATE_ARGUMENT_ORGANISER_ID = 'argument.scenario_state_organiser'; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
public function getConfigKey() |
45
|
|
|
{ |
46
|
|
|
return 'scenariostate'; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
*/ |
52
|
|
|
public function initialize(ExtensionManager $extensionManager) |
53
|
|
|
{ |
54
|
|
|
AnnotationRegistry::registerFile(__DIR__.'/../Annotation/ScenarioStateArgument.php'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritdoc} |
59
|
|
|
*/ |
60
|
|
|
public function configure(ArrayNodeDefinition $builder) |
61
|
|
|
{ |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritdoc} |
66
|
|
|
*/ |
67
|
|
|
public function load(ContainerBuilder $container, array $config) |
68
|
|
|
{ |
69
|
|
|
$this->loadContextInitializer($container); |
70
|
|
|
$this->loadOrganiser($container); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritdoc} |
75
|
|
|
*/ |
76
|
|
|
public function process(ContainerBuilder $container) |
77
|
|
|
{ |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
private function loadContextInitializer(ContainerBuilder $container) |
81
|
|
|
{ |
82
|
|
|
$definition = new Definition(ScenarioStateInitializer::class, []); |
83
|
|
|
$definition->addTag(ContextExtension::INITIALIZER_TAG, ['priority' => 0]); |
84
|
|
|
$definition->addTag(EventDispatcherExtension::SUBSCRIBER_TAG, ['priority' => 0]); |
85
|
|
|
|
86
|
|
|
$container->setDefinition('behatstore.context_initializer.store_aware', $definition); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
private function loadOrganiser(ContainerBuilder $container) |
90
|
|
|
{ |
91
|
|
|
// Declare Doctrine annotation reader as service |
92
|
|
|
$container->register('doctrine.reader.annotation', AnnotationReader::class) |
93
|
|
|
// Ignore Behat annotations in reader |
94
|
|
|
->addMethodCall('addGlobalIgnoredName', ['Given']) |
95
|
|
|
->addMethodCall('addGlobalIgnoredName', ['When']) |
96
|
|
|
->addMethodCall('addGlobalIgnoredName', ['Then']); |
97
|
|
|
|
98
|
|
|
$container->register(self::SCENARIO_STATE_ARGUMENT_ORGANISER_ID, ScenarioStateArgumentOrganiser::class) |
99
|
|
|
->setDecoratedService(ArgumentExtension::PREG_MATCH_ARGUMENT_ORGANISER_ID) |
100
|
|
|
->setPublic(false) |
101
|
|
|
->setArguments([ |
102
|
|
|
new Reference(sprintf('%s.inner', self::SCENARIO_STATE_ARGUMENT_ORGANISER_ID)), |
103
|
|
|
new Reference('behatstore.context_initializer.store_aware'), |
104
|
|
|
new Reference('doctrine.reader.annotation'), |
105
|
|
|
]); |
106
|
|
|
|
107
|
|
|
// Override hook dispatcher |
108
|
|
|
$container->register(HookExtension::DISPATCHER_ID, ScenarioStateHookDispatcher::class) |
109
|
|
|
->setPublic(false) |
110
|
|
|
->setArguments([ |
111
|
|
|
new Reference(HookExtension::REPOSITORY_ID), |
112
|
|
|
new Reference(CallExtension::CALL_CENTER_ID), |
113
|
|
|
new Reference('behatstore.context_initializer.store_aware'), |
114
|
|
|
new Reference('doctrine.reader.annotation'), |
115
|
|
|
]); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|