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
|
8 |
|
public function getDriverName() |
27
|
|
|
{ |
28
|
8 |
|
return 'phantomjs'; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Returns default values for browser configuration. |
33
|
|
|
* |
34
|
|
|
* @return array |
35
|
|
|
*/ |
36
|
|
|
public function getDriverDefaults() |
37
|
|
|
{ |
38
|
|
|
return array( |
39
|
|
|
'host' => 'localhost', |
40
|
|
|
'driver' => 'phantomjs', |
41
|
|
|
'driverOptions' => array( |
42
|
|
|
'api_endpoint' => '/api' |
|
|
|
|
43
|
|
|
), |
44
|
|
|
'browserName' => 'phantomjs', |
45
|
|
|
'port' => 8510 |
|
|
|
|
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
|
|
|
*/ |
|
|
|
|
56
|
|
|
public function createDriver(BrowserConfiguration $browser) |
57
|
|
|
{ |
58
|
|
|
if ( !class_exists('Zumba\Mink\Driver\PhantomJSDriver') ) { |
59
|
|
|
throw new \RuntimeException( |
60
|
|
|
'Install PhantomJSDriver in order to use phantomjs driver.' |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$driverOptions = $browser->getDriverOptions(); |
|
|
|
|
65
|
|
|
return new \Zumba\Mink\Driver\PhantomJSDriver(sprintf("http://%s:%s%s", $browser->getHost(), $browser->getPort(), $driverOptions['api_endpoint'])); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
} |
69
|
|
|
|