Skip to content

Commit 3de4450

Browse files
committed
Merge pull request #10 from Nyholm/patch-1
Make sure we return false when committing.
2 parents a3d5f53 + b388a12 commit 3de4450

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/CachePoolTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ public function testCommit()
207207
$this->assertNotEmpty($prop->getValue($this->pool));
208208
$this->assertTrue($this->pool->commit());
209209
$this->assertEmpty($prop->getValue($this->pool));
210+
}
211+
212+
public function testCommitBadItems()
213+
{
214+
$ref = new \ReflectionObject($this->pool);
215+
$prop = $ref->getProperty('deferred');
216+
$prop->setAccessible(true);
210217

211218
$badItem = m::mock(CacheItemInterface::class);
212219
$badItem->shouldReceive('getKey')->once()->andReturn('bad_key');
@@ -218,4 +225,25 @@ public function testCommit()
218225
$this->assertFalse($this->pool->commit());
219226
$this->assertEmpty($prop->getValue($this->pool));
220227
}
228+
229+
public function testCommitMultipleItems()
230+
{
231+
$ref = new \ReflectionObject($this->pool);
232+
$prop = $ref->getProperty('deferred');
233+
$prop->setAccessible(true);
234+
235+
// the middle object is bad
236+
$this->mockDoctrine->shouldReceive('save')->andReturn(true, false, true);
237+
238+
for ($i = 0; $i < 3; $i++) {
239+
$item = m::mock(CacheItemInterface::class);
240+
$item->shouldReceive('getKey')->andReturn('key_'.$i);
241+
$this->pool->saveDeferred($item);
242+
}
243+
244+
$this->assertNotEmpty($prop->getValue($this->pool));
245+
246+
$this->assertFalse($this->pool->commit());
247+
$this->assertEmpty($prop->getValue($this->pool));
248+
}
221249
}

0 commit comments

Comments
 (0)