public function testChangeFieldType() { $entityModel = $this->createEntityModel(self::TEST_ENTITY); $fieldModel = $this->createFieldModel($entityModel, self::TEST_FIELD); $this->createRepositoryMock([$entityModel], [UnitOfWork::STATE_MANAGED, UnitOfWork::STATE_MANAGED, UnitOfWork::STATE_MANAGED]); $this->em->expects($this->once())->method('persist')->with($this->equalTo($fieldModel)); $this->em->expects($this->never())->method('flush'); $result = $this->configModelManager->changeFieldType(self::TEST_ENTITY, self::TEST_FIELD, 'int'); $this->assertTrue($result); $this->assertEquals('int', $this->configModelManager->getFieldModel(self::TEST_ENTITY, self::TEST_FIELD)->getType()); }
/** * @param array $models */ protected function prepareFlush(&$models) { foreach ($this->persistConfigs as $config) { $this->calculateConfigChangeSet($config); $this->eventDispatcher->dispatch(Events::PRE_PERSIST_CONFIG, new PersistConfigEvent($config, $this)); $configId = $config->getId(); $configKey = $configId instanceof FieldConfigId ? sprintf('%s_%s', $configId->getClassName(), $configId->getFieldName()) : $configId->getClassName(); if (isset($models[$configKey])) { $model = $models[$configKey]; } else { $model = $configId instanceof FieldConfigId ? $this->modelManager->getFieldModel($configId->getClassName(), $configId->getFieldName()) : $this->modelManager->getEntityModel($configId->getClassName()); $models[$configKey] = $model; } $indexedValues = $this->getProvider($config->getId()->getScope())->getPropertyConfig()->getIndexedValues($config->getId()); $model->fromArray($config->getId()->getScope(), $config->all(), $indexedValues); if ($this->cache) { $this->cache->removeConfigFromCache($config->getId()); } } if (count($this->persistConfigs) != count($this->configChangeSets)) { $this->prepareFlush($models); } }
/** * Gets a model for the given config id * * @param ConfigIdInterface $configId * * @return ConfigModel */ protected function getModelByConfigId(ConfigIdInterface $configId) { return $configId instanceof FieldConfigId ? $this->modelManager->getFieldModel($configId->getClassName(), $configId->getFieldName()) : $this->modelManager->getEntityModel($configId->getClassName()); }