Failed Conditions
Pull Request — master (#75)
by Malte
02:23
created

PhantomJsDriverFactory::createDriver()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2.0438

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 15
ccs 7
cts 9
cp 0.7778
rs 9.4285
cc 2
eloc 9
nc 2
nop 1
crap 2.0438
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 PhantomJsDriverFactory implements IMinkDriverFactory
19
{
20
21
	/**
22
	 * Returns driver name, that can be used in browser configuration.
23
	 *
24
	 * @return string
25
	 */
26 11
	public function getDriverName()
27
	{
28 11
		return 'phantomjs';
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
			'host' => 'localhost',
40 1
			'driver' => 'phantomjs',
41 1
			'driverOptions' => array(),
42 1
			'browserName' => 'phantomjs',
43 1
			'port' => 8510,
44 1
		);
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
	 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @throws tag in function comment
Loading history...
54 1
	public function createDriver(BrowserConfiguration $browser)
55
	{
56 1
		if ( !class_exists('Zumba\Mink\Driver\PhantomJSDriver') ) {
57
			throw new \RuntimeException(
58
				'Install MinkPhantomJSDriver in order to use phantomjs driver.'
59
			);
60
		}
61
62 1
		return new \Zumba\Mink\Driver\PhantomJSDriver(sprintf(
63 1
			'http://%s:%s%s',
64 1
			$browser->getHost(),
65 1
			$browser->getPort(),
66
			'/api'
67 1
		));
68
	}
69
70
}
71