1
|
|
|
<?php |
2
|
|
|
namespace Yoanm\Behat3SymfonyExtension\ServiceContainer; |
3
|
|
|
|
4
|
|
|
use Behat\Testwork\ServiceContainer\Extension; |
5
|
|
|
use Behat\Testwork\ServiceContainer\ExtensionManager; |
6
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
7
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
9
|
|
|
use Yoanm\Behat3SymfonyExtension\ServiceContainer\Driver\Behat3SymfonyDriverFactory; |
10
|
|
|
use Yoanm\Behat3SymfonyExtension\ServiceContainer\SubExtension\AbstractSubExtension; |
11
|
|
|
use Yoanm\Behat3SymfonyExtension\ServiceContainer\SubExtension\HandlerSubExtension; |
12
|
|
|
use Yoanm\Behat3SymfonyExtension\ServiceContainer\SubExtension\InitializerSubExtension; |
13
|
|
|
use Yoanm\Behat3SymfonyExtension\ServiceContainer\SubExtension\KernelSubExtension; |
14
|
|
|
use Yoanm\Behat3SymfonyExtension\ServiceContainer\SubExtension\LoggerSubExtension; |
15
|
|
|
use Yoanm\Behat3SymfonyExtension\ServiceContainer\SubExtension\SubscriberSubExtension; |
16
|
|
|
|
17
|
|
|
class Behat3SymfonyExtension implements Extension |
18
|
|
|
{ |
19
|
|
|
const BASE_CONTAINER_ID = 'behat3_symfony_extension'; |
20
|
|
|
const KERNEL_SERVICE_ID = 'behat3_symfony_extension.kernel'; |
21
|
|
|
|
22
|
|
|
/** @var AbstractSubExtension[] */ |
23
|
|
|
private $subExtensionList = array(); |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
1 |
|
public function getConfigKey() |
29
|
|
|
{ |
30
|
1 |
|
return 'behat3_symfony'; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
|
|
public function initialize(ExtensionManager $extensionManager) |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* @codeCoverageIgnoreStart |
40
|
|
|
* Not possible to test this because of ExtensionManager is a final class |
41
|
|
|
*/ |
42
|
|
|
$extensionManager->getExtension('mink') |
43
|
|
|
->registerDriverFactory(new Behat3SymfonyDriverFactory()); |
44
|
|
|
|
45
|
|
|
$this->subExtensionList[] = new KernelSubExtension(); |
46
|
|
|
$this->subExtensionList[] = new LoggerSubExtension(); |
47
|
|
|
$this->subExtensionList[] = new HandlerSubExtension(); |
48
|
|
|
$this->subExtensionList[] = new InitializerSubExtension(); |
49
|
|
|
$this->subExtensionList[] = new SubscriberSubExtension(); |
50
|
|
|
// @codeCoverageIgnoreEnd |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
|
|
public function configure(ArrayNodeDefinition $builder) |
57
|
|
|
{ |
58
|
|
|
$node = $builder |
59
|
|
|
->addDefaultsIfNotSet() |
60
|
|
|
->children(); |
61
|
|
|
foreach ($this->subExtensionList as $subExtension) { |
62
|
|
|
if (false !== $subExtension->getConfigKey()) { |
63
|
|
|
$tree = new TreeBuilder(); |
64
|
|
|
$subBuilder = $tree->root($subExtension->getConfigKey()); |
|
|
|
|
65
|
|
|
$subExtension->configure($subBuilder); |
66
|
|
|
$node->append($subBuilder); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$node->end(); |
71
|
|
|
// @codeCoverageIgnoreEnd |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritdoc} |
76
|
|
|
*/ |
77
|
|
|
public function load(ContainerBuilder $container, array $config) |
78
|
|
|
{ |
79
|
|
|
foreach ($this->subExtensionList as $subExtension) { |
80
|
|
|
$subExtension->load($container, $config); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritdoc} |
86
|
|
|
*/ |
87
|
|
|
public function process(ContainerBuilder $container) |
88
|
|
|
{ |
89
|
|
|
foreach ($this->subExtensionList as $subExtension) { |
90
|
|
|
$subExtension->process($container); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: