1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Magium\Util\Phpunit5; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use Magium\Util\Phpunit\MasterListenerInterface; |
7
|
|
|
use PHPUnit\Framework\TestListener; |
8
|
|
|
use PHPUnit_Framework_AssertionFailedError; |
9
|
|
|
use PHPUnit_Framework_Test; |
10
|
|
|
use PHPUnit_Framework_TestSuite; |
11
|
|
|
|
12
|
|
|
class MasterListener implements TestListener, MasterListenerInterface |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
protected $replay = []; |
16
|
|
|
protected $listeners = []; |
17
|
|
|
protected $result; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param $class |
21
|
|
|
* @return \PHPUnit_Framework_TestListener |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
public function getListener($class) |
25
|
|
|
{ |
26
|
|
|
foreach ($this->listeners as $listener) { |
27
|
|
|
if (get_class($listener) == $class) { |
28
|
|
|
return $listener; |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function clear() |
34
|
|
|
{ |
35
|
|
|
$this->replay = []; |
36
|
|
|
$this->listeners = []; |
37
|
|
|
$this->result = null; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
View Code Duplication |
public function addListener( $listener) |
|
|
|
|
41
|
|
|
{ |
42
|
|
|
// This pretty piece of code is to maintain compatibility between PHPUnit 5 and 6. |
43
|
|
|
if ($listener instanceof \PHPUnit_Framework_TestListener) { |
|
|
|
|
44
|
|
|
foreach ($this->listeners as $existingListener) { |
45
|
|
|
if (get_class($listener) == get_class($existingListener)) { |
46
|
|
|
return; |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
$this->listeners[] = $listener; |
50
|
|
|
foreach ($this->replay as $replay) { |
51
|
|
|
$this->play($replay['method'], $replay['args'], $listener); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
View Code Duplication |
public function play($method, $args, \PHPUnit_Framework_TestListener $instance = null) |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
if ($instance instanceof \PHPUnit_Framework_TestListener) { |
|
|
|
|
59
|
|
|
call_user_func_array([$instance, $method], $args); |
60
|
|
|
} else { |
61
|
|
|
foreach ($this->listeners as $listener) { |
62
|
|
|
call_user_func_array([$listener, $method], $args); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function bindToResult(\PHPUnit_Framework_TestResult $result) |
68
|
|
|
{ |
69
|
|
|
if ($this->result !== $result) { |
70
|
|
|
$this->result = $result; |
71
|
|
|
$result->addListener($this); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) |
76
|
|
|
{ |
77
|
|
|
$this->replay[] = [ |
78
|
|
|
'method' => __FUNCTION__, |
79
|
|
|
'args' => func_get_args() |
80
|
|
|
]; |
81
|
|
|
$this->play(__FUNCTION__, func_get_args()); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
View Code Duplication |
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) |
|
|
|
|
85
|
|
|
{ |
86
|
|
|
$this->replay[] = [ |
87
|
|
|
'method' => __FUNCTION__, |
88
|
|
|
'args' => func_get_args() |
89
|
|
|
]; |
90
|
|
|
$this->play(__FUNCTION__, func_get_args()); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) |
94
|
|
|
{ |
95
|
|
|
$this->replay[] = [ |
96
|
|
|
'method' => __FUNCTION__, |
97
|
|
|
'args' => func_get_args() |
98
|
|
|
]; |
99
|
|
|
$this->play(__FUNCTION__, func_get_args()); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time) |
103
|
|
|
{ |
104
|
|
|
$this->replay[] = [ |
105
|
|
|
'method' => __FUNCTION__, |
106
|
|
|
'args' => func_get_args() |
107
|
|
|
]; |
108
|
|
|
$this->play(__FUNCTION__, func_get_args()); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) |
112
|
|
|
{ |
113
|
|
|
$this->replay[] = [ |
114
|
|
|
'method' => __FUNCTION__, |
115
|
|
|
'args' => func_get_args() |
116
|
|
|
]; |
117
|
|
|
$this->play(__FUNCTION__, func_get_args()); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
View Code Duplication |
public function startTestSuite(PHPUnit_Framework_TestSuite $suite) |
|
|
|
|
121
|
|
|
{ |
122
|
|
|
$this->replay[] = [ |
123
|
|
|
'method' => __FUNCTION__, |
124
|
|
|
'args' => func_get_args() |
125
|
|
|
]; |
126
|
|
|
$this->play(__FUNCTION__, func_get_args()); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
View Code Duplication |
public function endTestSuite(PHPUnit_Framework_TestSuite $suite) |
|
|
|
|
130
|
|
|
{ |
131
|
|
|
$this->replay[] = [ |
132
|
|
|
'method' => __FUNCTION__, |
133
|
|
|
'args' => func_get_args() |
134
|
|
|
]; |
135
|
|
|
$this->play(__FUNCTION__, func_get_args()); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
View Code Duplication |
public function startTest(PHPUnit_Framework_Test $test) |
|
|
|
|
139
|
|
|
{ |
140
|
|
|
$this->replay[] = [ |
141
|
|
|
'method' => __FUNCTION__, |
142
|
|
|
'args' => func_get_args() |
143
|
|
|
]; |
144
|
|
|
$this->play(__FUNCTION__, func_get_args()); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
View Code Duplication |
public function endTest(PHPUnit_Framework_Test $test, $time) |
|
|
|
|
148
|
|
|
{ |
149
|
|
|
$this->replay[] = [ |
150
|
|
|
'method' => __FUNCTION__, |
151
|
|
|
'args' => func_get_args() |
152
|
|
|
]; |
153
|
|
|
$this->play(__FUNCTION__, func_get_args()); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
} |
157
|
|
|
|