/** * @covers \Migration\Step\SalesOrder\Integrity::checkEavEntities * @covers \Migration\Step\SalesOrder\Integrity::getEavEntities * @covers \Migration\Step\SalesOrder\Integrity::getIterationsCount * @return void */ public function testPerform() { $fields = ['field1' => ['DATA_TYPE' => 'int']]; $destinationRecord = ['attribute_code' => 'eav_entity']; $this->helper->expects($this->any())->method('getDocumentList')->willReturn(['source_doc' => 'dest_doc']); $this->helper->expects($this->once())->method('getDestEavDocument')->willReturn('eav_entity_int'); $this->helper->expects($this->once())->method('getEavAttributes')->willReturn(['eav_entity']); $this->progress->expects($this->once())->method('start')->with(3); $this->progress->expects($this->any())->method('advance'); $structure = $this->getMockBuilder('\\Migration\\ResourceModel\\Structure')->disableOriginalConstructor()->setMethods([])->getMock(); $structure->expects($this->any())->method('getFields')->willReturn($fields); $document = $this->getMockBuilder('\\Migration\\ResourceModel\\Document')->disableOriginalConstructor()->getMock(); $document->expects($this->any())->method('getStructure')->willReturn($structure); $this->source->expects($this->any())->method('getDocumentList')->willReturn(['source_doc']); $this->destination->expects($this->once())->method('getDocumentList')->willReturn(['dest_doc']); $this->destination->expects($this->any())->method('getDocument')->willReturn($document); $this->destination->expects($this->at(3))->method('getRecords')->willReturn([0 => $destinationRecord]); $this->destination->expects($this->at(4))->method('getRecords')->willReturn(null); $this->map->expects($this->any())->method('isDocumentIgnored')->willReturn(false); $this->map->expects($this->at(1))->method('getDocumentMap')->willReturn('dest_doc'); $this->map->expects($this->at(4))->method('getDocumentMap')->willReturn('source_doc'); $this->map->expects($this->any())->method('getFieldMap')->willReturn('field1'); $this->source->expects($this->any())->method('getDocument')->willReturn($document); $this->logger->expects($this->never())->method('error'); $this->salesOrder->perform(); }
/** * @covers \Migration\Step\SalesOrder\InitialData::initDestAttributes * @covers \Migration\Step\SalesOrder\InitialData::getDestEavAttributesCount * @return void */ public function testInit() { $eavEntityDocument = 'eav_entity_int'; $this->helper->expects($this->once())->method('getDestEavDocument')->willReturn($eavEntityDocument); $this->destination->expects($this->once())->method('getRecordsCount')->willReturn(2); $this->initialData->init(); $this->assertEquals($this->initialData->getDestEavAttributesCount($eavEntityDocument), 2); }
/** * @covers \Migration\Step\SalesOrder\Data::prepareEavEntityData * @covers \Migration\Step\SalesOrder\Data::getAttributeData * @covers \Migration\Step\SalesOrder\Data::getAttributeValue * @covers \Migration\Step\SalesOrder\Data::getDestEavDocument * @return void */ public function testGetMap() { $sourceDocumentName = 'source_document'; $destinationDocumentName = 'destination_document'; $eavAttributes = ['eav_attr_1', 'eav_attr_2']; $eavAttributeData = ['entity_type_id' => 1, 'attribute_id' => 2, 'attribute_code' => 'eav_attr_1']; $this->helper->expects($this->any())->method('getDocumentList')->willReturn([$sourceDocumentName => $destinationDocumentName]); $this->helper->expects($this->once())->method('getDestEavDocument')->willReturn('eav_document'); $this->helper->expects($this->at(3))->method('getEavAttributes')->willReturn($eavAttributes); $this->map->expects($this->once())->method('getDocumentMap')->willReturn($destinationDocumentName); $sourceDocument = $this->getMock('\\Migration\\ResourceModel\\Document', ['getRecords'], [], '', false); $this->source->expects($this->once())->method('getDocument')->willReturn($sourceDocument); $this->source->expects($this->any())->method('getRecordsCount')->willReturn(2); $destinationDocument = $this->getMock('\\Migration\\ResourceModel\\Document', [], [], '', false); $eavDestinationDocument = $this->getMock('\\Migration\\ResourceModel\\Document', [], [], '', false); $dstDocName = 'destination_document'; $eavDstDocName = 'eav_document'; $this->destination->expects($this->any())->method('getDocument')->willReturnMap([[$dstDocName, $destinationDocument], [$eavDstDocName, $eavDestinationDocument]]); $recordTransformer = $this->getMock('Migration\\RecordTransformer', ['init', 'transform'], [], '', false); $this->recordTransformerFactory->expects($this->once())->method('create')->willReturn($recordTransformer); $recordTransformer->expects($this->once())->method('init'); $bulk = [['eav_attr_1' => 'attribute_value', 'store_id' => '1', 'entity_id' => '2']]; $this->source->expects($this->at(3))->method('getRecords')->willReturn($bulk); $this->source->expects($this->at(4))->method('getRecords')->willReturn([]); $destinationRecords = $this->getMock('\\Migration\\ResourceModel\\Record\\Collection', [], [], '', false); $eavDestinationRecords = $this->getMock('\\Migration\\ResourceModel\\Record\\Collection', [], [], '', false); $destinationDocument->expects($this->once())->method('getRecords')->willReturn($destinationRecords); $srcRecord = $this->getMock('\\Migration\\ResourceModel\\Record', [], [], '', false); $dstRecord = $this->getMock('\\Migration\\ResourceModel\\Record', [], [], '', false); $this->recordFactory->expects($this->at(0))->method('create')->willReturn($srcRecord); $this->recordFactory->expects($this->at(1))->method('create')->willReturn($dstRecord); $recordTransformer->expects($this->once())->method('transform')->with($srcRecord, $dstRecord); $eavDestinationDocument->expects($this->once())->method('getRecords')->willReturn($eavDestinationRecords); $eavDestinationRecords->expects($this->once())->method('addRecord'); $this->destination->expects($this->at(5))->method('saveRecords')->with($dstDocName, $destinationRecords); $this->destination->expects($this->at(6))->method('saveRecords')->with($eavDstDocName, $eavDestinationRecords); $this->destination->expects($this->once())->method('clearDocument')->with($dstDocName); $this->destination->expects($this->at(3))->method('getRecords')->willReturn([0 => $eavAttributeData]); $this->logger->expects($this->any())->method('debug')->with('migrating', ['table' => $sourceDocumentName])->willReturn(true); $this->salesOrder->perform(); }
/** * @param string $documentName * @param string $idKey * @return void */ protected function processChangedRecords($documentName, $idKey) { $destinationName = $this->mapReader->getDocumentMap($documentName, MapInterface::TYPE_SOURCE); $items = $this->source->getChangedRecords($documentName, $idKey); $sourceDocument = $this->source->getDocument($documentName); $destDocument = $this->destination->getDocument($destinationName); $recordTransformer = $this->getRecordTransformer($sourceDocument, $destDocument); $eavDocumentName = $this->helper->getDestEavDocument(); $eavDocumentResource = $this->destination->getDocument($eavDocumentName); do { $destinationRecords = $destDocument->getRecords(); $destEavCollection = $eavDocumentResource->getRecords(); $ids = []; foreach ($items as $data) { echo '.'; $ids[] = $data[$idKey]; $this->transformData($data, $sourceDocument, $destDocument, $recordTransformer, $destinationRecords); $this->data->migrateAdditionalOrderData($data, $sourceDocument, $destEavCollection); } $this->destination->updateChangedRecords($destinationName, $destinationRecords); $this->destination->updateChangedRecords($eavDocumentName, $destEavCollection); $this->markRecordsProcessed($this->source->getDeltaLogName($documentName), $idKey, $ids); } while (!empty($items = $this->source->getChangedRecords($documentName, $idKey))); }
/** * @return void */ public function testPerformFailExistingDocumentEntities() { $sourceDocumentName = 'source_document'; $destDocumentName = 'dest_document'; $eavDocumentName = 'eav_entity_int'; $eavAttributes = ['eav_attribute_1', 'eav_attribute_2']; $this->helper->expects($this->any())->method('getDocumentList')->willReturn([$sourceDocumentName => $destDocumentName]); $this->helper->expects($this->any())->method('getEavAttributes')->willReturn($eavAttributes); $this->helper->expects($this->any())->method('getDestEavDocument')->willReturn($eavDocumentName); $this->helper->expects($this->at(3))->method('getSourceAttributes')->willReturn(1); $this->helper->expects($this->at(4))->method('getSourceAttributes')->willReturn(0); $this->progress->expects($this->any())->method('start')->with(1); $this->progress->expects($this->once())->method('advance'); $this->map->expects($this->any())->method('getDocumentMap')->with($sourceDocumentName)->willReturn($destDocumentName); $this->source->expects($this->any())->method('getRecordsCount')->with($sourceDocumentName)->willReturn(1); $this->destination->expects($this->any())->method('getRecordsCount')->willReturnMap([[$destDocumentName, true, [], 2], [$eavDocumentName, true, [], 1]]); $this->initialData->expects($this->once())->method('getDestEavAttributesCount')->with('eav_entity_int')->willReturn(0); $this->logger->expects($this->once())->method('addRecord')->with(Logger::WARNING, 'Mismatch of entities in the document: ' . $destDocumentName); $this->assertFalse($this->salesOrder->perform()); }
/** * Get iterations count for step * * @return int */ protected function getIterationsCount() { $migrationDocuments = $this->helper->getDocumentList(); $documents = [$this->helper->getDestEavDocument(), array_keys($migrationDocuments), array_values($migrationDocuments)]; return count($documents); }
/** * Load EAV data before migration * @return void */ public function init() { $this->initDestAttributes($this->helper->getDestEavDocument()); }
/** * @return void */ public function testGetDestEavDocument() { $destEavDocument = 'eav_entity_int'; $this->assertEquals($destEavDocument, $this->helper->getDestEavDocument()); }
/** * @return int */ protected function getDestEavDocument() { return count($this->helper->getDocumentList()); }