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