1
1
<?php
2
+ declare (strict_types=1 );
2
3
3
4
namespace VCR \PHPUnit \TestListener ;
4
5
5
6
use PHPUnit \Framework \AssertionFailedError ;
6
7
use PHPUnit \Framework \Test ;
8
+ use PHPUnit \Framework \TestCase ;
7
9
use PHPUnit \Framework \TestListener ;
8
10
use PHPUnit \Framework \TestSuite ;
9
11
use PHPUnit \Framework \Warning ;
15
17
* Here is an example XML configuration for activating this listener:
16
18
*
17
19
* <code>
18
- * <listeners>
19
- * <listener class="VCR\PHPUnit\TestListener\VCRTestListener" file="vendor/php-vcr/phpunit-testlistener-vcr/src/VCRTestListener.php" />
20
- * </listeners>
20
+ * <listeners>
21
+ * <listener class="VCR\PHPUnit\TestListener\VCRTestListener" file="vendor/php-vcr/phpunit-testlistener-vcr/src/VCRTestListener.php" />
22
+ * </listeners>
21
23
* </code>
22
24
*
23
- * @author Adrian Philipp <[email protected] >
25
+ * @author Adrian Philipp <[email protected] >
24
26
* @author Davide Borsatto <[email protected] >
25
- * @copyright 2011-2017 Adrian Philipp <[email protected] >
26
- * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
27
- *
28
- * @version Release: @package_version@
29
- *
30
- * @see http://www.phpunit.de/
27
+ * @author Renato Mefi <[email protected] >
31
28
*/
32
- class VCRTestListener implements TestListener
29
+ final class VCRTestListener implements TestListener
33
30
{
34
- /**
35
- * @var array
36
- */
37
- protected $ runs = array ();
38
-
39
- /**
40
- * @var array
41
- */
42
- protected $ options = array ();
43
-
44
- /**
45
- * @var int
46
- */
47
- protected $ suites = 0 ;
48
-
49
- /**
50
- * Constructor.
51
- *
52
- * @param array $options
53
- */
54
- public function __construct (array $ options = array ())
55
- {
56
- }
57
-
58
- /**
59
- * An error occurred.
60
- *
61
- * @param Test $test
62
- * @param Exception $e
63
- * @param float $time
64
- */
65
- public function addError (Test $ test , \Throwable $ t , float $ time ): void
66
- {
67
- }
68
-
69
- /**
70
- * A warning occurred.
71
- *
72
- * @param Test $test
73
- * @param Warning $e
74
- * @param float $time
75
- *
76
- * @since Method available since Release 5.1.0
77
- */
78
- public function addWarning (Test $ test , Warning $ e , float $ time ): void
79
- {
80
- }
81
-
82
- /**
83
- * A failure occurred.
84
- *
85
- * @param Test $test
86
- * @param AssertionFailedError $e
87
- * @param float $time
88
- */
89
- public function addFailure (Test $ test , AssertionFailedError $ e , float $ time ): void
90
- {
91
- }
92
-
93
- /**
94
- * Incomplete test.
95
- *
96
- * @param Test $test
97
- * @param \Exception $e
98
- * @param float $time
99
- */
100
- public function addIncompleteTest (Test $ test , \Throwable $ e , float $ time ): void
101
- {
102
- }
103
-
104
- /**
105
- * Skipped test.
106
- *
107
- * @param Test $test
108
- * @param \Exception $e
109
- * @param float $time
110
- */
111
- public function addSkippedTest (Test $ test , \Throwable $ e , float $ time ): void
112
- {
113
- }
114
-
115
- /**
116
- * Risky test.
117
- *
118
- * @param Test $test
119
- * @param \Exception $e
120
- * @param float $time
121
- */
122
- public function addRiskyTest (Test $ test , \Throwable $ e , float $ time ): void
123
- {
124
- }
125
-
126
- /**
127
- * A test started.
128
- *
129
- * @param Test $test
130
- *
131
- * @return bool|null
132
- */
133
31
public function startTest (Test $ test ): void
134
32
{
135
- $ class = get_class ($ test );
33
+ $ class = \get_class ($ test );
34
+ \assert ($ test instanceof TestCase);
136
35
$ method = $ test ->getName (false );
137
36
138
37
if (!method_exists ($ class , $ method )) {
@@ -147,7 +46,7 @@ public function startTest(Test $test): void
147
46
$ cassetteName = array_pop ($ parsed );
148
47
149
48
// If the cassette name ends in .json, then use the JSON storage format
150
- if (substr ($ cassetteName , ' -5 ' ) == '.json ' ) {
49
+ if (substr ($ cassetteName , - 5 ) = == '.json ' ) {
151
50
VCR ::configure ()->setStorage ('json ' );
152
51
}
153
52
@@ -159,9 +58,9 @@ public function startTest(Test $test): void
159
58
VCR ::insertCassette ($ cassetteName );
160
59
}
161
60
162
- private static function parseDocBlock ($ docBlock , $ tag )
61
+ private static function parseDocBlock ($ docBlock , $ tag ): array
163
62
{
164
- $ matches = array () ;
63
+ $ matches = [] ;
165
64
166
65
if (empty ($ docBlock )) {
167
66
return $ matches ;
@@ -185,31 +84,39 @@ private static function parseDocBlock($docBlock, $tag)
185
84
return $ matches ;
186
85
}
187
86
188
- /**
189
- * A test ended.
190
- *
191
- * @param Test $test
192
- * @param float $time
193
- */
194
87
public function endTest (Test $ test , float $ time ): void
195
88
{
196
89
VCR ::turnOff ();
197
90
}
198
91
199
- /**
200
- * A test suite started.
201
- *
202
- * @param TestSuite $suite
203
- */
92
+ public function addError (Test $ test , \Throwable $ t , float $ time ): void
93
+ {
94
+ }
95
+
96
+ public function addWarning (Test $ test , Warning $ e , float $ time ): void
97
+ {
98
+ }
99
+
100
+ public function addFailure (Test $ test , AssertionFailedError $ e , float $ time ): void
101
+ {
102
+ }
103
+
104
+ public function addIncompleteTest (Test $ test , \Throwable $ e , float $ time ): void
105
+ {
106
+ }
107
+
108
+ public function addSkippedTest (Test $ test , \Throwable $ e , float $ time ): void
109
+ {
110
+ }
111
+
112
+ public function addRiskyTest (Test $ test , \Throwable $ e , float $ time ): void
113
+ {
114
+ }
115
+
204
116
public function startTestSuite (TestSuite $ suite ): void
205
117
{
206
118
}
207
119
208
- /**
209
- * A test suite ended.
210
- *
211
- * @param TestSuite $suite
212
- */
213
120
public function endTestSuite (TestSuite $ suite ): void
214
121
{
215
122
}
0 commit comments