Skip to content

Commit

Permalink
Added tests for zendframework#165
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasvargiu committed Apr 26, 2018
1 parent 8fafa99 commit 1a0ad3a
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/Storage/Adapter/MemcachedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace ZendTest\Cache\Storage\Adapter;

use Prophecy\Argument;
use Zend\Cache;

/**
Expand Down Expand Up @@ -86,6 +87,34 @@ public function testOptionsAddServer()
$this->assertEquals($memcached->getOptions()->getServers(), $servers);
}

public function testMemcachedReturnsSuccessFalseOnError()
{
$resource = $this->prophesize(\Memcached::class);
$resourceManager = $this->prophesize(Cache\Storage\Adapter\MemcachedResourceManager::class);

$resourceManager->getResource(Argument::any())->willReturn($resource->reveal());
$resource->get(Argument::cetera())->willReturn(null);
$resource->getResultCode()->willReturn(\Memcached::RES_PARTIAL_READ);
$resource->getResultMessage()->willReturn('foo');

$storage = new Cache\Storage\Adapter\Memcached([
'resource_manager' => $resourceManager->reveal(),
]);

$storage->getEventManager()->attach(
'getItem.exception',
function(Cache\Storage\ExceptionEvent $e) {
$e->setThrowException(false);
$e->stopPropagation(true);
},
-1
);

$this->assertNull($storage->getItem('unknwon', $success, $casToken));
$this->assertFalse($success);
$this->assertNull($casToken);
}

public function getServersDefinitions()
{
$expectedServers = [
Expand Down

0 comments on commit 1a0ad3a

Please sign in to comment.