Example #1
0
 /**
  * @param string $scope
  * @param string $className
  *
  * @return ConfigInterface
  *
  * @throws RuntimeException
  */
 public function getEntityConfig($scope, $className)
 {
     $config = $this->cache->getEntityConfig($scope, $className);
     if (!$config) {
         if (!$this->modelManager->checkDatabase()) {
             throw $this->createDatabaseNotSyncedException();
         }
         $isConfigurableEntity = $this->cache->getConfigurable($className);
         if (null === $isConfigurableEntity) {
             $isConfigurableEntity = null !== $this->modelManager->findEntityModel($className);
             $this->cache->saveConfigurable($isConfigurableEntity, $className);
         }
         if (!$isConfigurableEntity) {
             throw new RuntimeException(sprintf('Entity "%s" is not configurable', $className));
         }
         $config = new Config(new EntityConfigId($scope, $className), $this->modelManager->getEntityModel($className)->toArray($scope));
         // put to a cache
         $this->cache->saveConfig($config);
     }
     // for calculate change set
     $cacheKey = $scope . '.' . $className;
     if (!isset($this->originalConfigs[$cacheKey])) {
         $this->originalConfigs[$cacheKey] = clone $config;
     }
     return $config;
 }
Example #2
0
 public function testDeleteAllConfigsLocalCacheOnly()
 {
     $config = new Config(new EntityConfigId(self::SCOPE, self::ENTITY_CLASS), ['key1' => 'val1']);
     $this->configCache->saveConfig($config, true);
     $this->cache->expects($this->never())->method('deleteAll');
     $this->assertTrue($this->configCache->deleteAllConfigs(true));
     // check that a local cache is cleaned up
     $this->assertNull($this->configCache->getEntityConfig(self::SCOPE, self::ENTITY_CLASS, true));
 }
Example #3
0
 public function testGetEntityConfigNotCachedScope()
 {
     $configId = new EntityConfigId(self::SCOPE, self::ENTITY_CLASS);
     $anotherConfigId = new EntityConfigId('another', self::ENTITY_CLASS);
     $anotherConfigValues = ['key2' => 'val2'];
     $anotherConfig = new Config($anotherConfigId, $anotherConfigValues);
     $cacheKey = self::ENTITY_CLASS;
     $this->cache->expects($this->once())->method('fetch')->with($cacheKey)->willReturn(['another' => $anotherConfigValues]);
     $this->assertNull($this->configCache->getEntityConfig($configId->getScope(), $configId->getClassName()));
     // test local cache
     $this->assertNull($this->configCache->getEntityConfig($configId->getScope(), $configId->getClassName()));
     $this->assertEquals($anotherConfig, $this->configCache->getEntityConfig($anotherConfigId->getScope(), $anotherConfigId->getClassName()));
 }