11<?php
2+ declare (strict_types=1 );
23
34namespace VCR \PHPUnit \TestListener ;
45
56use PHPUnit \Framework \AssertionFailedError ;
67use PHPUnit \Framework \Test ;
8+ use PHPUnit \Framework \TestCase ;
79use PHPUnit \Framework \TestListener ;
810use PHPUnit \Framework \TestSuite ;
911use PHPUnit \Framework \Warning ;
1517 * Here is an example XML configuration for activating this listener:
1618 *
1719 * <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>
2123 * </code>
2224 *
23- * @author Adrian Philipp <[email protected] > 25+ * @author Adrian Philipp <[email protected] > 2426 * @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] > 3128 */
32- class VCRTestListener implements TestListener
29+ final class VCRTestListener implements TestListener
3330{
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- */
13331 public function startTest (Test $ test ): void
13432 {
135- $ class = get_class ($ test );
33+ $ class = \get_class ($ test );
34+ \assert ($ test instanceof TestCase);
13635 $ method = $ test ->getName (false );
13736
13837 if (!method_exists ($ class , $ method )) {
@@ -147,7 +46,7 @@ public function startTest(Test $test): void
14746 $ cassetteName = array_pop ($ parsed );
14847
14948 // 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 ' ) {
15150 VCR ::configure ()->setStorage ('json ' );
15251 }
15352
@@ -159,9 +58,9 @@ public function startTest(Test $test): void
15958 VCR ::insertCassette ($ cassetteName );
16059 }
16160
162- private static function parseDocBlock ($ docBlock , $ tag )
61+ private static function parseDocBlock ($ docBlock , $ tag ): array
16362 {
164- $ matches = array () ;
63+ $ matches = [] ;
16564
16665 if (empty ($ docBlock )) {
16766 return $ matches ;
@@ -185,31 +84,39 @@ private static function parseDocBlock($docBlock, $tag)
18584 return $ matches ;
18685 }
18786
188- /**
189- * A test ended.
190- *
191- * @param Test $test
192- * @param float $time
193- */
19487 public function endTest (Test $ test , float $ time ): void
19588 {
19689 VCR ::turnOff ();
19790 }
19891
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+
204116 public function startTestSuite (TestSuite $ suite ): void
205117 {
206118 }
207119
208- /**
209- * A test suite ended.
210- *
211- * @param TestSuite $suite
212- */
213120 public function endTestSuite (TestSuite $ suite ): void
214121 {
215122 }
0 commit comments