Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 protected function initializeFromContext(ContextInterface $context)
 {
     if (!$context->hasOption('entityName')) {
         throw new InvalidConfigurationException('Configuration of fixture reader must contain "entityName".');
     }
     $this->fixture = $this->templateManager->getEntityFixture($context->getOption('entityName'));
     $this->setSourceIterator($this->fixture->getData());
 }
Exemplo n.º 2
0
 public function testGetData()
 {
     $templateManager = new TemplateManager(new TemplateEntityRegistry());
     $templateManager->addEntityRepository(new EmptyFixture('\\stdClass'));
     $fixture = $templateManager->getEntityFixture('\\stdClass');
     $data = $fixture->getData();
     $this->assertCount(1, $data);
     $this->assertInstanceOf('\\stdClass', reset($data));
 }
 public function testGetEntityData()
 {
     $entityKey = 'test1';
     $entity = new \stdClass();
     $repository = $this->getMock('Oro\\Bundle\\ImportExportBundle\\TemplateFixture\\TemplateEntityRepositoryInterface');
     $repository->expects($this->once())->method('getEntityClass')->will($this->returnValue(self::ENTITY_CLASS));
     $this->templateManager->addEntityRepository($repository);
     $this->templateRepository->expects($this->once())->method('createEntity')->with($entityKey)->will($this->returnValue($entity));
     $repository->expects($this->once())->method('fillEntityData')->with($entityKey, $this->identicalTo($entity));
     // test that new entity is created
     $data = $this->callProtectedMethod($this->templateRepository, 'getEntityData', [$entityKey]);
     $data = iterator_to_array($data);
     $this->assertSame($entity, current($data));
     $this->assertSame($entity, $this->entityRegistry->getEntity(self::ENTITY_CLASS, $entityKey));
     // test that existing entity is returned
     $data = $this->callProtectedMethod($this->templateRepository, 'getEntityData', [$entityKey]);
     $data = iterator_to_array($data);
     $this->assertSame($entity, current($data));
     $this->assertSame($entity, $this->entityRegistry->getEntity(self::ENTITY_CLASS, $entityKey));
 }
 /**
  * {@inheritdoc}
  */
 public function getMaxRelatedEntities($entityName, $fieldName)
 {
     $maxFields = 1;
     $fixtures = $this->templateManager->getEntityFixture($entityName)->getData();
     foreach ($fixtures as $fixture) {
         try {
             $fieldValue = $this->fieldHelper->getObjectValue($fixture, $fieldName);
             if ($fieldValue instanceof \Countable || is_array($fieldValue)) {
                 $itemsCount = count($fieldValue);
                 if ($itemsCount > $maxFields) {
                     $maxFields = $itemsCount;
                 }
             }
         } catch (\Exception $e) {
             // there is no $fieldName in fixture
             continue;
         }
     }
     return $maxFields;
 }
Exemplo n.º 5
0
 /**
  * Makes sure all entities in this registry are ready to work.
  * It means that all properties of these entities are filled.
  *
  * @param TemplateManager $templateManager
  */
 protected function ensureReadyToWork(TemplateManager $templateManager)
 {
     while ($this->isDirty) {
         $this->isDirty = false;
         foreach ($this->entities as $className => &$entities) {
             foreach ($entities as $entityKey => &$val) {
                 if ($val['isDirty']) {
                     $repository = $templateManager->getEntityRepository($className);
                     $repository->fillEntityData($entityKey, $val['entity']);
                     $val['isDirty'] = false;
                 }
             }
         }
     }
 }
Exemplo n.º 6
0
 /**
  * @return TemplateManager
  */
 protected function getTemplateManager()
 {
     $entityRegistry = new TemplateEntityRegistry();
     $templateManager = new TemplateManager($entityRegistry);
     $templateManager->addEntityRepository(new CountryFixture());
     $templateManager->addEntityRepository(new RegionFixture());
     $templateManager->addEntityRepository(new AddressTypeFixture());
     $templateManager->addEntityRepository($this->fixture);
     return $templateManager;
 }
 /**
  * @param string $key
  *
  * @return \Iterator
  */
 protected function getEntityData($key)
 {
     $this->ensureEntityRegistered($key);
     return $this->templateManager->getEntityRegistry()->getData($this->templateManager, $this->getEntityClass(), $key);
 }
Exemplo n.º 8
0
 public function testInitialization()
 {
     $repository = new TestTemplateEntityRepository();
     $this->templateManager->addEntityRepository($repository);
     $this->assertSame($this->templateManager, $this->templateManager->getEntityRepository($repository->getEntityClass())->getTemplateManager());
 }