/** * {@inheritdoc} */ public function isApplicableTarget(ConfigIdInterface $configId, ConfigManager $configManager) { if ($configId->getClassName() === 'Acme\\DemoBundle\\Entity\\CorrectEntity') { return true; } return false; }
/** * {@inheritdoc} */ public function isApplicableTarget(ConfigIdInterface $configId, ConfigManager $configManager) { if ($configId->getClassName() === self::SUPPORTED_TARGET_CLASS_NAME) { return true; } return false; }
/** * @param ConfigIdInterface $configId * @param bool $immutable */ protected function setIsReadOnlyExpectations(ConfigIdInterface $configId, $immutable) { $className = $configId->getClassName(); if (empty($className)) { $this->typeHelper->expects($this->never())->method('isImmutable'); } else { $this->typeHelper->expects($this->once())->method('getFieldName')->with($this->identicalTo($configId))->will($this->returnValue($configId instanceof FieldConfigId ? $configId->getFieldName() : null)); $this->typeHelper->expects($this->once())->method('isImmutable')->with($configId->getScope(), $configId->getClassName(), $configId instanceof FieldConfigId ? $configId->getFieldName() : null)->will($this->returnValue($immutable)); } }
/** * @dataProvider setDefaultOptionsProvider */ public function testSetDefaultOptions(ConfigIdInterface $configId, $isNewConfig, $enumCode, $isSystem, $isImmutablePublic, $hasOtherReferences, $options, $expectedOptions) { $fieldName = $configId instanceof FieldConfigId ? $configId->getFieldName() : null; $enumValueClassName = $enumCode ? ExtendHelper::buildEnumValueClassName($enumCode) : null; $this->typeHelper->expects($this->any())->method('getEnumCode')->with($configId->getClassName(), $fieldName)->will($this->returnValue($enumCode)); $this->typeHelper->expects($this->any())->method('isSystem')->with($configId->getClassName(), $fieldName)->will($this->returnValue($isSystem)); $this->typeHelper->expects($this->any())->method('isImmutable')->with('enum', $enumValueClassName, null, 'public')->will($this->returnValue($isImmutablePublic)); $this->typeHelper->expects($this->any())->method('hasOtherReferences')->with($enumCode, $configId->getClassName(), $fieldName)->will($this->returnValue($hasOtherReferences)); $resolver = $this->getOptionsResolver(); $this->type->setDefaultOptions($resolver); $options['config_id'] = $configId; $options['config_is_new'] = $isNewConfig; $resolvedOptions = $resolver->resolve($options); $this->assertSame($configId, $resolvedOptions['config_id']); unset($resolvedOptions['config_id']); $this->assertEquals($isNewConfig, $resolvedOptions['config_is_new']); unset($resolvedOptions['config_is_new']); $this->assertEquals($expectedOptions, $resolvedOptions); }
/** * @dataProvider setDefaultOptionsProvider */ public function testSetDefaultOptions(ConfigIdInterface $configId, $isNewConfig, $enumCode, $isImmutableAdd, $isImmutableDelete, $options, $expectedOptions) { $enumValueClassName = $enumCode ? ExtendHelper::buildEnumValueClassName($enumCode) : null; $this->typeHelper->expects($this->any())->method('getEnumCode')->with($configId->getClassName(), $configId instanceof FieldConfigId ? $configId->getFieldName() : null)->will($this->returnValue($enumCode)); $this->typeHelper->expects($this->any())->method('isImmutable')->will($this->returnValueMap([['enum', $enumValueClassName, null, 'add', $isImmutableAdd], ['enum', $enumValueClassName, null, 'delete', $isImmutableDelete]])); $resolver = $this->getOptionsResolver(); $this->type->setDefaultOptions($resolver); $options['config_id'] = $configId; $options['config_is_new'] = $isNewConfig; $resolvedOptions = $resolver->resolve($options); $this->assertSame($configId, $resolvedOptions['config_id']); unset($resolvedOptions['config_id']); $this->assertEquals($isNewConfig, $resolvedOptions['config_is_new']); unset($resolvedOptions['config_is_new']); $this->assertFalse($resolvedOptions['handle_primary']); unset($resolvedOptions['handle_primary']); $this->assertEquals('oro_entity_extend_enum_value', $resolvedOptions['type']); unset($resolvedOptions['type']); $this->assertEquals($expectedOptions, $resolvedOptions); }
/** * @dataProvider setDefaultOptionsProvider */ public function testSetDefaultOptions(ConfigIdInterface $configId, $isNewConfig, $hasEnumCode, $options, $expectedOptions) { $fieldName = $configId instanceof FieldConfigId ? $configId->getFieldName() : null; $this->typeHelper->expects($this->any())->method('hasEnumCode')->with($configId->getClassName(), $fieldName)->will($this->returnValue($hasEnumCode)); $resolver = $this->getOptionsResolver(); $this->type->setDefaultOptions($resolver); $options['config_id'] = $configId; $options['config_is_new'] = $isNewConfig; $resolvedOptions = $resolver->resolve($options); $this->assertSame($configId, $resolvedOptions['config_id']); unset($resolvedOptions['config_id']); $this->assertEquals($isNewConfig, $resolvedOptions['config_is_new']); unset($resolvedOptions['config_is_new']); if ($hasEnumCode) { $this->assertCount(2, $resolvedOptions['constraints']); } else { $this->assertCount(5, $resolvedOptions['constraints']); } unset($resolvedOptions['constraints']); $this->assertEquals($expectedOptions, $resolvedOptions); }
/** * @param ConfigIdInterface $configId * * @return string */ protected function buildConfigCacheKey(ConfigIdInterface $configId) { return $configId instanceof FieldConfigId ? $configId->getClassName() . '_' . $configId->getFieldName() : $configId->getClassName(); }
/** * @dataProvider getConfigNotCachedProvider */ public function testGetConfigNotCached(ConfigIdInterface $configId, $getModelResult, $expectedConfig) { $this->modelManager->expects($this->any())->method('checkDatabase')->willReturn(true); if ($configId instanceof FieldConfigId) { $this->configCache->expects($this->exactly(2))->method('getConfigurable')->willReturnMap([[$configId->getClassName(), null, true], [$configId->getClassName(), $configId->getFieldName(), true]]); $this->configCache->expects($this->once())->method('getFieldConfig')->with($configId->getScope(), $configId->getClassName(), $configId->getFieldName())->willReturn(null); } else { $this->configCache->expects($this->once())->method('getConfigurable')->with($configId->getClassName())->willReturn(true); $this->configCache->expects($this->once())->method('getEntityConfig')->with($configId->getScope(), $configId->getClassName())->willReturn(null); } $this->configCache->expects($this->once())->method('saveConfig')->with($this->equalTo($expectedConfig)); if ($configId instanceof FieldConfigId) { $this->modelManager->expects($this->never())->method('getEntityModel'); $this->modelManager->expects($this->once())->method('getFieldModel')->with($configId->getClassName(), $configId->getFieldName())->willReturn($getModelResult); } else { $this->modelManager->expects($this->once())->method('getEntityModel')->with($configId->getClassName())->willReturn($getModelResult); $this->modelManager->expects($this->never())->method('getFieldModel'); } $result = $this->configManager->getConfig($configId); $this->assertEquals($expectedConfig, $result); $this->configManager->calculateConfigChangeSet($result); $this->assertEquals([], $this->configManager->getConfigChangeSet($result)); }
/** * @param ConfigIdInterface $configId * @return bool */ public function hasConfigById(ConfigIdInterface $configId) { if ($configId instanceof FieldConfigId) { return $this->configManager->hasConfig($configId->getClassName(), $configId->getFieldName()); } else { return $this->configManager->hasConfig($configId->getClassName()); } }
/** * Gets configuration data for the given entity or field. * * @param ConfigIdInterface $configId * * @return ConfigInterface */ public function getConfigById(ConfigIdInterface $configId) { $className = $configId->getClassName(); if ($configId instanceof FieldConfigId) { return $this->configManager->getFieldConfig($this->scope, $className, $configId->getFieldName()); } elseif ($className) { return $this->configManager->getEntityConfig($this->scope, $className); } else { return $this->configManager->createEntityConfig($this->scope); } }
/** * Returns a string unique identifies each config item * * @param ConfigIdInterface $configId * @return string */ protected function buildConfigKey(ConfigIdInterface $configId) { return $configId instanceof FieldConfigId ? sprintf('%s_%s_%s', $configId->getScope(), $configId->getClassName(), $configId->getFieldName()) : sprintf('%s_%s', $configId->getScope(), $configId->getClassName()); }
/** * @param ConfigIdInterface $configId * @throws RuntimeException * @throws LogicException * @return ConfigInterface */ public function getConfig(ConfigIdInterface $configId) { if ($this->localCache->containsKey($configId->toString())) { return $this->localCache->get($configId->toString()); } if (!$this->modelManager->checkDatabase()) { throw new LogicException('Database is not synced, if you use ConfigManager, when a db schema may be hasn\'t synced.' . ' check it by ConfigManager::modelManager::checkDatabase'); } if (!$this->hasConfig($configId->getClassName())) { throw new RuntimeException(sprintf('Entity "%s" is not configurable', $configId->getClassName())); } $resultConfig = null !== $this->cache ? $this->cache->loadConfigFromCache($configId) : null; if (!$resultConfig) { $model = $this->modelManager->getModelByConfigId($configId); $config = new Config($this->getConfigIdByModel($model, $configId->getScope())); $config->setValues($model->toArray($configId->getScope())); if (null !== $this->cache) { $this->cache->putConfigInCache($config); } $resultConfig = $config; } //local cache $this->localCache->set($resultConfig->getId()->toString(), $resultConfig); //for calculate change set $this->originalConfigs->set($resultConfig->getId()->toString(), clone $resultConfig); return $resultConfig; }
/** * {@inheritdoc} */ public function getConfigById(ConfigIdInterface $configId) { return $configId instanceof FieldConfigId ? $this->getConfig($configId->getClassName(), $configId->getFieldName()) : $this->getConfig($configId->getClassName()); }
/** * @param ConfigIdInterface $configId * @return AbstractConfigModel */ public function getModelByConfigId(ConfigIdInterface $configId) { $fieldName = $configId instanceof FieldConfigId ? $configId->getFieldName() : null; return $this->getModel($configId->getClassName(), $fieldName); }