SahiFactory::buildDriver()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
cc 2
eloc 13
nc 2
nop 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 SahiFactory implements DriverFactory
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function getDriverName()
22
    {
23
        return 'sahi';
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('sid')->defaultNull()->end()
42
                ->scalarNode('host')->defaultValue('localhost')->end()
43
                ->scalarNode('port')->defaultValue(9999)->end()
44
                ->scalarNode('browser')->defaultNull()->end()
45
                ->scalarNode('limit')->defaultValue(600)->end()
46
            ->end()
47
        ;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function buildDriver(array $config)
54
    {
55
        if (!class_exists('Behat\Mink\Driver\SahiDriver')) {
56
            throw new \RuntimeException(
57
                'Install MinkSahiDriver in order to use sahi driver.'
58
            );
59
        }
60
61
        return new Definition('Behat\Mink\Driver\SahiDriver', array(
62
            '%mink.browser_name%',
63
            new Definition('Behat\SahiClient\Client', array(
64
                new Definition('Behat\SahiClient\Connection', array(
65
                    $config['sid'],
66
                    $config['host'],
67
                    $config['port'],
68
                    $config['browser'],
69
                    $config['limit'],
70
                )),
71
            )),
72
        ));
73
    }
74
}
75