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 0c50aba
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 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,39 @@ public function testOptionsAddServer()
$this->assertEquals($memcached->getOptions()->getServers(), $servers);
}

public function testMemcachedReturnsSuccessFalseOnError()
{
if (! defined('Memcached::GET_EXTENDED')) {
$this->markTestSkipped('Test skipped because Memcached < 3.0 with Memcached::GET_EXTENDED not defined');
return;
}

$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 0c50aba

Please sign in to comment.