Completed
Push — master ( 987505...ce3c0b )
by Hamish
8s
created

src/SilverStripe/BehatExtension/Extension.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace SilverStripe\BehatExtension;
4
5
use Symfony\Component\Config\FileLocator,
6
    Symfony\Component\DependencyInjection\ContainerBuilder,
7
    Symfony\Component\DependencyInjection\Loader\YamlFileLoader,
8
    Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
9
10
use Behat\Behat\Extension\ExtensionInterface;
11
12
/*
13
 * This file is part of the SilverStripe\BehatExtension
14
 *
15
 * (c) Michał Ochman <[email protected]>
16
 *
17
 * This source file is subject to the MIT license that is bundled
18
 * with this source code in the file LICENSE.
19
 */
20
21
/**
22
 * SilverStripe extension for Behat class.
23
 *
24
 * @author Michał Ochman <[email protected]>
25
 */
26
class Extension implements ExtensionInterface
27
{
28
    /**
29
     * Loads a specific configuration.
30
     *
31
     * @param array            $config    Extension configuration hash (from behat.yml)
32
     * @param ContainerBuilder $container ContainerBuilder instance
33
     */
34
    public function load(array $config, ContainerBuilder $container)
35
    {
36
        if (!isset($config['framework_path'])) {
37
            throw new \InvalidArgumentException('Specify `framework_path` parameter for silverstripe_extension');
38
        }
39
40
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/services'));
41
        $loader->load('silverstripe.yml');
42
43
        $behatBasePath = $container->getParameter('behat.paths.base');
44
        $config['framework_path'] = realpath(sprintf('%s%s%s',
45
            rtrim($behatBasePath, DIRECTORY_SEPARATOR),
46
            DIRECTORY_SEPARATOR,
47
            ltrim($config['framework_path'], DIRECTORY_SEPARATOR)
48
        ));
49
        if (!file_exists($config['framework_path']) || !is_dir($config['framework_path'])) {
50
            throw new \InvalidArgumentException('Path specified as `framework_path` either doesn\'t exist or is not a directory');
51
        }
52
53
        $container->setParameter('behat.silverstripe_extension.framework_path', $config['framework_path']);
54
        $container->setParameter('behat.silverstripe_extension.admin_url', $config['admin_url']);
55
        $container->setParameter('behat.silverstripe_extension.login_url', $config['login_url']);
56
        $container->setParameter('behat.silverstripe_extension.screenshot_path', $config['screenshot_path']);
57
        $container->setParameter('behat.silverstripe_extension.ajax_timeout', $config['ajax_timeout']);
58
        if (isset($config['ajax_steps'])) {
59
            $container->setParameter('behat.silverstripe_extension.ajax_steps', $config['ajax_steps']);
60
        }
61
        if (isset($config['region_map'])) {
62
             $container->setParameter('behat.silverstripe_extension.region_map', $config['region_map']);
63
        }
64
    }
65
66
    /**
67
     * @return array
68
     */
69
    public function getCompilerPasses()
70
    {
71
        return array(
72
            new Compiler\CoreInitializationPass()
73
        );
74
    }
75
76
    /**
77
     * Setups configuration for current extension.
78
     *
79
     * @param ArrayNodeDefinition $builder
80
     */
81
    function getConfig(ArrayNodeDefinition $builder)
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
82
    {
83
        $builder->
84
            children()->
85
                scalarNode('framework_path')->
86
                    defaultValue('framework')->
87
                end()->
88
                scalarNode('screenshot_path')->
89
                    defaultNull()->
90
                end()->
91
                arrayNode('region_map')->
92
                    useAttributeAsKey('key')->
93
                    prototype('variable')->end()->
94
                end()->
95
                scalarNode('admin_url')->
96
                    defaultValue('/admin/')->
97
                end()->
98
                scalarNode('login_url')->
99
                    defaultValue('/Security/login')->
100
                end()->
101
                scalarNode('ajax_timeout')->
102
                    defaultValue(5000)->
103
                end()->
104
                arrayNode('ajax_steps')->
105
                    defaultValue(array(
106
                        'go to',
107
                        'follow',
108
                        'press',
109
                        'click',
110
                        'submit'
111
                    ))->
112
                    prototype('scalar')->
113
                end()->
114
            end()->
115
        end();
116
    }
117
}
118