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
|
|
|
namespace aik099\PHPUnit\BrowserConfiguration; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
use aik099\PHPUnit\BrowserTestCase; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Browser configuration factory. |
18
|
|
|
* |
19
|
|
|
* @method \Mockery\Expectation shouldReceive(string $name) |
20
|
|
|
*/ |
21
|
|
|
class BrowserConfigurationFactory implements IBrowserConfigurationFactory |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Browser configurations. |
26
|
|
|
* |
27
|
|
|
* @var array |
28
|
|
|
*/ |
29
|
|
|
protected $browserConfigurations = array(); |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Registers a browser configuration. |
33
|
|
|
* |
34
|
|
|
* @param BrowserConfiguration $browser Browser configuration. |
35
|
|
|
* |
36
|
|
|
* @return void |
37
|
|
|
* @throws \InvalidArgumentException When browser configuration is already registered. |
38
|
|
|
*/ |
39
|
8 |
|
public function register(BrowserConfiguration $browser) |
40
|
|
|
{ |
41
|
8 |
|
$type = $browser->getType(); |
42
|
|
|
|
43
|
8 |
|
if ( isset($this->browserConfigurations[$type]) ) { |
44
|
1 |
|
throw new \InvalidArgumentException( |
45
|
1 |
|
'Browser configuration with type "' . $type . '" is already registered' |
46
|
1 |
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
8 |
|
$this->browserConfigurations[$type] = $browser; |
50
|
8 |
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Returns browser configuration instance. |
54
|
|
|
* |
55
|
|
|
* @param array $config Browser. |
56
|
|
|
* @param BrowserTestCase $test_case Test case. |
57
|
|
|
* |
58
|
|
|
* @return BrowserConfiguration |
59
|
|
|
*/ |
60
|
5 |
|
public function createBrowserConfiguration(array $config, BrowserTestCase $test_case) |
61
|
|
|
{ |
62
|
5 |
|
$aliases = $test_case->getBrowserAliases(); |
63
|
5 |
|
$config = BrowserConfiguration::resolveAliases($config, $aliases); |
64
|
|
|
|
65
|
5 |
|
$type = isset($config['type']) ? $config['type'] : 'default'; |
66
|
5 |
|
unset($config['type']); |
67
|
|
|
|
68
|
5 |
|
return $this->create($type)->setAliases($aliases)->setup($config); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Creates browser configuration based on give type. |
73
|
|
|
* |
74
|
|
|
* @param string $type Type. |
75
|
|
|
* |
76
|
|
|
* @return BrowserConfiguration |
77
|
|
|
* @throws \InvalidArgumentException When browser configuration not registered. |
78
|
|
|
*/ |
79
|
5 |
|
protected function create($type) |
80
|
|
|
{ |
81
|
5 |
|
if ( !isset($this->browserConfigurations[$type]) ) { |
82
|
1 |
|
throw new \InvalidArgumentException('Browser configuration type "' . $type . '" not registered'); |
83
|
|
|
} |
84
|
|
|
|
85
|
4 |
|
return clone $this->browserConfigurations[$type]; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
} |
89
|
|
|
|