Skip to content

Commit 262d7a7

Browse files
committed
Merge pull request #5 from Nyholm/patch-1
Bugfix, we should return false if fetch fails
2 parents 5a23dc3 + d253ce7 commit 262d7a7

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/DoctrineCacheBridge.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff 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
/**

tests/DoctrineCacheBridgeTest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff 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);

0 commit comments

Comments
 (0)