File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed
Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,13 @@ public function __construct(CacheItemPoolInterface $cachePool)
4343 */
4444 public function fetch ($ id )
4545 {
46- return $ this ->cachePool ->getItem ($ id )->get ();
46+ $ item = $ this ->cachePool ->getItem ($ id );
47+
48+ if ($ item ->isHit ()) {
49+ return $ item ->get ();
50+ }
51+
52+ return false ;
4753 }
4854
4955 /**
Original file line number Diff line number Diff line change @@ -53,15 +53,23 @@ public function testConstructor()
5353
5454 public function testFetch ()
5555 {
56- $ this ->itemMock ->shouldReceive ('get ' )->times (2 )->andReturn (null , 'some_value ' );
56+ $ this ->itemMock ->shouldReceive ('isHit ' )->times (1 )->andReturn (true );
57+ $ this ->itemMock ->shouldReceive ('get ' )->times (1 )->andReturn ('some_value ' );
5758
58- $ this ->mock ->shouldReceive ('getItem ' )->withArgs (['no_item ' ])->andReturn ($ this ->itemMock );
5959 $ this ->mock ->shouldReceive ('getItem ' )->withArgs (['some_item ' ])->andReturn ($ this ->itemMock );
6060
61- $ this ->assertEmpty ($ this ->bridge ->fetch ('no_item ' ));
6261 $ this ->assertEquals ('some_value ' , $ this ->bridge ->fetch ('some_item ' ));
6362 }
6463
64+ public function testFetchMiss ()
65+ {
66+ $ this ->itemMock ->shouldReceive ('isHit ' )->times (1 )->andReturn (false );
67+
68+ $ this ->mock ->shouldReceive ('getItem ' )->withArgs (['no_item ' ])->andReturn ($ this ->itemMock );
69+
70+ $ this ->assertFalse ($ this ->bridge ->fetch ('no_item ' ));
71+ }
72+
6573 public function testContains ()
6674 {
6775 $ this ->mock ->shouldReceive ('hasItem ' )->withArgs (['no_item ' ])->andReturn (false );
You can’t perform that action at this time.
0 commit comments