/** * @param State\OptionsInterface $options * @param \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool * @param \Magento\Framework\App\State $appState * @param bool $banAll Whether all cache types are forced to be disabled */ public function __construct(State\OptionsInterface $options, \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool, \Magento\Framework\App\State $appState, $banAll = false) { $this->_options = $options; $this->_cacheFrontend = $cacheFrontendPool->get(\Magento\Framework\App\Cache\Frontend\Pool::DEFAULT_FRONTEND_ID); if ($appState->isInstalled()) { $this->_loadTypeStatuses($banAll); } }
/** * @param array $fixtureCacheConfig * @param array $frontendSettings * @param array $expectedFactoryArg * * @dataProvider initializationParamsDataProvider */ public function testInitializationParams(array $fixtureCacheConfig, array $frontendSettings, array $expectedFactoryArg) { $deploymentConfig = $this->getMock('Magento\\Framework\\App\\DeploymentConfig', [], [], '', false); $deploymentConfig->expects($this->once())->method('getConfigData')->with(FrontendPool::KEY_CACHE)->will($this->returnValue($fixtureCacheConfig)); $frontendFactory = $this->getMock('Magento\\Framework\\App\\Cache\\Frontend\\Factory', [], [], '', false); $frontendFactory->expects($this->at(0))->method('create')->with($expectedFactoryArg); $model = new \Magento\Framework\App\Cache\Frontend\Pool($deploymentConfig, $frontendFactory, $frontendSettings); $model->current(); }
/** * @param string|null $fixtureSegment * @param string $inputCacheType * @param string $expectedFrontendId * * @dataProvider getDataProvider */ public function testGet($fixtureSegment, $inputCacheType, $expectedFrontendId) { $this->_deploymentConfig->expects($this->once())->method('getSegment')->with(\Magento\Framework\App\DeploymentConfig\CacheConfig::CONFIG_KEY)->will($this->returnValue($fixtureSegment)); $cacheFrontend = $this->getMock('Magento\\Framework\\Cache\\FrontendInterface'); $this->_cachePool->expects($this->once())->method('get')->with($expectedFrontendId)->will($this->returnValue($cacheFrontend)); $accessProxy = $this->getMock('Magento\\Framework\\App\\Cache\\Type\\AccessProxy', [], [], '', false); $this->_objectManager->expects($this->once())->method('create')->with('Magento\\Framework\\App\\Cache\\Type\\AccessProxy', $this->identicalTo(['frontend' => $cacheFrontend, 'identifier' => $inputCacheType]))->will($this->returnValue($accessProxy)); $this->assertSame($accessProxy, $this->_model->get($inputCacheType)); // Result has to be cached in memory $this->assertSame($accessProxy, $this->_model->get($inputCacheType)); }
/** * Retrieve cache frontend instance by a cache type identifier, enforcing identifier-scoped access control * * @param string $cacheType Cache type identifier * @return \Magento\Framework\Cache\FrontendInterface Cache frontend instance */ public function get($cacheType) { if (!isset($this->_instances[$cacheType])) { $frontendId = $this->_getCacheFrontendId($cacheType); $frontendInstance = $this->_frontendPool->get($frontendId); /** @var $frontendInstance AccessProxy */ $frontendInstance = $this->_objectManager->create('Magento\\Framework\\App\\Cache\\Type\\AccessProxy', ['frontend' => $frontendInstance, 'identifier' => $cacheType]); $this->_instances[$cacheType] = $frontendInstance; } return $this->_instances[$cacheType]; }
/** * @param string|null $fixtureFrontendId * @param string $inputCacheType * @param string $expectedFrontendId * * @dataProvider getDataProvider */ public function testGet($fixtureFrontendId, $inputCacheType, $expectedFrontendId) { $this->_arguments->expects($this->once())->method('getCacheTypeFrontendId')->with($inputCacheType)->will($this->returnValue($fixtureFrontendId)); $cacheFrontend = $this->getMock('Magento\\Framework\\Cache\\FrontendInterface'); $this->_cachePool->expects($this->once())->method('get')->with($expectedFrontendId)->will($this->returnValue($cacheFrontend)); $accessProxy = $this->getMock('Magento\\Framework\\App\\Cache\\Type\\AccessProxy', array(), array(), '', false); $this->_objectManager->expects($this->once())->method('create')->with('Magento\\Framework\\App\\Cache\\Type\\AccessProxy', $this->identicalTo(array('frontend' => $cacheFrontend, 'identifier' => $inputCacheType)))->will($this->returnValue($accessProxy)); $this->assertSame($accessProxy, $this->_model->get($inputCacheType)); // Result has to be cached in memory $this->assertSame($accessProxy, $this->_model->get($inputCacheType)); }
/** * @param \Magento\Framework\App\Cache\Frontend\Pool $frontendPool */ public function __construct(\Magento\Framework\App\Cache\Frontend\Pool $frontendPool) { $this->_frontendPool = $frontendPool; $this->_frontend = $frontendPool->get($this->_frontendIdentifier); }
/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage Cache frontend 'unknown' is not recognized */ public function testGetUnknownFrontendId() { $this->_model->get('unknown'); }