Skip to content

Commit

Permalink
Merge pull request #10 from Nyholm/patch-1
Browse files Browse the repository at this point in the history
Make sure we return false when committing.
  • Loading branch information
cryptiklemur committed Dec 30, 2015
2 parents a3d5f53 + b388a12 commit 3de4450
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/CachePoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ public function testCommit()
$this->assertNotEmpty($prop->getValue($this->pool));
$this->assertTrue($this->pool->commit());
$this->assertEmpty($prop->getValue($this->pool));
}

public function testCommitBadItems()
{
$ref = new \ReflectionObject($this->pool);
$prop = $ref->getProperty('deferred');
$prop->setAccessible(true);

$badItem = m::mock(CacheItemInterface::class);
$badItem->shouldReceive('getKey')->once()->andReturn('bad_key');
Expand All @@ -218,4 +225,25 @@ public function testCommit()
$this->assertFalse($this->pool->commit());
$this->assertEmpty($prop->getValue($this->pool));
}

public function testCommitMultipleItems()
{
$ref = new \ReflectionObject($this->pool);
$prop = $ref->getProperty('deferred');
$prop->setAccessible(true);

// the middle object is bad
$this->mockDoctrine->shouldReceive('save')->andReturn(true, false, true);

for ($i = 0; $i < 3; $i++) {
$item = m::mock(CacheItemInterface::class);
$item->shouldReceive('getKey')->andReturn('key_'.$i);
$this->pool->saveDeferred($item);
}

$this->assertNotEmpty($prop->getValue($this->pool));

$this->assertFalse($this->pool->commit());
$this->assertEmpty($prop->getValue($this->pool));
}
}

0 comments on commit 3de4450

Please sign in to comment.