/** * @param string|null $className * @param string|null $mode * @return EntityConfigModel */ public function createConfigEntityModel($className = null, $mode = ConfigModelManager::MODE_DEFAULT) { if (empty($className)) { $entityModel = $this->modelManager->createEntityModel($className, $mode); } else { $entityModel = $this->modelManager->findEntityModel($className); if (null === $entityModel) { $metadata = $this->getEntityMetadata($className); $newEntityMode = $metadata ? $metadata->mode : $mode; $entityModel = $this->modelManager->createEntityModel($className, $newEntityMode); foreach ($this->getProviders() as $provider) { $configId = new EntityConfigId($provider->getScope(), $className); $config = new Config($configId, $this->getEntityDefaultValues($provider, $className, $metadata)); $this->merge($config); // local cache $this->cache->saveConfig($config, true); $this->cache->saveConfigurable(true, $className, null, true); // for calculate change set $this->originalConfigs[$this->buildConfigKey($configId)] = clone $config; } $this->eventDispatcher->dispatch(Events::NEW_ENTITY_CONFIG, new EntityConfigEvent($className, $this)); } } return $entityModel; }
public function testFindEntityModelAllDetached() { $entityModel = $this->createEntityModel(self::TEST_ENTITY); $repo = $this->createRepositoryMock([$entityModel, $this->createEntityModel('Test\\Entity\\AnotherEntity')], [UnitOfWork::STATE_DETACHED, UnitOfWork::STATE_DETACHED, UnitOfWork::STATE_DETACHED, UnitOfWork::STATE_MANAGED, UnitOfWork::STATE_MANAGED], 2); $repo->expects($this->never())->method('findOneBy'); $this->assertSame($entityModel, $this->configModelManager->findEntityModel(self::TEST_ENTITY)); // test localCache $this->assertSame($entityModel, $this->configModelManager->findEntityModel(self::TEST_ENTITY)); }
/** * Checks whether an entity is configurable. * * @param string $className * * @return bool */ protected function isConfigurableEntity($className) { $isConfigurable = $this->cache->getConfigurable($className); if (null === $isConfigurable) { $isConfigurable = null !== $this->modelManager->findEntityModel($className); $this->cache->saveConfigurable($isConfigurable, $className); } return $isConfigurable; }
public function testThatEntityListAreLoadedAfterConfigurableEntityIsLoaded() { $entityModel0 = $this->createEntityModel('Test\\ConfigurableEntity'); ReflectionUtil::setId($entityModel0, 123); $entityModel1 = $this->createEntityModel(self::TEST_ENTITY); $entityModel2 = $this->createEntityModel(self::TEST_ENTITY2); $this->repo->expects($this->once())->method('findOneBy')->with(['className' => 'Test\\ConfigurableEntity'])->will($this->returnValue($entityModel0)); $query = $this->getMockBuilder('Doctrine\\ORM\\AbstractQuery')->disableOriginalConstructor()->setMethods(['getResult'])->getMockForAbstractClass(); $qb = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock(); $this->repo->expects($this->once())->method('createQueryBuilder')->with('e')->willReturn($qb); $qb->expects($this->once())->method('where')->with('e.id NOT IN (:exclusions)')->willReturnSelf(); $qb->expects($this->once())->method('setParameter')->with('exclusions', [$entityModel0->getId()])->willReturnSelf(); $qb->expects($this->once())->method('getQuery')->willReturn($query); $query->expects($this->once())->method('getResult')->will($this->returnValue([$entityModel1, $entityModel2])); $this->prepareCheckDetached([UnitOfWork::STATE_MANAGED, UnitOfWork::STATE_MANAGED, UnitOfWork::STATE_MANAGED, UnitOfWork::STATE_MANAGED]); $this->assertSame($entityModel0, $this->configModelManager->findEntityModel('Test\\ConfigurableEntity')); $this->assertEquals([$entityModel0, $entityModel1, $entityModel2], $this->configModelManager->getModels()); // test localCache $this->assertSame($entityModel0, $this->configModelManager->findEntityModel('Test\\ConfigurableEntity')); $this->assertSame($entityModel1, $this->configModelManager->findEntityModel(self::TEST_ENTITY)); $this->assertSame($entityModel2, $this->configModelManager->findEntityModel(self::TEST_ENTITY2)); }