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

ZombieDriverFactory::getDriverDefaults()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 2
cts 2
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
crap 1
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