|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the StepArgumentInjectorBehatExtension 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\StepArgumentInjectorBehatExtension\ServiceContainer; |
|
13
|
|
|
|
|
14
|
|
|
use Behat\Behat\Context\ServiceContainer\ContextExtension; |
|
15
|
|
|
use Behat\Behat\Tester\ServiceContainer\TesterExtension; |
|
16
|
|
|
use Behat\Testwork\Argument\ServiceContainer\ArgumentExtension; |
|
17
|
|
|
use Behat\Testwork\Call\ServiceContainer\CallExtension; |
|
18
|
|
|
use Behat\Testwork\EventDispatcher\ServiceContainer\EventDispatcherExtension; |
|
19
|
|
|
use Behat\Testwork\Hook\ServiceContainer\HookExtension; |
|
20
|
|
|
use Behat\Testwork\ServiceContainer\Extension as ExtensionInterface; |
|
21
|
|
|
use Behat\Testwork\ServiceContainer\ExtensionManager; |
|
22
|
|
|
use Doctrine\Common\Annotations\AnnotationReader; |
|
23
|
|
|
use Gorghoa\ScenarioStateBehatExtension\ServiceContainer\ScenarioStateExtension; |
|
24
|
|
|
use Gorghoa\StepArgumentInjectorBehatExtension\Argument\ArgumentOrganiser; |
|
25
|
|
|
use Gorghoa\StepArgumentInjectorBehatExtension\Argument\StepArgumentInjectorArgumentOrganiser; |
|
26
|
|
|
use Gorghoa\StepArgumentInjectorBehatExtension\Call\Handler\RuntimeCallHandler; |
|
27
|
|
|
use Gorghoa\StepArgumentInjectorBehatExtension\Hook\Dispatcher\StepArgumentInjectorHookDispatcher; |
|
28
|
|
|
use Gorghoa\StepArgumentInjectorBehatExtension\Hook\Tester\StepArgumentInjectorHookableScenarioTester; |
|
29
|
|
|
use Gorghoa\StepArgumentInjectorBehatExtension\Resolver\ArgumentsResolver; |
|
30
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
|
31
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
32
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Behat store for Behat contexts. |
|
36
|
|
|
* |
|
37
|
|
|
* @author Rodrigue Villetard <[email protected]> |
|
38
|
|
|
* @author Vincent Chalamon <[email protected]> |
|
39
|
|
|
*/ |
|
40
|
|
|
class StepArgumentInjectorExtension implements ExtensionInterface |
|
41
|
|
|
{ |
|
42
|
|
|
const STEP_ARGUMENT_INJECTOR_ARGUMENT_ORGANISER_ID = 'argument.step_argument_injector.organiser'; |
|
43
|
|
|
const STEP_ARGUMENT_INJECTOR_DISPATCHER_ID = 'hook.step_argument_injector.dispatcher'; |
|
44
|
|
|
const STEP_ARGUMENT_INJECTOR_TESTER_ID = 'tester.step_argument_injector.wrapper'; |
|
45
|
|
|
const STEP_ARGUMENT_INJECTOR_CALL_HANDLER_ID = 'call.step_argument_injector.call_handler'; |
|
46
|
|
|
const STEP_ARGUMENT_INJECTOR_ARGUMENTS_RESOLVER_ID = 'step_argument_injector.arguments_resolver'; |
|
47
|
|
|
const STEP_ARGUMENT_INJECTOR_STORE_ID = 'behatstore.context_initializer.store_aware'; |
|
48
|
|
|
const STEP_ARGUMENT_INJECTOR_DOCTRINE_READER_ID = 'doctrine.reader.annotation'; |
|
49
|
|
|
const STEP_ARGUMENT_INJECTOR_HOOK_TAG_ID = 'step_argument_injector.hook_tag_id'; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* {@inheritdoc} |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getConfigKey() |
|
55
|
|
|
{ |
|
56
|
|
|
return 'stepargumentinjector'; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* {@inheritdoc} |
|
61
|
|
|
*/ |
|
62
|
|
|
public function initialize(ExtensionManager $extensionManager) |
|
63
|
|
|
{ |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* {@inheritdoc} |
|
68
|
|
|
*/ |
|
69
|
|
|
public function configure(ArrayNodeDefinition $builder) |
|
70
|
|
|
{ |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* {@inheritdoc} |
|
75
|
|
|
*/ |
|
76
|
|
|
public function load(ContainerBuilder $container, array $config) |
|
77
|
|
|
{ |
|
78
|
|
|
// Declare Doctrine annotation reader as service |
|
79
|
|
|
$container->register(self::STEP_ARGUMENT_INJECTOR_DOCTRINE_READER_ID, AnnotationReader::class) |
|
80
|
|
|
// Ignore Behat annotations in reader |
|
81
|
|
|
->addMethodCall('addGlobalIgnoredName', ['Given']) |
|
82
|
|
|
->addMethodCall('addGlobalIgnoredName', ['When']) |
|
83
|
|
|
->addMethodCall('addGlobalIgnoredName', ['Then']) |
|
84
|
|
|
->addMethodCall('addGlobalIgnoredName', ['Transform']) |
|
85
|
|
|
->addMethodCall('addGlobalIgnoredName', ['BeforeStep']) |
|
86
|
|
|
->addMethodCall('addGlobalIgnoredName', ['BeforeScenario']) |
|
87
|
|
|
->addMethodCall('addGlobalIgnoredName', ['BeforeFeature']) |
|
88
|
|
|
->addMethodCall('addGlobalIgnoredName', ['BeforeSuite']) |
|
89
|
|
|
->addMethodCall('addGlobalIgnoredName', ['AfterStep']) |
|
90
|
|
|
->addMethodCall('addGlobalIgnoredName', ['AfterScenario']) |
|
91
|
|
|
->addMethodCall('addGlobalIgnoredName', ['AfterFeature']) |
|
92
|
|
|
->addMethodCall('addGlobalIgnoredName', ['AfterSuite']); |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
$taggedServices = array_map(function ($serviceId) { |
|
96
|
|
|
return new Reference($serviceId); |
|
97
|
|
|
}, array_keys($container->findTaggedServiceIds(self::STEP_ARGUMENT_INJECTOR_HOOK_TAG_ID))); |
|
98
|
|
|
|
|
99
|
|
|
// Arguments resolver: resolve StepArgumentInjector arguments from annotation |
|
100
|
|
|
$container->register(self::STEP_ARGUMENT_INJECTOR_ARGUMENTS_RESOLVER_ID, ArgumentsResolver::class) |
|
101
|
|
|
->setArguments([ |
|
102
|
|
|
$taggedServices, |
|
103
|
|
|
new Reference(self::STEP_ARGUMENT_INJECTOR_DOCTRINE_READER_ID), |
|
104
|
|
|
]); |
|
105
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
// Argument organiser |
|
108
|
|
|
$container->register(self::STEP_ARGUMENT_INJECTOR_ARGUMENT_ORGANISER_ID, ArgumentOrganiser::class) |
|
109
|
|
|
->setDecoratedService(ArgumentExtension::PREG_MATCH_ARGUMENT_ORGANISER_ID) |
|
110
|
|
|
->setPublic(false) |
|
111
|
|
|
->setArguments([ |
|
112
|
|
|
new Reference(sprintf('%s.inner', self::STEP_ARGUMENT_INJECTOR_ARGUMENT_ORGANISER_ID)), |
|
113
|
|
|
$taggedServices, |
|
114
|
|
|
new Reference(self::STEP_ARGUMENT_INJECTOR_DOCTRINE_READER_ID), |
|
115
|
|
|
new Reference(self::STEP_ARGUMENT_INJECTOR_ARGUMENTS_RESOLVER_ID), |
|
116
|
|
|
]); |
|
117
|
|
|
|
|
118
|
|
|
// Override calls process |
|
119
|
|
|
$container->register(self::STEP_ARGUMENT_INJECTOR_CALL_HANDLER_ID, RuntimeCallHandler::class) |
|
120
|
|
|
->setDecoratedService(CallExtension::CALL_HANDLER_TAG.'.runtime') |
|
121
|
|
|
->setArguments([ |
|
122
|
|
|
new Reference(self::STEP_ARGUMENT_INJECTOR_CALL_HANDLER_ID.'.inner'), |
|
123
|
|
|
new Reference(self::STEP_ARGUMENT_INJECTOR_ARGUMENTS_RESOLVER_ID), |
|
124
|
|
|
]); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* {@inheritdoc} |
|
129
|
|
|
*/ |
|
130
|
|
|
public function process(ContainerBuilder $container) |
|
131
|
|
|
{ |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|