|
1
|
|
|
<?php |
|
2
|
|
|
namespace Yoanm\Behat3SymfonyExtension\ServiceContainer\SubExtension; |
|
3
|
|
|
|
|
4
|
|
|
use Behat\MinkExtension\ServiceContainer\MinkExtension; |
|
5
|
|
|
use Behat\Testwork\EventDispatcher\ServiceContainer\EventDispatcherExtension; |
|
6
|
|
|
use Behat\Testwork\ServiceContainer\Exception\ProcessingException; |
|
7
|
|
|
use Behat\Testwork\ServiceContainer\ExtensionManager; |
|
8
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
|
9
|
|
|
use Symfony\Component\Config\FileLocator; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
11
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
|
12
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
13
|
|
|
use Yoanm\Behat3SymfonyExtension\Context\Initializer\KernelAwareInitializer; |
|
14
|
|
|
use Yoanm\Behat3SymfonyExtension\ServiceContainer\AbstractExtension; |
|
15
|
|
|
use Yoanm\Behat3SymfonyExtension\ServiceContainer\DriverFactory\Behat3SymfonyFactory; |
|
16
|
|
|
use Yoanm\Behat3SymfonyExtension\Subscriber\RebootKernelSubscriber; |
|
17
|
|
|
|
|
18
|
|
|
class KernelSubExtension extends AbstractExtension |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @inheritDoc |
|
22
|
|
|
*/ |
|
23
|
1 |
|
public function getConfigKey() |
|
24
|
|
|
{ |
|
25
|
1 |
|
return 'kernel'; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
// @codeCoverageIgnoreStart |
|
29
|
|
|
// Not possible to cover this because ExtensionManager is a final class |
|
30
|
|
|
/** |
|
31
|
|
|
* @inheritDoc |
|
32
|
|
|
*/ |
|
33
|
|
|
public function initialize(ExtensionManager $extensionManager) |
|
34
|
|
|
{ |
|
35
|
|
|
$minExtension = $extensionManager->getExtension('mink'); |
|
36
|
|
|
if ($minExtension instanceof MinkExtension) { |
|
37
|
|
|
$minExtension->registerDriverFactory(new Behat3SymfonyFactory()); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
// @codeCoverageIgnoreEnd |
|
41
|
|
|
|
|
42
|
|
|
// @codeCoverageIgnoreStart |
|
43
|
|
|
// Will be covered by FT |
|
44
|
|
|
/** |
|
45
|
|
|
* @inheritDoc |
|
46
|
|
|
*/ |
|
47
|
|
|
public function configure(ArrayNodeDefinition $builder) |
|
48
|
|
|
{ |
|
49
|
|
|
$castToBool = function ($value) { |
|
50
|
|
|
$filtered = filter_var( |
|
51
|
|
|
$value, |
|
52
|
|
|
FILTER_VALIDATE_BOOLEAN, |
|
53
|
|
|
FILTER_NULL_ON_FAILURE |
|
54
|
|
|
); |
|
55
|
|
|
|
|
56
|
|
|
return (null === $filtered) ? (bool) $value : $filtered; |
|
57
|
|
|
}; |
|
58
|
|
|
$builder |
|
59
|
|
|
->addDefaultsIfNotSet() |
|
60
|
|
|
->children() |
|
61
|
|
|
->scalarNode('bootstrap') |
|
62
|
|
|
->defaultValue('app/autoload.php') |
|
63
|
|
|
->end() |
|
64
|
|
|
->scalarNode('path') |
|
65
|
|
|
->defaultValue('app/AppKernel.php') |
|
66
|
|
|
->end() |
|
67
|
|
|
->scalarNode('class') |
|
68
|
|
|
->defaultValue('AppKernel') |
|
69
|
|
|
->end() |
|
70
|
|
|
->scalarNode('env') |
|
71
|
|
|
->defaultValue('test') |
|
72
|
|
|
->end() |
|
73
|
|
|
->booleanNode('debug') |
|
74
|
|
|
->beforeNormalization() |
|
75
|
|
|
->always() |
|
76
|
|
|
->then($castToBool) |
|
77
|
|
|
->end() |
|
78
|
|
|
->defaultTrue() |
|
79
|
|
|
->end() |
|
80
|
|
|
->booleanNode('reboot') |
|
81
|
|
|
->info('If true symfony kernel will be rebooted after each scenario/example') |
|
82
|
|
|
->beforeNormalization() |
|
83
|
|
|
->always() |
|
84
|
|
|
->then($castToBool) |
|
85
|
|
|
->end() |
|
86
|
|
|
->defaultTrue() |
|
87
|
|
|
->end() |
|
88
|
|
|
->end(); |
|
89
|
|
|
} |
|
90
|
|
|
// @codeCoverageIgnoreEnd |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* {@inheritdoc} |
|
94
|
|
|
*/ |
|
95
|
|
|
public function load(ContainerBuilder $container, array $config) |
|
96
|
|
|
{ |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* {@inheritdoc} |
|
101
|
|
|
*/ |
|
102
|
3 |
|
public function process(ContainerBuilder $container) |
|
103
|
|
|
{ |
|
104
|
3 |
|
$basePath = $container->getParameter('paths.base'); |
|
105
|
3 |
|
$bootstrapPath = $container->getParameter($this->buildContainerId('kernel.bootstrap')); |
|
106
|
3 |
|
if ($bootstrapPath) { |
|
107
|
2 |
|
$bootstrapPathUnderBasePath = sprintf('%s/%s', $basePath, $bootstrapPath); |
|
108
|
2 |
|
if (file_exists($bootstrapPathUnderBasePath)) { |
|
109
|
1 |
|
$bootstrapPath = $bootstrapPathUnderBasePath; |
|
110
|
1 |
|
} |
|
111
|
2 |
|
if (file_exists($bootstrapPath)) { |
|
112
|
1 |
|
require_once($bootstrapPath); |
|
113
|
1 |
|
} else { |
|
114
|
1 |
|
throw new ProcessingException('Could not find bootstrap file !'); |
|
115
|
|
|
} |
|
116
|
1 |
|
} |
|
117
|
|
|
|
|
118
|
|
|
// load kernel |
|
119
|
2 |
|
$kernelPath = $container->getParameter($this->buildContainerId('kernel.path')); |
|
120
|
2 |
|
$kernelPathUnderBasePath = sprintf('%s/%s', $basePath, $kernelPath); |
|
121
|
2 |
|
if (file_exists($kernelPathUnderBasePath)) { |
|
122
|
|
|
$kernelPath = $kernelPathUnderBasePath; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
2 |
|
$container->getDefinition(self::KERNEL_SERVICE_ID) |
|
126
|
2 |
|
->setFile($kernelPath); |
|
127
|
2 |
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|