@@ -76,6 +76,21 @@ public function testStorageExceptionIsWrappedWhenSaving()
7676 }
7777 }
7878
79+ public function testStorageExceptionUsesGetItemOperationName ()
80+ {
81+ $ exception = new \RuntimeException ('backend down ' );
82+ $ pool = new ThrowingArrayCachePool ();
83+ $ pool ->fetchException = $ exception ;
84+
85+ try {
86+ $ pool ->getItem ('key ' )->isHit ();
87+ self ::fail ('getItem did not wrap the storage exception ' );
88+ } catch (CachePoolException $ wrapped ) {
89+ self ::assertSame ($ exception , $ wrapped ->getPrevious ());
90+ self ::assertSame ('Exception thrown when executing "getItem". ' , $ wrapped ->getMessage ());
91+ }
92+ }
93+
7994 public function testSetMultipleWrapsItemExpirationFailure ()
8095 {
8196 $ exception = new InvalidArgumentException ('invalid ' );
@@ -367,13 +382,24 @@ final class ThrowingArrayCachePool extends ArrayCachePool
367382{
368383 public ?\RuntimeException $ clearException = null ;
369384
385+ public ?\RuntimeException $ fetchException = null ;
386+
370387 public ?\RuntimeException $ saveException = null ;
371388
372389 protected function clearAllObjectsFromCache (): bool
373390 {
374391 throw $ this ->clearException ?? new \LogicException ('clearException is not configured ' );
375392 }
376393
394+ protected function fetchObjectFromCache (string $ key ): array
395+ {
396+ if (null !== $ this ->fetchException ) {
397+ throw $ this ->fetchException ;
398+ }
399+
400+ return parent ::fetchObjectFromCache ($ key );
401+ }
402+
377403 protected function storeItemInCache (PhpCacheItem $ item , ?int $ ttl ): bool
378404 {
379405 throw $ this ->saveException ?? new \LogicException ('saveException is not configured ' );
0 commit comments