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

Selenium2DriverFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 88.24%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 58
ccs 15
cts 17
cp 0.8824
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDriverName() 0 4 1
A getDriverDefaults() 0 7 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 Selenium2DriverFactory 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 'selenium2';
28
    }
29
30
    /**
31
     * Returns default values for browser configuration.
32
     *
33
     * @return array
34
     */
35 10
    public function getDriverDefaults()
36
    {
37
        return array(
38 10
            'port' => 4444,
39
            'driverOptions' => array(),
40
        );
41
    }
42
43
    /**
44
     * Returns a new driver instance according to the browser configuration.
45
     *
46
     * @param BrowserConfiguration $browser The browser configuration.
47
     *
48
     * @return DriverInterface
49
     * @throws \RuntimeException When driver isn't installed.
50
     */
51 1
    public function createDriver(BrowserConfiguration $browser)
52
    {
53 1
        if (!class_exists('Behat\Mink\Driver\Selenium2Driver')) {
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...
54
            throw new \RuntimeException(
55
                'Install MinkSelenium2Driver in order to use selenium2 driver.'
56
            );
57
        }
58
59 1
        $browser_name = $browser->getBrowserName();
60 1
        $capabilities = $browser->getDesiredCapabilities();
61 1
        $capabilities['browserName'] = $browser_name;
62
63
        // TODO: Maybe doesn't work!
64 1
        ini_set('default_socket_timeout', $browser->getTimeout());
65
66 1
        $driver = new \Behat\Mink\Driver\Selenium2Driver(
67 1
            $browser_name,
68 1
            $capabilities,
69 1
            'http://' . $browser->getHost() . ':' . $browser->getPort() . '/wd/hub'
70
        );
71
72 1
        return $driver;
73
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line after function; 0 found
Loading history...
74
}
75