/** * @covers Robo47_Service_Gravatar::gravatarExists * @covers Robo47_Service_Gravatar::_getCacheId * @dataProvider gravatarExistsProvider */ public function testGravatarExistsWithCache() { $cache = Zend_Cache::factory('Core', new Robo47_Cache_Backend_Array(), array('automatic_cleaning_factor' => 0), array('automatic_cleaning_factor' => 0)); $options = array('cachePrefix' => 'foo_', 'cache' => $cache); $service = new Robo47_Service_Gravatar($options); // do first request $this->_adapter->setResponse(new Zend_Http_Response(404, array())); $this->assertSame(false, $service->gravatarExists('*****@*****.**')); $cacheEntry = $cache->load($service->getCacheId('*****@*****.**')); $this->assertEquals('false', $cacheEntry, 'wrong value in cache'); // assert cache is used and no request is made $this->_adapter->setResponse(new Zend_Http_Response(200, array())); $this->assertSame(false, $service->gravatarExists('*****@*****.**')); $cacheEntry = $cache->load($service->getCacheId('*****@*****.**')); $this->assertEquals('false', $cacheEntry, 'wrong value in cache'); // ignore cache for checking $this->_adapter->setResponse(new Zend_Http_Response(200, array())); $this->assertSame(true, $service->gravatarExists('*****@*****.**', false)); $cacheEntry = $cache->load($service->getCacheId('*****@*****.**')); $this->assertEquals('true', $cacheEntry, 'wrong value in cache'); // use cache for checking $this->_adapter->setResponse(new Zend_Http_Response(404, array())); $this->assertSame(true, $service->gravatarExists('*****@*****.**')); $cacheEntry = $cache->load($service->getCacheId('*****@*****.**')); $this->assertEquals('true', $cacheEntry, 'wrong value in cache'); // ignore cache again for checking $this->_adapter->setResponse(new Zend_Http_Response(404, array())); $this->assertSame(false, $service->gravatarExists('*****@*****.**', false)); $cacheEntry = $cache->load($service->getCacheId('*****@*****.**')); $this->assertEquals('false', $cacheEntry, 'wrong value in cache'); }