Failed Conditions
Pull Request — master (#102)
by
unknown
03:22
created

SahiDriverFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 44.44%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 62
ccs 8
cts 18
cp 0.4444
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDriverName() 0 4 1
A getDriverDefaults() 0 11 1
A createDriver() 0 23 2
1
<?php
2
/**
3
 * This file is part of the phpunit-mink library.
4
 * For the full copyright and license information, please view
5
 * the LICENSE file that was distributed with this source code.
6
 *
7
 * @copyright Alexander Obuhovich <[email protected]>
8
 * @link      https://github.com/aik099/phpunit-mink
9
 */
10
11
12
namespace aik099\PHPUnit\MinkDriver;
0 ignored issues
show
introduced by
Expected 2 blank line(-s) after namespace declaration; 1 found
Loading history...
13
14
use aik099\PHPUnit\BrowserConfiguration\BrowserConfiguration;
15
use Behat\Mink\Driver\DriverInterface;
16
17
class SahiDriverFactory implements IMinkDriverFactory
18
{
19
20
    /**
21
     * Returns driver name, that can be used in browser configuration.
22
     *
23
     * @return string
24
     */
25 10
    public function getDriverName()
26
    {
27 10
        return 'sahi';
28
    }
29
30
    /**
31
     * Returns default values for browser configuration.
32
     *
33
     * @return array
34
     */
35 1
    public function getDriverDefaults()
36
    {
37
        return array(
38 1
            'port' => 9999,
39
            'driverOptions' => array(
40
                'sid' => null,
41
                'limit' => 600,
42
                'browser' => null,
43
            ),
44
        );
45
    }
46
47
    /**
48
     * Returns a new driver instance according to the browser configuration.
49
     *
50
     * @param BrowserConfiguration $browser The browser configuration.
51
     *
52
     * @return DriverInterface
53
     * @throws \RuntimeException When driver isn't installed.
54
     */
55 1
    public function createDriver(BrowserConfiguration $browser)
56
    {
57 1
        if (!class_exists('Behat\Mink\Driver\SahiDriver')) {
0 ignored issues
show
introduced by
Expected 1 spaces after "if" opening bracket; 0 found
Loading history...
introduced by
Expected 1 spaces before "if" closing bracket; 0 found
Loading history...
58 1
            throw new \RuntimeException(
59 1
                'Install MinkSahiDriver in order to use sahi driver.'
60
            );
61
        }
62
63
        $driver_options = $browser->getDriverOptions();
64
65
        $connection = new \Behat\SahiClient\Connection(
66
            $driver_options['sid'],
67
            $browser->getHost(),
68
            $browser->getPort(),
69
            $driver_options['browser'],
70
            $driver_options['limit']
71
        );
72
73
        return new \Behat\Mink\Driver\SahiDriver(
74
            $browser->getBrowserName(),
75
            new \Behat\SahiClient\Client($connection)
76
        );
77
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line after function; 0 found
Loading history...
78
}
79