14
14
/**
15
15
* A TestListener that integrates with PHP-VCR.
16
16
*
17
- * Here is an example XML configuration for activating this listener:
17
+ * Here is an example XML configuration for activating this listener in PHPUnit < 10.
18
18
*
19
19
* <code>
20
20
* <listeners>
@@ -32,61 +32,13 @@ public function startTest(Test $test): void
32
32
{
33
33
$ class = \get_class ($ test );
34
34
\assert ($ test instanceof TestCase);
35
- $ method = $ test ->getName (false );
36
35
37
- if (!method_exists ($ class , $ method )) {
38
- return ;
39
- }
40
-
41
- $ reflection = new \ReflectionMethod ($ class , $ method );
42
- $ docBlock = $ reflection ->getDocComment ();
43
-
44
- // Use regex to parse the doc_block for a specific annotation
45
- $ parsed = self ::parseDocBlock ($ docBlock , '@vcr ' );
46
- $ cassetteName = array_pop ($ parsed );
47
-
48
- if (empty ($ cassetteName )) {
49
- return ;
50
- }
51
-
52
- // If the cassette name ends in .json, then use the JSON storage format
53
- if (substr ($ cassetteName , -5 ) === '.json ' ) {
54
- VCR ::configure ()->setStorage ('json ' );
55
- }
56
-
57
- VCR ::turnOn ();
58
- VCR ::insertCassette ($ cassetteName );
59
- }
60
-
61
- private static function parseDocBlock ($ docBlock , $ tag ): array
62
- {
63
- $ matches = [];
64
-
65
- if (empty ($ docBlock )) {
66
- return $ matches ;
67
- }
68
-
69
- $ regex = "/ {$ tag } (.*)( \\r \\n| \\r| \\n)/U " ;
70
- preg_match_all ($ regex , $ docBlock , $ matches );
71
-
72
- if (empty ($ matches [1 ])) {
73
- return array ();
74
- }
75
-
76
- // Removed extra index
77
- $ matches = $ matches [1 ];
78
-
79
- // Trim the results, array item by array item
80
- foreach ($ matches as $ ix => $ match ) {
81
- $ matches [$ ix ] = trim ($ match );
82
- }
83
-
84
- return $ matches ;
36
+ VCRTestHandler::onStart ($ class , $ test ->getName (false ));
85
37
}
86
38
87
39
public function endTest (Test $ test , float $ time ): void
88
40
{
89
- VCR :: turnOff ();
41
+ VCRTestHandler:: onEnd ();
90
42
}
91
43
92
44
public function addError (Test $ test , \Throwable $ t , float $ time ): void
0 commit comments