public function flush()
 {
     $models = array();
     foreach ($this->persistConfigs as $config) {
         $this->calculateConfigChangeSet($config);
         $this->eventDispatcher->dispatch(Events::PRE_PERSIST_CONFIG, new PersistConfigEvent($config, $this));
         if (isset($models[$config->getId()->toString()])) {
             $model = $models[$config->getId()->toString()];
         } else {
             $model = $this->modelManager->getModelByConfigId($config->getId());
             $models[$config->getId()->toString()] = $model;
         }
         //TODO::refactoring
         $serializableValues = $this->getProvider($config->getId()->getScope())->getPropertyConfig()->getSerializableValues($config->getId());
         $model->fromArray($config->getId()->getScope(), $config->all(), $serializableValues);
         if ($this->cache) {
             $this->cache->removeConfigFromCache($config->getId());
             $this->cache->removeAllConfigurable();
         }
     }
     $this->auditManager->log();
     foreach ($models as $model) {
         $this->getEntityManager()->persist($model);
     }
     $this->getEntityManager()->flush();
     $this->persistConfigs = new \SplObjectStorage();
     $this->configChangeSets = new ArrayCollection();
 }
 public function testGetModelByConfigId()
 {
     $meta = $this->em->getClassMetadata(EntityConfigModel::ENTITY_NAME);
     $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $em->expects($this->any())->method('getRepository')->will($this->returnValue(new FoundEntityConfigRepository($em, $meta)));
     $serviceLink = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\DependencyInjection\\Utils\\ServiceLink')->disableOriginalConstructor()->getMock();
     $serviceLink->expects($this->any())->method('getService')->will($this->returnValue($em));
     $configModelManager = new ConfigModelManager($serviceLink);
     $this->assertEquals(FoundEntityConfigRepository::getResultConfigEntity(), $configModelManager->getModelByConfigId(new EntityConfigId(DemoEntity::ENTITY_NAME, 'test')));
 }