Selenium2Factory   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 146
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 0
cbo 5
dl 0
loc 146
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getDriverName() 0 4 1
A supportsJavascript() 0 4 1
A configure() 0 10 1
B buildDriver() 0 36 4
A getCapabilitiesNode() 0 73 1
1
<?php
2
3
/*
4
 * This file is part of the Behat MinkExtension.
5
 * (c) Konstantin Kudryashov <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Behat\MinkExtension\ServiceContainer\Driver;
12
13
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
14
use Symfony\Component\DependencyInjection\Definition;
15
16
class Selenium2Factory implements DriverFactory
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function getDriverName()
22
    {
23
        return 'selenium2';
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function supportsJavascript()
30
    {
31
        return true;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function configure(ArrayNodeDefinition $builder)
38
    {
39
        $builder
40
            ->children()
41
                ->scalarNode('browser')->defaultValue('%mink.browser_name%')->end()
42
                ->append($this->getCapabilitiesNode())
43
                ->scalarNode('wd_host')->defaultValue('http://localhost:4444/wd/hub')->end()
44
            ->end()
45
        ;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function buildDriver(array $config)
52
    {
53
        if (!class_exists('Behat\Mink\Driver\Selenium2Driver')) {
54
            throw new \RuntimeException(sprintf(
55
                'Install MinkSelenium2Driver in order to use %s driver.',
56
                $this->getDriverName()
57
            ));
58
        }
59
60
        $extraCapabilities = $config['capabilities']['extra_capabilities'];
61
        unset($config['capabilities']['extra_capabilities']);
62
63
        if (getenv('TRAVIS_JOB_NUMBER')) {
64
            $guessedCapabilities = array(
65
                'tunnel-identifier' => getenv('TRAVIS_JOB_NUMBER'),
66
                'build' => getenv('TRAVIS_BUILD_NUMBER'),
67
                'tags' => array('Travis-CI', 'PHP '.phpversion()),
68
            );
69
        } elseif (getenv('JENKINS_HOME')) {
70
            $guessedCapabilities = array(
71
                'tunnel-identifier' => getenv('JOB_NAME'),
72
                'build' => getenv('BUILD_NUMBER'),
73
                'tags' => array('Jenkins', 'PHP '.phpversion(), getenv('BUILD_TAG')),
74
            );
75
        } else {
76
            $guessedCapabilities = array(
77
                'tags' => array(php_uname('n'), 'PHP '.phpversion()),
78
            );
79
        }
80
81
        return new Definition('Behat\Mink\Driver\Selenium2Driver', array(
82
            $config['browser'],
83
            array_replace($guessedCapabilities, $extraCapabilities, $config['capabilities']),
84
            $config['wd_host'],
85
        ));
86
    }
87
88
    protected function getCapabilitiesNode()
89
    {
90
        $node = new ArrayNodeDefinition('capabilities');
91
92
        $node
93
            ->addDefaultsIfNotSet()
94
            ->normalizeKeys(false)
95
            ->children()
96
                ->scalarNode('browserName')->end()
97
                ->scalarNode('version')->end()
98
                ->scalarNode('platform')->end()
99
                ->scalarNode('browserVersion')->end()
100
                ->scalarNode('browser')->defaultValue('firefox')->end()
101
                ->booleanNode('marionette')->defaultNull()->end()
102
                ->booleanNode('ignoreZoomSetting')->defaultFalse()->end()
103
                ->scalarNode('name')->defaultValue('Behat feature suite')->end()
104
                ->scalarNode('deviceOrientation')->end()
105
                ->scalarNode('deviceType')->end()
106
                ->booleanNode('javascriptEnabled')->end()
107
                ->booleanNode('databaseEnabled')->end()
108
                ->booleanNode('locationContextEnabled')->end()
109
                ->booleanNode('applicationCacheEnabled')->end()
110
                ->booleanNode('browserConnectionEnabled')->end()
111
                ->booleanNode('webStorageEnabled')->end()
112
                ->booleanNode('rotatable')->end()
113
                ->booleanNode('acceptSslCerts')->end()
114
                ->booleanNode('nativeEvents')->end()
115
                ->booleanNode('overlappingCheckDisabled')->end()
116
                ->arrayNode('proxy')
117
                    ->children()
118
                        ->scalarNode('proxyType')->end()
119
                        ->scalarNode('proxyAuthconfigUrl')->end()
120
                        ->scalarNode('ftpProxy')->end()
121
                        ->scalarNode('httpProxy')->end()
122
                        ->scalarNode('sslProxy')->end()
123
                    ->end()
124
                    ->validate()
125
                        ->ifTrue(function ($v) {
126
                            return empty($v);
127
                        })
128
                        ->thenUnset()
129
                    ->end()
130
                ->end()
131
                ->arrayNode('firefox')
132
                    ->children()
133
                        ->scalarNode('profile')
134
                            ->validate()
135
                                ->ifTrue(function ($v) {
136
                                    return !file_exists($v);
137
                                })
138
                                ->thenInvalid('Cannot find profile zip file %s')
139
                            ->end()
140
                        ->end()
141
                        ->scalarNode('binary')->end()
142
                    ->end()
143
                ->end()
144
                ->arrayNode('chrome')
145
                    ->children()
146
                        ->arrayNode('switches')->prototype('scalar')->end()->end()
147
                        ->scalarNode('binary')->end()
148
                        ->arrayNode('extensions')->prototype('scalar')->end()->end()
149
                    ->end()
150
                ->end()
151
                ->arrayNode('extra_capabilities')
152
                    ->info('Custom capabilities merged with the known ones')
153
                    ->normalizeKeys(false)
154
                    ->useAttributeAsKey('name')
155
                    ->prototype('variable')->end()
156
                ->end()
157
            ->end();
158
159
        return $node;
160
    }
161
}
162