Completed
Pull Request — master (#100)
by Michał
01:35
created

ZombieDriverFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
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 62
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;
13
14
15
use aik099\PHPUnit\BrowserConfiguration\BrowserConfiguration;
16
use Behat\Mink\Driver\DriverInterface;
17
18
class ZombieDriverFactory implements IMinkDriverFactory
19
{
20
21
	/**
22
	 * Returns driver name, that can be used in browser configuration.
23
	 *
24
	 * @return string
25
	 */
26 10
	public function getDriverName()
27
	{
28 10
		return 'zombie';
29
	}
30
31
	/**
32
	 * Returns default values for browser configuration.
33
	 *
34
	 * @return array
35
	 */
36 1
	public function getDriverDefaults()
37
	{
38
		return array(
39 1
			'port' => 8124,
40
			'driverOptions' => array(
41
				'node_bin' => 'node',
42
				'server_path' => null,
43
				'threshold' => 2000000,
44
				'node_modules_path' => '',
45
			),
46
		);
47
	}
48
49
	/**
50
	 * Returns a new driver instance according to the browser configuration.
51
	 *
52
	 * @param BrowserConfiguration $browser The browser configuration.
53
	 *
54
	 * @return DriverInterface
55
	 * @throws \RuntimeException When driver isn't installed.
56
	 */
57 1
	public function createDriver(BrowserConfiguration $browser)
58
	{
59 1
		if ( !class_exists('Behat\Mink\Driver\ZombieDriver') ) {
60 1
			throw new \RuntimeException(
61 1
				'Install MinkZombieDriver in order to use zombie driver.'
62
			);
63
		}
64
65
		$driver_options = $browser->getDriverOptions();
66
67
		return new \Behat\Mink\Driver\ZombieDriver(
68
			new \Behat\Mink\Driver\NodeJS\Server\ZombieServer(
69
				$browser->getHost(),
70
				$browser->getPort(),
71
				$driver_options['node_bin'],
72
				$driver_options['server_path'],
73
				$driver_options['threshold'],
74
				$driver_options['node_modules_path']
75
			)
76
		);
77
	}
78
79
}
80