@@ -333,4 +333,36 @@ public function testResultIsCached()
333
333
$ this ->assertTrue ($ isCached , 'Cache::isCached() could not find the cached value ' );
334
334
$ this ->assertSame ($ resultFirstRun , $ resultSecondRun , 'Second result did not match first ' );
335
335
}
336
+
337
+ /**
338
+ * Verify that the build-in caching is used when caching is enabled and a parse error is encountered.
339
+ *
340
+ * @return void
341
+ */
342
+ public function testResultIsCachedForParseError ()
343
+ {
344
+ $ methodName = 'PHPCSUtils \\Utils \\UseStatements::splitImportUseStatement ' ;
345
+ $ cases = $ this ->dataSplitImportUseStatement ();
346
+ $ testMarker = $ cases ['parse-error ' ]['testMarker ' ];
347
+ $ expected = $ cases ['parse-error ' ]['expected ' ];
348
+
349
+ $ stackPtr = $ this ->getTargetToken ($ testMarker , \T_USE );
350
+
351
+ // Verify the caching works.
352
+ $ origStatus = Cache::$ enabled ;
353
+ Cache::$ enabled = true ;
354
+
355
+ $ resultFirstRun = UseStatements::splitImportUseStatement (self ::$ phpcsFile , $ stackPtr );
356
+ $ isCached = Cache::isCached (self ::$ phpcsFile , $ methodName , $ stackPtr );
357
+ $ resultSecondRun = UseStatements::splitImportUseStatement (self ::$ phpcsFile , $ stackPtr );
358
+
359
+ if ($ origStatus === false ) {
360
+ Cache::clear ();
361
+ }
362
+ Cache::$ enabled = $ origStatus ;
363
+
364
+ $ this ->assertSame ($ expected , $ resultFirstRun , 'First result did not match expectation ' );
365
+ $ this ->assertTrue ($ isCached , 'Cache::isCached() could not find the cached value ' );
366
+ $ this ->assertSame ($ resultFirstRun , $ resultSecondRun , 'Second result did not match first ' );
367
+ }
336
368
}
0 commit comments