|
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; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
use aik099\PHPUnit\BrowserConfiguration\BrowserConfiguration; |
|
15
|
|
|
use aik099\PHPUnit\BrowserConfiguration\BrowserConfigurationFactory; |
|
16
|
|
|
use aik099\PHPUnit\BrowserConfiguration\BrowserStackBrowserConfiguration; |
|
17
|
|
|
use aik099\PHPUnit\BrowserConfiguration\SauceLabsBrowserConfiguration; |
|
18
|
|
|
use aik099\PHPUnit\MinkDriver\DriverFactoryRegistry; |
|
19
|
|
|
use aik099\PHPUnit\MinkDriver\GoutteDriverFactory; |
|
20
|
|
|
use aik099\PHPUnit\MinkDriver\SahiDriverFactory; |
|
21
|
|
|
use aik099\PHPUnit\MinkDriver\Selenium2DriverFactory; |
|
22
|
|
|
use aik099\PHPUnit\MinkDriver\ZombieDriverFactory; |
|
23
|
|
|
use aik099\PHPUnit\RemoteCoverage\RemoteCoverageHelper; |
|
24
|
|
|
use aik099\PHPUnit\RemoteCoverage\RemoteUrl; |
|
25
|
|
|
use aik099\PHPUnit\Session\IsolatedSessionStrategy; |
|
26
|
|
|
use aik099\PHPUnit\Session\SessionFactory; |
|
27
|
|
|
use aik099\PHPUnit\Session\SessionStrategyFactory; |
|
28
|
|
|
use aik099\PHPUnit\Session\SessionStrategyManager; |
|
29
|
|
|
use aik099\PHPUnit\Session\SharedSessionStrategy; |
|
30
|
|
|
use aik099\PHPUnit\TestSuite\BrowserTestSuite; |
|
31
|
|
|
use aik099\PHPUnit\TestSuite\RegularTestSuite; |
|
32
|
|
|
use aik099\PHPUnit\TestSuite\TestSuiteFactory; |
|
33
|
|
|
use PimpleCopy\Pimple\Container; |
|
34
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
|
35
|
|
|
|
|
36
|
|
|
class DIContainer extends Container implements IApplicationAware |
|
37
|
|
|
{ |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Sets application. |
|
41
|
|
|
* |
|
42
|
|
|
* @param Application $application The application. |
|
43
|
|
|
* |
|
44
|
|
|
* @return void |
|
45
|
|
|
*/ |
|
46
|
21 |
|
public function setApplication(Application $application) |
|
47
|
|
|
{ |
|
48
|
21 |
|
$this['application'] = $application; |
|
49
|
21 |
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Instantiate the container. |
|
53
|
|
|
* |
|
54
|
|
|
* Objects and parameters can be passed as argument to the constructor. |
|
55
|
|
|
* |
|
56
|
|
|
* @param array $values The parameters or objects. |
|
57
|
|
|
*/ |
|
58
|
25 |
|
public function __construct(array $values = array()) |
|
59
|
|
|
{ |
|
60
|
25 |
|
parent::__construct($values); |
|
61
|
|
|
|
|
62
|
|
|
$this['event_dispatcher'] = function () { |
|
63
|
10 |
|
return new EventDispatcher(); |
|
64
|
|
|
}; |
|
65
|
|
|
|
|
66
|
|
|
$this['session_factory'] = function () { |
|
67
|
5 |
|
return new SessionFactory(); |
|
68
|
|
|
}; |
|
69
|
|
|
|
|
70
|
|
|
$this['session_strategy_factory'] = function ($c) { |
|
71
|
6 |
|
$session_strategy_factory = new SessionStrategyFactory(); |
|
72
|
6 |
|
$session_strategy_factory->setApplication($c['application']); |
|
73
|
|
|
|
|
74
|
6 |
|
return $session_strategy_factory; |
|
75
|
|
|
}; |
|
76
|
|
|
|
|
77
|
|
|
$this['session_strategy_manager'] = function ($c) { |
|
78
|
5 |
|
return new SessionStrategyManager($c['session_strategy_factory']); |
|
79
|
|
|
}; |
|
80
|
|
|
|
|
81
|
|
|
$this['isolated_session_strategy'] = $this->factory(function ($c) { |
|
82
|
5 |
|
$session_strategy = new IsolatedSessionStrategy($c['session_factory']); |
|
83
|
5 |
|
$session_strategy->setEventDispatcher($c['event_dispatcher']); |
|
84
|
|
|
|
|
85
|
5 |
|
return $session_strategy; |
|
86
|
25 |
|
}); |
|
87
|
|
|
|
|
88
|
|
|
$this['shared_session_strategy'] = $this->factory(function ($c) { |
|
89
|
1 |
|
$session_strategy = new SharedSessionStrategy($c['isolated_session_strategy']); |
|
90
|
1 |
|
$session_strategy->setEventDispatcher($c['event_dispatcher']); |
|
91
|
|
|
|
|
92
|
1 |
|
return $session_strategy; |
|
93
|
25 |
|
}); |
|
94
|
|
|
|
|
95
|
|
|
$this['remote_url'] = function () { |
|
96
|
6 |
|
return new RemoteUrl(); |
|
97
|
|
|
}; |
|
98
|
|
|
|
|
99
|
|
|
$this['remote_coverage_helper'] = function ($c) { |
|
100
|
5 |
|
return new RemoteCoverageHelper($c['remote_url']); |
|
101
|
|
|
}; |
|
102
|
|
|
|
|
103
|
|
|
$this['test_suite_factory'] = function ($c) { |
|
104
|
4 |
|
$test_suite_factory = new TestSuiteFactory( |
|
105
|
4 |
|
$c['session_strategy_manager'], |
|
106
|
4 |
|
$c['browser_configuration_factory'], |
|
107
|
4 |
|
$c['remote_coverage_helper'] |
|
108
|
4 |
|
); |
|
109
|
4 |
|
$test_suite_factory->setApplication($c['application']); |
|
110
|
|
|
|
|
111
|
4 |
|
return $test_suite_factory; |
|
112
|
|
|
}; |
|
113
|
|
|
|
|
114
|
|
|
$this['regular_test_suite'] = $this->factory(function ($c) { |
|
115
|
5 |
|
$test_suite = new RegularTestSuite(); |
|
116
|
5 |
|
$test_suite->setEventDispatcher($c['event_dispatcher']); |
|
117
|
|
|
|
|
118
|
5 |
|
return $test_suite; |
|
119
|
25 |
|
}); |
|
120
|
|
|
|
|
121
|
|
|
$this['browser_test_suite'] = $this->factory(function ($c) { |
|
122
|
3 |
|
$test_suite = new BrowserTestSuite(); |
|
123
|
3 |
|
$test_suite->setEventDispatcher($c['event_dispatcher']); |
|
124
|
|
|
|
|
125
|
3 |
|
return $test_suite; |
|
126
|
25 |
|
}); |
|
127
|
|
|
|
|
128
|
|
|
$this['driver_factory_registry'] = function () { |
|
129
|
10 |
|
$registry = new DriverFactoryRegistry(); |
|
130
|
|
|
|
|
131
|
10 |
|
$registry->add(new Selenium2DriverFactory()); |
|
132
|
10 |
|
$registry->add(new SahiDriverFactory()); |
|
133
|
10 |
|
$registry->add(new GoutteDriverFactory()); |
|
134
|
10 |
|
$registry->add(new ZombieDriverFactory()); |
|
135
|
|
|
|
|
136
|
10 |
|
return $registry; |
|
137
|
|
|
}; |
|
138
|
|
|
|
|
139
|
5 |
|
$this['browser_configuration_factory'] = function ($c) { |
|
140
|
5 |
|
$browser_configuration_factory = new BrowserConfigurationFactory(); |
|
141
|
|
|
|
|
142
|
5 |
|
$browser_configuration_factory->register( |
|
143
|
5 |
|
new BrowserConfiguration($c['event_dispatcher'], $c['driver_factory_registry']) |
|
144
|
5 |
|
); |
|
145
|
5 |
|
$browser_configuration_factory->register( |
|
146
|
5 |
|
new SauceLabsBrowserConfiguration($c['event_dispatcher'], $c['driver_factory_registry']) |
|
147
|
5 |
|
); |
|
148
|
5 |
|
$browser_configuration_factory->register( |
|
149
|
5 |
|
new BrowserStackBrowserConfiguration($c['event_dispatcher'], $c['driver_factory_registry']) |
|
150
|
5 |
|
); |
|
151
|
|
|
|
|
152
|
5 |
|
return $browser_configuration_factory; |
|
153
|
|
|
}; |
|
154
|
25 |
|
} |
|
155
|
|
|
|
|
156
|
|
|
} |
|
157
|
|
|
|