/** * Set up before test * * @throws Exception */ public function setUp() { $this->appMock = $this->getMock(\Magelight\App::class, [], [], '', false); \Magelight\App::forgeMock($this->appMock); $this->configLoaderMock = $this->getMock(\Magelight\Components\Loaders\Config::class, ['getConfig', 'loadConfig', 'getModulesConfigFilePath'], [], '', false); \Magelight\Components\Loaders\Config::forgeMock($this->configLoaderMock); $this->modulesMock = $this->getMock(\Magelight\Components\Modules::class, [], [], '', false); \Magelight\Components\Modules::forgeMock($this->modulesMock); $this->cacheAdapterPoolMock = $this->getMock(\Magelight\Cache\AdapterPool::class, [], [], '', false); \Magelight\Cache\AdapterPool::forgeMock($this->cacheAdapterPoolMock); $this->cacheAdapterMock = $this->getMockForAbstractClass(\Magelight\Cache\AdapterAbstract::class, [], '', false, false, true, []); $this->cacheAdapterPoolMock->expects($this->any())->method('getAdapter')->will($this->returnValue($this->cacheAdapterMock)); $this->config = \Magelight\Config::forge(); }
public function testGetAdapter() { $cacheConfig = new \SimpleXMLElement('<default> <type>file</type> <config> <path>var/cache</path> </config> </default> '); $this->configMock->expects($this->once())->method('getConfig')->with('global/cache/default')->will($this->returnValue($cacheConfig)); $fileAdapterMock = $this->getMock(\Magelight\Cache\Adapter\File::class, [], [], '', false); \Magelight\Cache\Adapter\File::forgeMock($fileAdapterMock); $this->assertEquals($fileAdapterMock, $this->adapterPool->getAdapter()); }
public function testToHtmlCacheMiss() { $cacheAdapterPoolMock = $this->getMock(\Magelight\Cache\AdapterPool::class, [], [], '', false); \Magelight\Cache\AdapterPool::forgeMock($cacheAdapterPoolMock); $cacheAdapterMock = $this->getMockForAbstractClass(\Magelight\Cache\AdapterAbstract::class, [], '', false, false, true, []); $cacheAdapterPoolMock->expects($this->any())->method('getAdapter')->will($this->returnValue($cacheAdapterMock)); $block = \Magelight\Block::forge(); $block->useCache('cache_key'); $block->setTemplate(__DIR__ . DS . '_fixtures' . DS . 'test_block_template.phtml'); $cacheAdapterMock->expects($this->once())->method('set')->with('e4453472c2481215f49f028d80db65d7', '<div>7</div>', 3600); $this->assertEquals('<div>7</div>', $block->toHtml()); }
/** * @param $cacheReturnValue * @param $expectedResult * * @dataProvider testUnlockActionDataProvider */ public function testUnlockAction($cacheReturnValue, $expectedResult) { $cacheMock = $this->getMockForAbstractClass(\Magelight\Cache\AdapterAbstract::class, [], '', false, false, true, ['del']); $adapterPoolMock = $this->getMock(\Magelight\Cache\AdapterPool::class, [], [], '', false); \Magelight\Cache\AdapterPool::forgeMock($adapterPoolMock); $adapterPoolMock->expects($this->any())->method('getAdapter')->will($this->returnValue($cacheMock)); $cacheMock->expects($this->any())->method('del')->with(md5(serialize([]) . '_lock'))->will($this->returnValue($cacheReturnValue)); $this->controller->init(); $this->assertEquals($expectedResult, $this->controller->unlockCurrentAction()); }
/** * Unlock controller action * * @return bool */ public function unlockCurrentAction() { if (\Magelight\Cache\AdapterPool::getInstance()->getAdapter()->del($this->getLockKey())) { return true; } return false; }
/** * Flush all application caches * * @return App */ public function flushAllCache() { $config = \Magelight\Config::getInstance()->getConfig('global/cache'); foreach ($config->children() as $index => $cache) { $adapters[] = \Magelight\Cache\AdapterPool::getInstance()->getAdapter($index)->clear(); } return $this; }
/** * Cleanup images cache * * @return Captcha */ public function cleanup() { if (isset($this->save_path)) { $files = glob(trim($this->save_path, '\\/') . DS . '*captcha.jpg'); foreach ($files as $file) { if (!\Magelight\Cache\AdapterPool::getInstance()->getAdapter()->get(realpath($file), false)) { unlink($file); } } } return $this; }
/** * Get cache adapter instance * * @return \Magelight\Cache\AdapterAbstract */ public function cache() { return \Magelight\Cache\AdapterPool::getInstance()->getAdapter($this->getCacheIndex()); }
public function testFlushAllCache() { $cacheConfig = new \SimpleXMLElement('<cache> <default> <type>file</type> <config> <path>var/cache</path> </config> </default> <other> <memcache> <server> <host>127.0.0.1</host> <port>11211</port> </server> </memcache> </other> </cache>'); $this->configMock->expects($this->once())->method('getConfig')->with('global/cache')->will($this->returnValue($cacheConfig)); $adapterPoolMock = $this->getMock(\Magelight\Cache\AdapterPool::class, [], [], '', false); \Magelight\Cache\AdapterPool::forgeMock($adapterPoolMock); $adapterMock = $this->getMockForAbstractClass(\Magelight\Cache\AdapterAbstract::class, [], '', false, false, true, ['clear']); $adapterMock->expects($this->exactly(2))->method('clear'); $adapterPoolMock->expects($this->at(0))->method('getAdapter')->with('default')->will($this->returnValue($adapterMock)); $adapterPoolMock->expects($this->at(1))->method('getAdapter')->with('other')->will($this->returnValue($adapterMock)); $this->app->flushAllCache(); }