From 0c50aba4763ee114e7acbf36a5838a579c45898f Mon Sep 17 00:00:00 2001 From: Thomas Vargiu Date: Thu, 26 Apr 2018 11:00:16 +0200 Subject: [PATCH] Added tests for #165 --- test/Storage/Adapter/MemcachedTest.php | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/Storage/Adapter/MemcachedTest.php b/test/Storage/Adapter/MemcachedTest.php index 2d3df92a3..b5590d044 100644 --- a/test/Storage/Adapter/MemcachedTest.php +++ b/test/Storage/Adapter/MemcachedTest.php @@ -9,6 +9,7 @@ namespace ZendTest\Cache\Storage\Adapter; +use Prophecy\Argument; use Zend\Cache; /** @@ -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 = [