@@ -24,7 +24,7 @@ class AbstractSnapshot extends Snapshot
2424    /** 
2525     * Keeps a counter for each class, function and data-set combination. 
2626     * 
27-      * @var array<string,array> 
27+      * @var array<string,array<string,int> > 
2828     */ 
2929    protected  static  $ counters
3030
@@ -49,6 +49,13 @@ class AbstractSnapshot extends Snapshot
4949     */ 
5050    protected  $ dataVisitor
5151
52+     /** 
53+      * By default, show the diff on failure. 
54+      * 
55+      * @var bool 
56+      */ 
57+     protected  $ showDifftrue ;
58+ 
5259    /** 
5360     * Snapshot constructor. 
5461     * 
@@ -84,14 +91,19 @@ protected function getFileName()
8491                debug_backtrace (DEBUG_BACKTRACE_IGNORE_ARGS 
8592                    | DEBUG_BACKTRACE_PROVIDE_OBJECT , 5 ),
8693                static  function  (array  $ backtraceEntryuse  ($ traitMethods
87-                     return  !in_array (
94+                     return  isset ( $ backtraceEntry [ ' class ' ]) &&  !in_array (
8895                        $ backtraceEntry'class ' ],
8996                        [Snapshot::class, static ::class, self ::class, SnapshotAssertions::class],
9097                        true 
9198                    ) && !in_array ($ backtraceEntry'function ' ], $ traitMethodstrue );
9299                }
93100            ));
94-             $ class$ backtrace0 ]['class ' ];
101+             $ classisset ($ backtrace0 ]['class ' ]) ? $ backtrace0 ]['class ' ] : '' ;
102+     
103+             if  (empty ($ class
104+                 throw  new  \RuntimeException ('Cannot get ithe class name. ' );
105+             }
106+ 
95107            $ classFragsexplode ('\\' , $ class
96108            $ classBasenamearray_pop ($ classFrags
97109            $ classFilenew  \ReflectionClass ($ classgetFileName ();
@@ -103,7 +115,7 @@ static function (array $backtraceEntry) use ($traitMethods) {
103115            $ classDirdirname ($ classFile
104116            $ function$ backtrace0 ]['function ' ];
105117            $ dataSetFrag'' ;
106-             if  ($ backtrace0 ]['object ' ] instanceof  TestCase) {
118+             if  (isset ( $ backtrace [ 0 ][ ' object ' ]) &&  $ backtrace0 ]['object ' ] instanceof  TestCase) {
107119                /** @var TestCase $testCase */ 
108120                $ testCase$ backtrace0 ]['object ' ];
109121                $ dataName$ this getDataName ($ testCase
@@ -268,6 +280,10 @@ public function assert()
268280                return ;
269281            }
270282
283+             if  ($ this showDiff ) {
284+                 throw  $ exception
285+             }
286+ 
271287            $ this fail ($ exceptiongetMessage ());
272288        }
273289    }
0 commit comments