|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace FriendsOfBehat\SymfonyExtension\Bundle\DependencyInjection; |
|
6
|
|
|
|
|
7
|
|
|
use Behat\Behat\Context\Context; |
|
8
|
|
|
use Behat\Mink\Mink; |
|
9
|
|
|
use Behat\Mink\Session; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
11
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
12
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
13
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
14
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
15
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
16
|
|
|
|
|
17
|
|
|
final class FriendsOfBehatSymfonyExtensionExtension extends Extension implements CompilerPassInterface |
|
18
|
|
|
{ |
|
19
|
|
|
public function load(array $configs, ContainerBuilder $container): void |
|
20
|
|
|
{ |
|
21
|
|
|
$this->registerBehatContainer($container); |
|
22
|
|
|
$this->provideMinkIntegration($container); |
|
23
|
|
|
|
|
24
|
|
|
$container |
|
25
|
|
|
->registerForAutoconfiguration(Context::class) |
|
26
|
|
|
->addTag('fob.context') |
|
27
|
|
|
; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function process(ContainerBuilder $container): void |
|
31
|
|
|
{ |
|
32
|
|
|
foreach ($container->findTaggedServiceIds('fob.context') as $serviceId => $attributes) { |
|
33
|
|
|
$container->findDefinition($serviceId)->setPublic(true); |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
private function registerBehatContainer(ContainerBuilder $container): void |
|
38
|
|
|
{ |
|
39
|
|
|
$behatServiceContainerDefinition = new Definition(ContainerInterface::class); |
|
40
|
|
|
$behatServiceContainerDefinition->setPublic(true); |
|
41
|
|
|
$behatServiceContainerDefinition->setSynthetic(true); |
|
42
|
|
|
|
|
43
|
|
|
$container->setDefinition('behat.service_container', $behatServiceContainerDefinition); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
private function provideMinkIntegration(ContainerBuilder $container): void |
|
47
|
|
|
{ |
|
48
|
|
|
$minkDefinition = new Definition(Mink::class, ['mink']); |
|
49
|
|
|
$minkDefinition->setPublic(true); |
|
50
|
|
|
$minkDefinition->setFactory([new Reference('behat.service_container'), 'get']); |
|
51
|
|
|
|
|
52
|
|
|
$container->setDefinition('behat.mink', $minkDefinition); |
|
53
|
|
|
|
|
54
|
|
|
$minkDefaultSessionDefinition = new Definition(Session::class); |
|
55
|
|
|
$minkDefaultSessionDefinition->setPublic(true); |
|
56
|
|
|
$minkDefaultSessionDefinition->setLazy(true); |
|
57
|
|
|
$minkDefaultSessionDefinition->setFactory([new Reference('behat.mink'), 'getSession']); |
|
58
|
|
|
|
|
59
|
|
|
$container->setDefinition('behat.mink.default_session', $minkDefaultSessionDefinition); |
|
60
|
|
|
$container->setAlias(Session::class, 'behat.mink.default_session'); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|