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\TestSuite; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
use aik099\PHPUnit\BrowserConfiguration\IBrowserConfigurationFactory; |
15
|
|
|
use aik099\PHPUnit\BrowserTestCase; |
16
|
|
|
use aik099\PHPUnit\IEventDispatcherAware; |
17
|
|
|
use aik099\PHPUnit\RemoteCoverage\RemoteCoverageHelper; |
18
|
|
|
use aik099\PHPUnit\Session\SessionStrategyManager; |
19
|
|
|
use PHPUnit\Framework\DataProviderTestSuite; |
20
|
|
|
use PHPUnit\Framework\TestSuite; |
21
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Base Test Suite class for browser tests. |
25
|
|
|
* |
26
|
|
|
* @method \Mockery\Expectation shouldReceive(string $name) |
27
|
|
|
*/ |
28
|
|
|
abstract class AbstractTestSuite extends TestSuite implements IEventDispatcherAware |
29
|
|
|
{ |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Event dispatcher. |
33
|
|
|
* |
34
|
|
|
* @var EventDispatcherInterface |
35
|
|
|
*/ |
36
|
|
|
private $_eventDispatcher; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Overriding the default: Selenium suites are always built from a TestCase class. |
40
|
|
|
* |
41
|
|
|
* @var boolean |
42
|
|
|
*/ |
43
|
|
|
protected $testCase = true; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Sets event dispatcher. |
47
|
|
|
* |
48
|
|
|
* @param EventDispatcherInterface $event_dispatcher Event dispatcher. |
49
|
|
|
* |
50
|
|
|
* @return void |
51
|
|
|
*/ |
52
|
15 |
|
public function setEventDispatcher(EventDispatcherInterface $event_dispatcher) |
53
|
|
|
{ |
54
|
15 |
|
$this->_eventDispatcher = $event_dispatcher; |
55
|
15 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Adds test methods to the suite. |
59
|
|
|
* |
60
|
|
|
* @param string $class_name Test case class name. |
61
|
|
|
* |
62
|
|
|
* @return self |
63
|
|
|
*/ |
64
|
5 |
|
public function addTestMethods($class_name) |
65
|
|
|
{ |
66
|
5 |
|
$class = new \ReflectionClass($class_name); |
67
|
|
|
|
68
|
5 |
|
foreach ( $class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method ) { |
69
|
5 |
|
$this->addTestMethod($class, $method); |
70
|
|
|
} |
71
|
|
|
|
72
|
5 |
|
return $this; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Sets session strategy manager recursively to all tests. |
77
|
|
|
* |
78
|
|
|
* @param SessionStrategyManager $session_strategy_manager Session strategy manager. |
79
|
|
|
* @param IBrowserConfigurationFactory $browser_configuration_factory Browser configuration factory. |
80
|
|
|
* @param RemoteCoverageHelper $remote_coverage_helper Remote coverage helper. |
81
|
|
|
* @param array $tests Tests to process. |
82
|
|
|
* |
83
|
|
|
* @return self |
84
|
|
|
*/ |
85
|
5 |
|
public function setTestDependencies( |
86
|
|
|
SessionStrategyManager $session_strategy_manager, |
87
|
|
|
IBrowserConfigurationFactory $browser_configuration_factory, |
88
|
|
|
RemoteCoverageHelper $remote_coverage_helper, |
89
|
|
|
array $tests = null |
90
|
|
|
) { |
91
|
5 |
|
if ( !isset($tests) ) { |
92
|
5 |
|
$tests = $this->tests(); |
93
|
|
|
} |
94
|
|
|
|
95
|
5 |
|
foreach ( $tests as $test ) { |
96
|
5 |
|
if ( $test instanceof DataProviderTestSuite ) { |
97
|
|
|
$this->setTestDependencies( |
98
|
|
|
$session_strategy_manager, |
99
|
|
|
$browser_configuration_factory, |
100
|
|
|
$remote_coverage_helper, |
101
|
|
|
$test->tests() |
102
|
|
|
); |
103
|
|
|
} |
104
|
|
|
else { |
105
|
|
|
/** @var BrowserTestCase $test */ |
106
|
5 |
|
$test->setEventDispatcher($this->_eventDispatcher); |
107
|
5 |
|
$test->setSessionStrategyManager($session_strategy_manager); |
108
|
5 |
|
$test->setBrowserConfigurationFactory($browser_configuration_factory); |
109
|
5 |
|
$test->setRemoteCoverageHelper($remote_coverage_helper); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
113
|
5 |
|
return $this; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Report back suite ending to each it's test. |
118
|
|
|
* |
119
|
|
|
* @param array $tests Tests to process. |
120
|
|
|
* |
121
|
|
|
* @return void |
122
|
|
|
*/ |
123
|
3 |
|
protected function tearDown(array $tests = null) |
124
|
|
|
{ |
125
|
3 |
|
if ( !isset($tests) ) { |
126
|
3 |
|
$tests = $this->tests(); |
127
|
|
|
} |
128
|
|
|
|
129
|
3 |
|
foreach ( $tests as $test ) { |
130
|
3 |
|
if ( $test instanceof DataProviderTestSuite ) { |
131
|
|
|
$this->tearDown($test->tests()); |
132
|
|
|
} |
133
|
|
|
else { |
134
|
|
|
/* @var $test BrowserTestCase */ |
|
|
|
|
135
|
3 |
|
$test->onTestSuiteEnded(); |
136
|
|
|
} |
137
|
|
|
} |
138
|
3 |
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Indicates end of the test suite. |
142
|
|
|
* |
143
|
|
|
* @return void |
144
|
|
|
* |
145
|
|
|
* @codeCoverageIgnore |
146
|
|
|
*/ |
147
|
|
|
public function onTestSuiteEnded() |
148
|
|
|
{ |
149
|
|
|
// Method created just to simplify tearDown method. |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
} |
153
|
|
|
|