public function testPerform() { $sourceDocName = 'core_config_data'; $this->source->expects($this->any())->method('getDocumentList')->will($this->returnValue([$sourceDocName])); $dstDocName = 'config_data'; $this->map->expects($this->once())->method('getDocumentMap')->will($this->returnValue($dstDocName)); $sourceDocument = $this->getMock('\\Migration\\Resource\\Document', ['getRecords'], [], '', false); $this->source->expects($this->once())->method('getDocument')->will($this->returnValue($sourceDocument)); $destinationDocument = $this->getMock('\\Migration\\Resource\\Document', [], [], '', false); $this->destination->expects($this->once())->method('getDocument')->will($this->returnValue($destinationDocument)); $recordTransformer = $this->getMock('Migration\\RecordTransformer', ['init', 'transform'], [], '', false); $this->recordTransformerFactory->expects($this->once())->method('create')->will($this->returnValue($recordTransformer)); $recordTransformer->expects($this->once())->method('init'); $bulk = [['id' => 4, 'name' => 'john']]; $this->source->expects($this->at(3))->method('getRecords')->will($this->returnValue($bulk)); $this->source->expects($this->at(4))->method('getRecords')->will($this->returnValue([])); $this->source->expects($this->any())->method('getRecordsCount')->will($this->returnValue(2)); $destinationRecords = $this->getMock('\\Migration\\Resource\\Record\\Collection', [], [], '', false); $destinationDocument->expects($this->once())->method('getRecords')->will($this->returnValue($destinationRecords)); $srcRecord = $this->getMock('\\Migration\\Resource\\Record', [], [], '', false); $dstRecord = $this->getMock('\\Migration\\Resource\\Record', [], [], '', false); $this->recordFactory->expects($this->at(0))->method('create')->will($this->returnValue($srcRecord)); $this->recordFactory->expects($this->at(1))->method('create')->will($this->returnValue($dstRecord)); $recordTransformer->expects($this->once())->method('transform')->with($srcRecord, $dstRecord); $this->destination->expects($this->once())->method('saveRecords')->with($dstDocName, $destinationRecords); $this->destination->expects($this->exactly(2))->method('clearDocument'); $this->logger->expects($this->any())->method('debug')->with('migrating', ['table' => 'source_document'])->willReturn(true); $this->data->perform(); }
public function testGetDestinationRecordsNoKey() { $row = ['key' => 'key_value', 'field' => 'field_value']; $this->map->expects($this->once())->method('getDocumentMap')->with('test_source_document', MapInterface::TYPE_SOURCE)->will($this->returnValue('test_dest_document')); $this->destination->expects($this->once())->method('getRecordsCount')->will($this->returnValue(1)); $this->destination->expects($this->once())->method('getRecords')->with('test_dest_document', 0, 1)->will($this->returnValue([$row])); $this->assertEquals([$row], $this->helper->getDestinationRecords('test_source_document')); }
public function testPerformFailed() { $sourceDocName = 'core_config_data'; $dstDocName = 'config_data'; $this->source->expects($this->once())->method('getDocumentList')->willReturn([$sourceDocName]); $this->map->expects($this->once())->method('getDocumentMap')->willReturn($dstDocName); $this->source->expects($this->once())->method('getRecordsCount')->willReturn(2); $this->destination->expects($this->once())->method('getRecordsCount')->willReturn(3); $this->logger->expects($this->once())->method('warning')->with('Mismatch of entities in the document: ' . $dstDocName); $this->assertFalse($this->volume->perform()); }
/** * @return void */ public function testPerform() { $fields = ['field1' => []]; $structure = $this->getMockBuilder('\\Migration\\ResourceModel\\Structure')->disableOriginalConstructor()->setMethods([])->getMock(); $structure->expects($this->any())->method('getFields')->will($this->returnValue($fields)); $document = $this->getMockBuilder('\\Migration\\ResourceModel\\Document')->disableOriginalConstructor()->getMock(); $document->expects($this->any())->method('getStructure')->will($this->returnValue($structure)); $this->map->expects($this->once())->method('getDocumentMap')->with('document1')->willReturn('document2'); $this->source->expects($this->once())->method('getRecordsCount')->willReturn(3); $this->source->expects($this->once())->method('getDocument')->with('document1')->willReturn($document); $this->destination->expects($this->once())->method('getDocument')->with('document2')->willReturn($document); $this->destination->expects($this->any())->method('getRecordsCount')->willReturnMap([['document2', true, [], 3]]); $this->assertTrue($this->volume->perform()); }
public function testDelta() { $sourceDocName = 'orders'; $sourceDeltaName = 'm2_cl_orders'; $this->source->expects($this->any())->method('getDocumentList')->willReturn([$sourceDocName, $sourceDeltaName]); $this->source->expects($this->atLeastOnce())->method('getDeltaLogName')->with('orders')->willReturn($sourceDeltaName); $this->source->expects($this->any())->method('getRecordsCount')->with($sourceDeltaName)->willReturn(1); /** @var \Migration\Resource\Document|\PHPUnit_Framework_MockObject_MockObject $source */ $document = $this->getMock('\\Migration\\Resource\\Document', [], [], '', false); $this->source->expects($this->any())->method('getDocument')->willReturn($document); $this->map->expects($this->any())->method('getDeltaDocuments')->willReturn([$sourceDocName => 'order_id']); $this->map->expects($this->any())->method('getDocumentMap')->with($sourceDocName, MapInterface::TYPE_SOURCE)->willReturn($sourceDocName); $this->logger->expects($this->any())->method('debug')->with($sourceDocName . ' has changes'); $this->assertTrue($this->delta->perform()); }
/** * @return void */ public function testDeleteBackups() { $this->readerGroups->expects($this->once())->method('getGroup')->with('documents')->willReturn(['some_document' => 0]); $this->map->expects($this->once())->method('getDocumentMap')->with('some_document', MapInterface::TYPE_SOURCE)->will($this->returnValue('some_dest_document')); $this->destination->expects($this->once())->method('deleteDocumentBackup')->with('some_dest_document'); $this->helper->deleteBackups(); }
/** * @return void */ public function testPerform() { $this->map->expects($this->any())->method('getDocumentMap')->willReturnMap([['source_document_1', MapInterface::TYPE_SOURCE, 'destination_document_1']]); $sourceTable = $this->getMockBuilder('Magento\\Framework\\DB\\Ddl\\Table')->disableOriginalConstructor()->setMethods(['getColumns'])->getMock(); $sourceTable->expects($this->any())->method('getColumns')->will($this->returnValue([['asdf']])); $sourceAdapter = $this->getMockBuilder('\\Migration\\ResourceModel\\Adapter\\Mysql')->disableOriginalConstructor()->setMethods(['getTableDdlCopy'])->getMock(); $sourceAdapter->expects($this->any())->method('getTableDdlCopy')->with('source_suffix_source_document_1', 'destination_suffix_destination_document_1')->will($this->returnValue($sourceTable)); $destinationTable = $this->getMockBuilder('Magento\\Framework\\DB\\Ddl\\Table')->disableOriginalConstructor()->setMethods(['setColumn'])->getMock(); $destinationTable->expects($this->any())->method('setColumn')->with(['asdf']); $destAdapter = $this->getMockBuilder('\\Migration\\ResourceModel\\Adapter\\Mysql')->disableOriginalConstructor()->setMethods(['createTableByDdl', 'getTableDdlCopy'])->getMock(); $destAdapter->expects($this->any())->method('getTableDdlCopy')->with('destination_suffix_destination_document_1', 'destination_suffix_destination_document_1')->will($this->returnValue($destinationTable)); $destAdapter->expects($this->any())->method('createTableByDdl')->with($destinationTable); $this->source->expects($this->once())->method('getAdapter')->will($this->returnValue($sourceAdapter)); $this->destination->expects($this->once())->method('getAdapter')->will($this->returnValue($destAdapter)); $recordsCollection = $this->getMockBuilder('Migration\\ResourceModel\\Record\\Collection')->disableOriginalConstructor()->setMethods(['addRecord'])->getMock(); $destDocument = $this->getMockBuilder('Migration\\ResourceModel\\Document')->disableOriginalConstructor()->setMethods(['getRecords', 'getName'])->getMock(); $destDocument->expects($this->any())->method('getName')->will($this->returnValue('some_name')); $destDocument->expects($this->any())->method('getRecords')->will($this->returnValue($recordsCollection)); $record = $this->getMockBuilder('Migration\\ResourceModel\\Record')->disableOriginalConstructor()->setMethods(['setData'])->getMock(); $record->expects($this->once())->method('setData')->with(['field_1' => 1, 'field_2' => 2]); $this->recordFactory->expects($this->any())->method('create')->with(['document' => $destDocument])->will($this->returnValue($record)); $recordsCollection->expects($this->any())->method('addRecord')->with($record); $this->destination->expects($this->any())->method('getDocument')->will($this->returnValue($destDocument)); $this->logger->expects($this->any())->method('debug')->with('migrating', ['table' => 'source_document_1'])->willReturn(true); $this->source->expects($this->any())->method('getRecords')->will($this->returnValueMap([['source_document_1', 0, null, [['field_1' => 1, 'field_2' => 2]]]])); $this->assertTrue($this->step->perform()); }
/** * @covers \Migration\Step\Log\Integrity::getIterationsCount * @return void */ public function testPerformMainFlow() { $fields = ['field1' => ['DATA_TYPE' => 'int']]; $structure = $this->getMockBuilder('\\Migration\\ResourceModel\\Structure')->disableOriginalConstructor()->setMethods([])->getMock(); $structure->expects($this->any())->method('getFields')->will($this->returnValue($fields)); $this->source->expects($this->atLeastOnce())->method('getDocumentList')->will($this->returnValue(['document1'])); $this->destination->expects($this->atLeastOnce())->method('getDocumentList')->will($this->returnValue(['document2', 'document_to_clear'])); $document = $this->getMockBuilder('\\Migration\\ResourceModel\\Document')->disableOriginalConstructor()->getMock(); $document->expects($this->any())->method('getStructure')->will($this->returnValue($structure)); $this->map->expects($this->any())->method('getDocumentMap')->willReturnMap([['document1', MapInterface::TYPE_SOURCE, 'document2'], ['document2', MapInterface::TYPE_DEST, 'document1']]); $this->source->expects($this->any())->method('getDocument')->will($this->returnValue($document)); $this->destination->expects($this->any())->method('getDocument')->will($this->returnValue($document)); $this->map->expects($this->any())->method('getFieldMap')->will($this->returnValue('field1')); $this->logger->expects($this->never())->method('error'); $this->assertTrue($this->log->perform()); }
/** * @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(); }
public function testPerformWithError() { $fields = ['field1' => ['DATA_TYPE' => 'int']]; $this->map->expects($this->atLeastOnce())->method('getDocumentMap')->willReturnMap([['source_document', MapInterface::TYPE_SOURCE, 'source_document'], ['common_document', MapInterface::TYPE_SOURCE, 'common_document'], ['source_document', MapInterface::TYPE_DEST, 'source_document'], ['common_document', MapInterface::TYPE_DEST, 'common_document']]); $structure = $this->getMockBuilder('\\Migration\\Resource\\Structure')->disableOriginalConstructor()->setMethods([])->getMock(); $structure->expects($this->any())->method('getFields')->will($this->returnValue($fields)); $document = $this->getMockBuilder('\\Migration\\Resource\\Document')->disableOriginalConstructor()->getMock(); $document->expects($this->any())->method('getStructure')->will($this->returnValue($structure)); $this->source->expects($this->atLeastOnce())->method('getDocumentList')->will($this->returnValue(['source_document', 'common_document'])); $this->source->expects($this->atLeastOnce())->method('getDocument')->willReturn($document); $this->destination->expects($this->atLeastOnce())->method('getDocumentList')->will($this->returnValue(['common_document'])); $this->destination->expects($this->atLeastOnce())->method('getDocument')->willReturn($document); $this->logger->expects($this->once())->method('error')->with('Source documents not mapped: source_document'); $this->readerGroups->expects($this->any())->method('getGroup')->with('documents')->willReturn(['source_document' => 0, 'common_document' => 1]); $this->assertFalse($this->integrity->perform()); }
/** * @param Record $recordToHandle * @param Record $oppositeRecord * @return mixed */ public function handle(Record $recordToHandle, Record $oppositeRecord) { $this->validate($recordToHandle); $sourcePatterns = []; $destinationPatters = []; foreach ($this->source->getDocumentList() as $document) { $destDocumentName = $this->map->getDocumentMap($document, MapInterface::TYPE_SOURCE); if ($destDocumentName === false) { continue; } $sourcePatterns[] = sprintf('`%s`', $this->source->addDocumentPrefix($document)); $destinationPatters[] = sprintf('`%s`', $this->destination->addDocumentPrefix($destDocumentName)); } $newValue = str_replace($sourcePatterns, $destinationPatters, $recordToHandle->getValue($this->field)); $recordToHandle->setValue($this->field, $newValue); }
public function testHandle() { /** @var Record|\PHPUnit_Framework_MockObject_MockObject $recordToHandle */ $recordToHandle = $this->getMockBuilder('Migration\\Resource\\Record')->setMethods(['getValue', 'setValue', 'getFields'])->disableOriginalConstructor()->getMock(); /** @var Record $oppositeRecord|\PHPUnit_Framework_MockObject_MockObject */ $oppositeRecord = $this->getMockBuilder('Migration\\Resource\\Record')->disableOriginalConstructor()->getMock(); $fieldName = 'fieldname'; $recordToHandle->expects($this->once())->method('getFields')->will($this->returnValue([$fieldName])); $recordToHandle->expects($this->once())->method('getValue')->with($fieldName)->will($this->returnValue('SELECT * FROM `source_some_document` LEFT JOIN `source_other_document`')); $recordToHandle->expects($this->once())->method('setValue')->with($fieldName, 'SELECT * FROM `pfx_dest_some_document` LEFT JOIN `pfx_dest_other_document`'); $this->map->expects($this->any())->method('getDocumentMap')->willReturnMap([['source_some_document', MapInterface::TYPE_SOURCE, 'dest_some_document'], ['source_other_document', MapInterface::TYPE_SOURCE, 'dest_other_document'], ['source_ignored_document', MapInterface::TYPE_SOURCE, false]]); $this->source->expects($this->once())->method('getDocumentList')->will($this->returnValue(['source_some_document', 'source_other_document', 'source_ignored_document'])); $this->source->expects($this->any())->method('addDocumentPrefix')->will($this->returnArgument(0)); $this->handler->setField($fieldName); $this->handler->handle($recordToHandle, $oppositeRecord); }
/** * @return bool */ public function perform() { $sourceDocuments = array_keys($this->helper->getDocumentList()); $this->progress->start(count($sourceDocuments)); foreach ($sourceDocuments as $sourceDocName) { $this->progress->advance(); $destinationName = $this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE); if (!$destinationName) { continue; } $this->checkMapEntities($sourceDocName, $destinationName); $this->checkEavEntities(); } $this->progress->finish(); return $this->checkForErrors(); }
public function testPerformJustCopy() { $sourceDocName = 'core_config_data'; $this->source->expects($this->any())->method('getDocumentList')->will($this->returnValue([$sourceDocName])); $this->source->expects($this->any())->method('getRecordsCount')->will($this->returnValue(2)); $dstDocName = 'config_data'; $this->progress->expects($this->once())->method('getProcessedEntities')->will($this->returnValue([])); $this->map->expects($this->once())->method('getDocumentMap')->will($this->returnValue($dstDocName)); $this->map->expects($this->any())->method('getHandlerConfig')->willReturn([]); $sourceDocument = $this->getMock('\\Migration\\Resource\\Document', ['getRecords', 'getStructure'], [], '', false); $bulk = [['id' => 4, 'name' => 'john']]; $this->source->expects($this->at(4))->method('getRecords')->will($this->returnValue($bulk)); $this->source->expects($this->at(5))->method('getRecords')->will($this->returnValue([])); $this->source->expects($this->once())->method('getDocument')->willReturn($sourceDocument); $destinationDocument = $this->getMockBuilder('\\Migration\\Resource\\Document')->disableOriginalConstructor()->setMethods(['getStructure', 'getRecords'])->getMock(); $this->destination->expects($this->once())->method('getDocument')->will($this->returnValue($destinationDocument)); $structure = $this->getMockBuilder('\\Migration\\Resource\\Structure')->disableOriginalConstructor()->setMethods(['getFields'])->getMock(); $structure->expects($this->any())->method('getFields')->willReturn(['field' => []]); $sourceDocument->expects($this->any())->method('getStructure')->willReturn($structure); $destinationDocument->expects($this->any())->method('getStructure')->willReturn($structure); $destinationRecords = $this->getMock('\\Migration\\Resource\\Record\\Collection', [], [], '', false); $destinationDocument->expects($this->once())->method('getRecords')->will($this->returnValue($destinationRecords)); $dstRecord = $this->getMock('\\Migration\\Resource\\Record', [], [], '', false); $this->recordFactory->expects($this->at(0))->method('create')->will($this->returnValue($dstRecord)); $this->destination->expects($this->once())->method('saveRecords')->with($dstDocName, $destinationRecords); $this->destination->expects($this->once())->method('clearDocument')->with($dstDocName); $this->data->perform(); }
/** * @param string $sourceDocName * @param array $keyFields * @return array */ public function getDestinationRecords($sourceDocName, $keyFields = []) { $destinationDocumentName = $this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE); $data = []; $count = $this->destination->getRecordsCount($destinationDocumentName); foreach ($this->destination->getRecords($destinationDocumentName, 0, $count) as $row) { if ($keyFields) { $key = []; foreach ($keyFields as $keyField) { $key[] = $row[$keyField]; } $data[implode('-', $key)] = $row; } else { $data[] = $row; } } return $data; }
public function testPerformCheckLogsClearFailed() { $dstDocName = 'config_data'; $this->map->expects($this->once())->method('getDocumentMap')->willReturn($dstDocName); $this->source->expects($this->once())->method('getRecordsCount')->willReturn(3); $this->destination->expects($this->any())->method('getRecordsCount')->willReturnMap([['config_data', true, 3], ['document_to_clear', true, 1]]); $this->logger->expects($this->once())->method('warning')->with('Log documents in the destination resource are not cleared'); $this->assertFalse($this->volume->perform()); }
/** * Rollback backed up documents * @return void */ public function rollback() { foreach (array_keys($this->readerGroups->getGroup('documents')) as $documentName) { $destinationDocument = $this->destination->getDocument($this->map->getDocumentMap($documentName, MapInterface::TYPE_SOURCE)); if ($destinationDocument !== false) { $this->destination->rollbackDocument($destinationDocument->getName()); } } }
/** * Delete backed up documents * @return void */ public function deleteBackups() { foreach (array_keys($this->readerGroups->getGroup('documents')) as $documentName) { $documentName = $this->map->getDocumentMap($documentName, MapInterface::TYPE_SOURCE); if ($documentName) { $this->destination->deleteDocumentBackup($documentName); } } }
/** * @return bool */ public function perform() { $sourceDocuments = array_keys($this->readerGroups->getGroup('source_documents')); $this->progress->start($this->getIterationsCount()); foreach ($sourceDocuments as $sourceDocName) { $this->progress->advance(); $destinationName = $this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE); if (!$destinationName) { continue; } $sourceCount = $this->helper->getSourceRecordsCount($sourceDocName); $destinationCount = $this->destination->getRecordsCount($destinationName); if ($sourceCount != $destinationCount) { $this->errors[] = 'Mismatch of entities in the document: ' . $destinationName; } } $this->progress->finish(); return $this->checkForErrors(); }
/** * Volume check * * @return bool */ public function perform() { $sourceDocuments = array_keys($this->groups->getGroup('source_documents')); $this->progress->start(count($sourceDocuments)); foreach ($sourceDocuments as $sourceName) { $this->progress->advance(); $destinationName = $this->map->getDocumentMap($sourceName, MapInterface::TYPE_SOURCE); $sourceFields = $this->source->getDocument($sourceName)->getStructure()->getFields(); $destinationFields = $this->destination->getDocument($destinationName)->getStructure()->getFields(); if (!empty(array_diff_key($sourceFields, $destinationFields))) { $this->errors[] = 'Mismatch of fields in the document: ' . $destinationName; } if ($this->source->getRecordsCount($sourceName) != $this->destination->getRecordsCount($destinationName)) { $this->errors[] = 'Mismatch of entities in the document: ' . $destinationName; } } $this->progress->finish(); return $this->checkForErrors(); }
/** * @return bool */ public function perform() { $sourceDocuments = $this->source->getDocumentList(); $this->progressBar->start(count($sourceDocuments)); foreach ($sourceDocuments as $sourceDocName) { $this->progressBar->advance(); $destinationName = $this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE); if (!$destinationName) { continue; } $sourceCount = $this->source->getRecordsCount($sourceDocName); $destinationCount = $this->destination->getRecordsCount($destinationName); if ($sourceCount != $destinationCount) { $this->errors[] = 'Mismatch of entities in the document: ' . $destinationName; } } $this->progressBar->finish(); return $this->checkForErrors(); }
/** * @return void */ public function testPerformFailed() { $sourceDocName = 'core_config_data'; $dstDocName = 'config_data'; $this->source->expects($this->once())->method('getDocumentList')->willReturn([$sourceDocName]); $this->map->expects($this->once())->method('getDocumentMap')->willReturn($dstDocName); $this->source->expects($this->once())->method('getRecordsCount')->willReturn(2); $this->destination->expects($this->once())->method('getRecordsCount')->willReturn(3); $this->logger->expects($this->once())->method('addRecord')->with(Logger::WARNING, 'Mismatch of entities in the document: ' . $dstDocName); $this->helper->expects($this->once())->method('getFieldsUpdateOnDuplicate')->with($dstDocName)->willReturn(false); $this->assertFalse($this->volume->perform()); }
/** * @param Document $document * @param string $type * @return bool */ protected function hasHandlers(Document $document, $type) { $result = false; foreach (array_keys($document->getStructure()->getFields()) as $fieldName) { $handlerConfig = $this->map->getHandlerConfig($document->getName(), $fieldName, $type); if (!empty($handlerConfig)) { $result = true; break; } } return $result; }
public function testPerformWithMismatchDocumentFieldDataTypes() { $this->setupFieldsValidation(true); $this->documentSource->expects($this->any())->method('getName')->will($this->returnValue('document1')); $this->documentDestination->expects($this->any())->method('getName')->will($this->returnValue('document1')); $this->source->expects($this->atLeastOnce())->method('getDocumentList')->will($this->returnValue(['document1'])); $this->destination->expects($this->atLeastOnce())->method('getDocumentList')->will($this->returnValue(['document1'])); $this->map->expects($this->any())->method('getDocumentMap')->will($this->returnArgument(0)); $this->map->expects($this->any())->method('isDocumentIgnored')->willReturn(false); $this->map->expects($this->any())->method('getFieldMap')->will($this->returnValue('field1')); $this->map->expects($this->any())->method('isFieldDataTypeIgnored')->will($this->returnValue(false)); $this->logger->expects($this->at(0))->method('warning')->with('Mismatch of data types. Source document: document1. Fields: field1'); $this->logger->expects($this->at(1))->method('warning')->with('Mismatch of data types. Destination document: document1. Fields: field1'); $this->integrity->perform(); }
/** * @return bool */ public function perform() { $this->progress->start($this->getIterationsCount(), LogManager::LOG_LEVEL_INFO); $sourceDocuments = array_keys($this->readerGroups->getGroup('source_documents')); foreach ($sourceDocuments as $sourceDocName) { $sourceDocument = $this->source->getDocument($sourceDocName); $destinationName = $this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE); if (!$destinationName) { continue; } $destDocument = $this->destination->getDocument($destinationName); $this->destination->clearDocument($destinationName); /** @var \Migration\RecordTransformer $recordTransformer */ $recordTransformer = $this->recordTransformerFactory->create(['sourceDocument' => $sourceDocument, 'destDocument' => $destDocument, 'mapReader' => $this->map]); $recordTransformer->init(); $attributeType = $this->helper->getAttributeType($sourceDocName); $pageNumber = 0; $this->logger->debug('migrating', ['table' => $sourceDocName]); $this->progress->start(ceil($this->source->getRecordsCount($sourceDocName) / $this->source->getPageSize($sourceDocName)), LogManager::LOG_LEVEL_DEBUG); while (!empty($bulk = $this->source->getRecords($sourceDocName, $pageNumber))) { $pageNumber++; $destinationRecords = $destDocument->getRecords(); foreach ($bulk as $recordData) { $this->source->setLastLoadedRecord($sourceDocName, $recordData); if ($this->helper->isSkipRecord($attributeType, $sourceDocName, $recordData)) { continue; } /** @var Record $record */ $record = $this->recordFactory->create(['document' => $sourceDocument, 'data' => $recordData]); /** @var Record $destRecord */ $destRecord = $this->recordFactory->create(['document' => $destDocument]); $recordTransformer->transform($record, $destRecord); $destinationRecords->addRecord($destRecord); } $this->progress->advance(LogManager::LOG_LEVEL_INFO); $this->progress->advance(LogManager::LOG_LEVEL_DEBUG); $this->helper->updateAttributeData($attributeType, $sourceDocName, $destinationRecords); $this->destination->saveRecords($destinationName, $destinationRecords); } $this->progress->finish(LogManager::LOG_LEVEL_DEBUG); } $this->helper->updateEavAttributes(); $this->progress->finish(LogManager::LOG_LEVEL_INFO); return true; }
/** * Entry point. Run migration of SalesOrder structure. * @return bool */ public function perform() { $this->progress->start($this->getIterationsCount(), LogManager::LOG_LEVEL_INFO); $sourceDocuments = array_keys($this->helper->getDocumentList()); foreach ($sourceDocuments as $sourceDocName) { $sourceDocument = $this->source->getDocument($sourceDocName); $destinationDocumentName = $this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE); if (!$destinationDocumentName) { continue; } $destDocument = $this->destination->getDocument($destinationDocumentName); $this->destination->clearDocument($destinationDocumentName); $eavDocumentName = $this->helper->getDestEavDocument(); $eavDocumentResource = $this->destination->getDocument($eavDocumentName); /** @var \Migration\RecordTransformer $recordTransformer */ $recordTransformer = $this->recordTransformerFactory->create(['sourceDocument' => $sourceDocument, 'destDocument' => $destDocument, 'mapReader' => $this->map]); $recordTransformer->init(); $pageNumber = 0; $this->logger->debug('migrating', ['table' => $sourceDocName]); $this->progress->start($this->source->getRecordsCount($sourceDocName), LogManager::LOG_LEVEL_DEBUG); while (!empty($bulk = $this->source->getRecords($sourceDocName, $pageNumber))) { $pageNumber++; $destinationCollection = $destDocument->getRecords(); $destEavCollection = $eavDocumentResource->getRecords(); foreach ($bulk as $recordData) { $this->progress->advance(LogManager::LOG_LEVEL_INFO); $this->progress->advance(LogManager::LOG_LEVEL_DEBUG); /** @var Record $sourceRecord */ $sourceRecord = $this->recordFactory->create(['document' => $sourceDocument, 'data' => $recordData]); /** @var Record $destRecord */ $destRecord = $this->recordFactory->create(['document' => $destDocument]); $recordTransformer->transform($sourceRecord, $destRecord); $destinationCollection->addRecord($destRecord); $this->migrateAdditionalOrderData($recordData, $sourceDocument, $destEavCollection); } $this->destination->saveRecords($destinationDocumentName, $destinationCollection); $this->destination->saveRecords($eavDocumentName, $destEavCollection); $this->progress->finish(LogManager::LOG_LEVEL_DEBUG); } } $this->progress->finish(LogManager::LOG_LEVEL_INFO); return true; }
/** * @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()); }
/** * @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(); }
/** * @return void */ public function testPerform() { $sourceDocName = 'core_config_data'; $this->source->expects($this->any())->method('getDocumentList')->will($this->returnValue([$sourceDocName])); $dstDocName = 'config_data'; $this->map->expects($this->once())->method('getDocumentMap')->will($this->returnValue($dstDocName)); $sourceDocument = $this->getMock('\\Migration\\ResourceModel\\Document', ['getRecords'], [], '', false); $this->source->expects($this->once())->method('getDocument')->will($this->returnValue($sourceDocument)); $destinationDocument = $this->getMock('\\Migration\\ResourceModel\\Document', [], [], '', false); $this->destination->expects($this->once())->method('getDocument')->will($this->returnValue($destinationDocument)); $this->sourceAdapter->expects($this->at(1))->method('loadDataFromSelect')->willReturn([['visitor_id' => 1, 'session_id' => 'dvak7ir3t9p3sicksr0t9thqc7', 'first_visit_at' => '2015-10-25 11:22:40', 'last_visit_at' => '2015-10-25 11:22:40', 'last_url_id' => 1, 'store_id' => 1]]); $this->sourceAdapter->expects($this->at(2))->method('loadDataFromSelect')->willReturn([]); $destinationRecords = $this->getMock('\\Migration\\ResourceModel\\Record\\Collection', [], [], '', false); $destinationDocument->expects($this->once())->method('getRecords')->will($this->returnValue($destinationRecords)); $srcRecord = $this->getMock('\\Migration\\ResourceModel\\Record', [], [], '', false); $this->recordFactory->expects($this->at(0))->method('create')->will($this->returnValue($srcRecord)); $this->destination->expects($this->once())->method('saveRecords')->with($dstDocName, $destinationRecords); $this->destination->expects($this->exactly(2))->method('clearDocument'); $this->logger->expects($this->any())->method('debug')->with('migrating', ['table' => 'source_document'])->willReturn(true); $this->data->perform(); }
public function testPerformWithSourceFieldErrors() { $structure = $this->getMockBuilder('\\Migration\\Resource\\Structure')->disableOriginalConstructor()->setMethods([])->getMock(); $structure->expects($this->at(0))->method('getFields')->will($this->returnValue(['field1' => []])); $structure->expects($this->at(1))->method('getFields')->will($this->returnValue(['field2' => []])); $structure->expects($this->at(2))->method('getFields')->will($this->returnValue(['field2' => []])); $structure->expects($this->at(3))->method('getFields')->will($this->returnValue(['field1' => []])); $document = $this->getMockBuilder('\\Migration\\Resource\\Document')->disableOriginalConstructor()->getMock(); $document->expects($this->any())->method('getStructure')->willReturn($structure); $document->expects($this->any())->method('getName')->willReturn('document'); $this->source->expects($this->atLeastOnce())->method('getDocumentList')->will($this->returnValue(['document'])); $this->destination->expects($this->atLeastOnce())->method('getDocumentList')->will($this->returnValue(['document'])); $this->source->expects($this->any())->method('getDocument')->will($this->returnValue($document)); $this->destination->expects($this->any())->method('getDocument')->with('document')->will($this->returnValue($document)); $this->map->expects($this->any())->method('isDocumentIgnored')->willReturn(false); $this->map->expects($this->exactly(2))->method('getDocumentMap')->with('document')->will($this->returnArgument(0)); $this->map->expects($this->at(2))->method('getFieldMap')->with('document', 'field1')->will($this->returnValue('field1')); $this->map->expects($this->at(5))->method('getFieldMap')->with('document', 'field2')->will($this->returnValue('field2')); $this->logger->expects($this->at(0))->method('error')->with('Source fields not mapped. Document: document. Fields: field1'); $this->logger->expects($this->at(1))->method('error')->with('Destination fields not mapped. Document: document. Fields: field2'); $this->integrity->perform(); }