/**
  * @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)));
 }
 /**
  * @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();
 }