|
3 | 3 | namespace Behat\YiiExtension; |
4 | 4 |
|
5 | 5 | use Symfony\Component\Config\FileLocator, |
| 6 | + Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition, |
6 | 7 | Symfony\Component\DependencyInjection\ContainerBuilder, |
7 | 8 | Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
8 | 9 |
|
@@ -34,27 +35,73 @@ public function load(array $config, ContainerBuilder $container) |
34 | 35 | { |
35 | 36 | $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/services')); |
36 | 37 | $loader->load('yii.xml'); |
37 | | - $configPath = $container->getParameter('behat.paths.base'); |
| 38 | + $basePath = $container->getParameter('behat.paths.base'); |
| 39 | + |
| 40 | + // starting from Behat 2.4.1, we can check for activated extensions |
| 41 | + $extensions = $container->hasParameter('behat.extension.classes') |
| 42 | + ? $container->getParameter('behat.extension.classes') |
| 43 | + : array(); |
38 | 44 |
|
39 | 45 | if (!isset($config['framework_script'])) { |
40 | 46 | throw new \InvalidArgumentException( |
41 | 47 | 'Specify `framework_script` parameter for yii_extension.' |
42 | 48 | ); |
43 | 49 | } |
44 | | - if (file_exists($cfg = $configPath.DIRECTORY_SEPARATOR.$config['framework_script'])) { |
| 50 | + if (file_exists($cfg = $basePath.DIRECTORY_SEPARATOR.$config['framework_script'])) { |
45 | 51 | $config['framework_script'] = $cfg; |
46 | 52 | } |
| 53 | + $container->setParameter('behat.yii_extension.framework_script', $config['framework_script']); |
47 | 54 |
|
48 | 55 | if (!isset($config['config_script'])) { |
49 | 56 | throw new \InvalidArgumentException( |
50 | 57 | 'Specify `config_script` parameter for yii_extension.' |
51 | 58 | ); |
52 | 59 | } |
53 | | - if (file_exists($cfg = $configPath.DIRECTORY_SEPARATOR.$config['config_script'])) { |
| 60 | + if (file_exists($cfg = $basePath.DIRECTORY_SEPARATOR.$config['config_script'])) { |
54 | 61 | $config['config_script'] = $cfg; |
55 | 62 | } |
56 | | - |
57 | | - $container->setParameter('behat.yii_extension.framework_script', $config['framework_script']); |
58 | 63 | $container->setParameter('behat.yii_extension.config_script', $config['config_script']); |
| 64 | + |
| 65 | + if ($config['mink_driver']) { |
| 66 | + if (!class_exists('Behat\\Mink\\Driver\\WUnitDriver')) { |
| 67 | + throw new \RuntimeException( |
| 68 | + 'Install WUnitDriver in order to activate wunit session.' |
| 69 | + ); |
| 70 | + } |
| 71 | + |
| 72 | + $loader->load('sessions/wunit.xml'); |
| 73 | + } elseif (in_array('Behat\\MinkExtension\\Extension', $extensions) && class_exists('Behat\\Mink\\Driver\\WUnitDriver')) { |
| 74 | + $loader->load('sessions/wunit.xml'); |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * Setups configuration for current extension. |
| 80 | + * |
| 81 | + * @param ArrayNodeDefinition $builder |
| 82 | + */ |
| 83 | + public function getConfig(ArrayNodeDefinition $builder) |
| 84 | + { |
| 85 | + $boolFilter = function ($v) { |
| 86 | + $filtered = filter_var($v, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); |
| 87 | + return (null === $filtered) ? $v : $filtered; |
| 88 | + }; |
| 89 | + |
| 90 | + $builder-> |
| 91 | + children()-> |
| 92 | + scalarNode('framework_script')-> |
| 93 | + isRequired()-> |
| 94 | + end()-> |
| 95 | + scalarNode('config_script')-> |
| 96 | + isRequired()-> |
| 97 | + end()-> |
| 98 | + booleanNode('mink_driver')-> |
| 99 | + beforeNormalization()-> |
| 100 | + ifString()->then($boolFilter)-> |
| 101 | + end()-> |
| 102 | + defaultFalse()-> |
| 103 | + end()-> |
| 104 | + end() |
| 105 | + ; |
59 | 106 | } |
60 | 107 | } |
0 commit comments