/** * {@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()); }
public function testGetEntityFixture() { $repository = $this->getMock('Oro\\Bundle\\ImportExportBundle\\TemplateFixture\\TemplateEntityRepositoryInterface'); $repository->expects($this->once())->method('getEntityClass')->will($this->returnValue('Test\\Entity1')); $fixture = $this->getMock('Oro\\Bundle\\ImportExportBundle\\TemplateFixture\\TemplateFixtureInterface'); $fixture->expects($this->once())->method('getEntityClass')->will($this->returnValue('Test\\Entity2')); $this->templateManager->addEntityRepository($repository); $this->templateManager->addEntityRepository($fixture); $this->assertSame($fixture, $this->templateManager->getEntityFixture('Test\\Entity2')); $this->setExpectedException('Oro\\Bundle\\ImportExportBundle\\Exception\\InvalidConfigurationException', 'The template fixture for "Test\\Entity1" was not registered.'); $this->templateManager->getEntityFixture('Test\\Entity1'); }
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)); }
/** * {@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; }
public function testGetEntityFixtureForUnknownEntityType() { $fixture = $this->templateManager->getEntityFixture('Test\\Entity1'); $this->assertInstanceOf('Oro\\Bundle\\ImportExportBundle\\TemplateFixture\\EmptyFixture', $fixture); $this->assertEquals('Test\\Entity1', $fixture->getEntityClass()); }