/** * @dataProvider setConfigurableProvider */ public function testSetConfigurable($flag, $expectedCacheValue) { $className = 'testClass'; $configCache = new ConfigCache($this->cacheProvider, $this->modelCacheProvider); $this->modelCacheProvider->expects($this->once())->method('save')->with($className, $this->identicalTo($expectedCacheValue))->will($this->returnValue(true)); $this->assertTrue($configCache->setConfigurable($flag, $className)); }
public function testCache() { $cacheProvider = $this->getMockBuilder('Doctrine\\Common\\Cache\\CacheProvider')->disableOriginalConstructor()->setMethods(array('fetch', 'save', 'delete', 'deleteAll'))->getMockForAbstractClass(); $modelCacheProvider = $this->getMockBuilder('Doctrine\\Common\\Cache\\CacheProvider')->disableOriginalConstructor()->setMethods(array('fetch', 'save', 'delete', 'deleteAll'))->getMockForAbstractClass(); $className = 'testClass'; $scope = 'testScope'; $configId = new EntityConfigId($className, $scope); $config = new Config($configId); $configCache = new ConfigCache($cacheProvider, $modelCacheProvider); $cacheProvider->expects($this->once())->method('save')->will($this->returnValue(true)); $this->assertTrue($configCache->putConfigInCache($config)); $cacheProvider->expects($this->once())->method('delete')->will($this->returnValue(true)); $this->assertTrue($configCache->removeConfigFromCache($configId)); $cacheProvider->expects($this->once())->method('deleteAll')->will($this->returnValue(true)); $this->assertTrue($configCache->removeAll()); $cacheProvider->expects($this->once())->method('fetch')->will($this->returnValue(serialize($config))); $this->assertEquals($config, $configCache->loadConfigFromCache($configId)); $value = 'testValue'; $modelCacheProvider->expects($this->once())->method('save')->will($this->returnValue(true)); $this->assertTrue($configCache->setConfigurable($value, $className)); $modelCacheProvider->expects($this->once())->method('fetch')->will($this->returnValue($value)); $this->assertEquals($value, $configCache->getConfigurable($className)); $modelCacheProvider->expects($this->once())->method('deleteAll')->will($this->returnValue(true)); $this->assertTrue($configCache->removeAllConfigurable()); }
/** * @param string $className * @param string $fieldName * @return bool */ public function hasConfig($className, $fieldName = null) { if (!$this->modelManager->checkDatabase()) { return false; } $result = $this->cache->getConfigurable($className, $fieldName); if ($result === false) { $result = (bool) $this->modelManager->findModel($className, $fieldName) ?: null; $this->cache->setConfigurable($result, $className, $fieldName); } return $result; }
/** * @param string $className * @param string $fieldName * @return bool */ public function hasConfig($className, $fieldName = null) { if (!$this->modelManager->checkDatabase()) { return false; } $result = $this->cache->getConfigurable($className, $fieldName); if (null === $result) { $model = $fieldName ? $this->modelManager->findFieldModel($className, $fieldName) : $this->modelManager->findEntityModel($className); $result = null !== $model; $this->cache->setConfigurable($result, $className, $fieldName); } return $result; }