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
|
|
|
use aik099\PHPUnit\BrowserConfiguration\BrowserConfiguration; |
15
|
|
|
use Behat\Mink\Driver\DriverInterface; |
16
|
|
|
|
17
|
|
|
class SahiDriverFactory 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 'sahi'; |
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' => 9999, |
39
|
|
|
'driverOptions' => array( |
40
|
|
|
'sid' => null, |
41
|
|
|
'limit' => 600, |
42
|
|
|
'browser' => null, |
43
|
|
|
), |
44
|
|
|
); |
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
|
|
|
* @throws \RuntimeException When driver isn't installed. |
54
|
|
|
*/ |
55
|
1 |
|
public function createDriver(BrowserConfiguration $browser) |
56
|
|
|
{ |
57
|
1 |
|
if (!class_exists('Behat\Mink\Driver\SahiDriver')) { |
|
|
|
|
58
|
1 |
|
throw new \RuntimeException( |
59
|
1 |
|
'Install MinkSahiDriver in order to use sahi driver.' |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$driver_options = $browser->getDriverOptions(); |
64
|
|
|
|
65
|
|
|
$connection = new \Behat\SahiClient\Connection( |
66
|
|
|
$driver_options['sid'], |
67
|
|
|
$browser->getHost(), |
68
|
|
|
$browser->getPort(), |
69
|
|
|
$driver_options['browser'], |
70
|
|
|
$driver_options['limit'] |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
return new \Behat\Mink\Driver\SahiDriver( |
74
|
|
|
$browser->getBrowserName(), |
75
|
|
|
new \Behat\SahiClient\Client($connection) |
76
|
|
|
); |
77
|
|
|
} |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|