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

ZombieDriverFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 47.06%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 61
ccs 8
cts 17
cp 0.4706
rs 10
c 1
b 1
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDriverName() 0 4 1
A getDriverDefaults() 0 12 1
A createDriver() 0 21 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 ZombieDriverFactory 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 'zombie';
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' => 8124,
39
            'driverOptions' => array(
40
                'node_bin' => 'node',
41
                'server_path' => null,
42
                'threshold' => 2000000,
43
                'node_modules_path' => '',
44
            ),
45
        );
46
    }
47
48
    /**
49
     * Returns a new driver instance according to the browser configuration.
50
     *
51
     * @param BrowserConfiguration $browser The browser configuration.
52
     *
53
     * @return DriverInterface
54
     * @throws \RuntimeException When driver isn't installed.
55
     */
56 1
    public function createDriver(BrowserConfiguration $browser)
57
    {
58 1
        if (!class_exists('Behat\Mink\Driver\ZombieDriver')) {
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...
59 1
            throw new \RuntimeException(
60 1
                'Install MinkZombieDriver in order to use zombie driver.'
61
            );
62
        }
63
64
        $driver_options = $browser->getDriverOptions();
65
66
        return new \Behat\Mink\Driver\ZombieDriver(
67
            new \Behat\Mink\Driver\NodeJS\Server\ZombieServer(
68
                $browser->getHost(),
69
                $browser->getPort(),
70
                $driver_options['node_bin'],
71
                $driver_options['server_path'],
72
                $driver_options['threshold'],
73
                $driver_options['node_modules_path']
74
            )
75
        );
76
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line after function; 0 found
Loading history...
77
}
78