1414/**
1515 * A TestListener that integrates with PHP-VCR.
1616 *
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.
1818 *
1919 * <code>
2020 * <listeners>
@@ -32,61 +32,13 @@ public function startTest(Test $test): void
3232 {
3333 $ class = \get_class ($ test );
3434 \assert ($ test instanceof TestCase);
35- $ method = $ test ->getName (false );
3635
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 ));
8537 }
8638
8739 public function endTest (Test $ test , float $ time ): void
8840 {
89- VCR :: turnOff ();
41+ VCRTestHandler:: onEnd ();
9042 }
9143
9244 public function addError (Test $ test , \Throwable $ t , float $ time ): void
0 commit comments