public function testGetDataForSeveralEntity() { $entity1 = new \stdClass(); $entity2 = new \stdClass(); $entity3 = new \stdClass(); $this->entityRegistry->addEntity('Test\\Entity1', 'test1', $entity1); $repository1 = $this->getMock('Oro\\Bundle\\ImportExportBundle\\TemplateFixture\\TemplateEntityRepositoryInterface'); $repository2 = $this->getMock('Oro\\Bundle\\ImportExportBundle\\TemplateFixture\\TemplateEntityRepositoryInterface'); $templateManager = $this->getMockBuilder('Oro\\Bundle\\ImportExportBundle\\TemplateFixture\\TemplateManager')->disableOriginalConstructor()->getMock(); $templateManager->expects($this->at(0))->method('getEntityRepository')->with('Test\\Entity1')->will($this->returnValue($repository1)); $repository1->expects($this->at(0))->method('fillEntityData')->with('test1', $this->identicalTo($entity1))->will($this->returnCallback(function ($key, $entity) use($entity2) { $this->entityRegistry->addEntity('Test\\Entity2', 'test2', $entity2); })); $templateManager->expects($this->at(1))->method('getEntityRepository')->with('Test\\Entity2')->will($this->returnValue($repository2)); $repository2->expects($this->once())->method('fillEntityData')->with('test2', $this->identicalTo($entity2))->will($this->returnCallback(function ($key, $entity) use($entity3) { $this->entityRegistry->addEntity('Test\\Entity1', 'test3', $entity3); })); $templateManager->expects($this->at(2))->method('getEntityRepository')->with('Test\\Entity1')->will($this->returnValue($repository1)); $repository1->expects($this->at(1))->method('fillEntityData')->with('test3', $this->identicalTo($entity3)); $data = $this->entityRegistry->getData($templateManager, 'Test\\Entity1'); $data = iterator_to_array($data); $this->assertCount(2, $data); $this->assertSame($entity1, $data[0]); $this->assertSame($entity3, $data[1]); }
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)); }