/** * @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(); }
/** * @return void */ public function testPerform() { $recordsData = ['record_1' => ['field_name' => []], 'record_2' => ['field_name' => []], 'record_3' => ['field_name' => []]]; $this->progress->expects($this->once())->method('start')->with('3'); $this->progress->expects($this->any())->method('advance'); $this->progress->expects($this->once())->method('finish'); $fields = ['field_name' => []]; $differentFields = ['field_different' => []]; $structure = $this->getMockBuilder('Migration\\ResourceModel\\Structure')->disableOriginalConstructor()->setMethods(['getFields'])->getMock(); $structure->expects($this->at(0))->method('getFields')->willReturn($differentFields); $structure->expects($this->any())->method('getFields')->willReturn($fields); $document = $this->getMockBuilder('Migration\\ResourceModel\\Document')->disableOriginalConstructor()->setMethods(['getName', 'getRecords', 'getStructure'])->getMock(); $document->expects($this->any())->method('getStructure')->willReturn($structure); $recordsCollection = $this->getMockBuilder('Migration\\ResourceModel\\Record\\Collection')->disableOriginalConstructor()->setMethods(['addRecord'])->getMock(); $document->expects($this->any())->method('getRecords')->willReturn($recordsCollection); $record = $this->getMockBuilder('Migration\\ResourceModel\\Record')->disableOriginalConstructor()->setMethods(['getFields', 'setValue'])->getMock(); $record->expects($this->once())->method('getFields')->willReturn(array_keys($fields)); $record->expects($this->once())->method('setValue')->willReturnSelf(); $this->recordFactory->expects($this->any())->method('create')->with(['document' => $document])->will($this->returnValue($record)); $recordsCollection->expects($this->any())->method('addRecord')->with($record); $this->source->expects($this->any())->method('getDocument')->willReturn($document); $this->source->expects($this->any())->method('getRecords')->willReturnMap([['core_store', 0, null, $recordsData], ['core_store_group', 0, null, $recordsData], ['core_website', 0, null, $recordsData]]); $this->destination->expects($this->any())->method('getDocument')->willReturn($document); $this->destination->expects($this->any())->method('clearDocument')->willReturnSelf(); $this->helper->expects($this->any())->method('getDocumentList')->willReturn(['core_store' => 'store', 'core_store_group' => 'store_group', 'core_website' => 'store_website']); $this->data = new Data($this->progress, $this->source, $this->destination, $this->recordFactory, $this->helper); $this->data->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); }
/** * @return void */ public function testPerform() { $document = $this->getMockBuilder('Migration\\ResourceModel\\Document')->disableOriginalConstructor()->getMock(); $this->progress->expects($this->once())->method('start')->with('3'); $this->progress->expects($this->any())->method('advance'); $this->progress->expects($this->once())->method('finish'); $this->source->expects($this->any())->method('getDocument', 'getRecords')->willReturn($document); $this->destination->expects($this->any())->method('getDocument')->willReturn($document); $this->helper->expects($this->any())->method('getDocumentList')->willReturn(['core_store' => 'store', 'core_store_group' => 'store_group', 'core_website' => 'store_website']); $this->integrity = new Integrity($this->progress, $this->source, $this->destination, $this->helper); $this->assertTrue($this->integrity->perform()); }
/** * @return void */ public function testPerform() { $this->data = new Data($this->destination, $this->progress); $this->progress->expects($this->once())->method('start')->with(1); $this->progress->expects($this->once())->method('advance'); $this->progress->expects($this->once())->method('finish'); $this->destination->expects($this->once())->method('getAdapter')->willReturn($this->adapter); $this->adapter->expects($this->once())->method('getSelect')->willReturn($this->select); $this->select->expects($this->once())->method('from')->with('rating_store', ['rating_id'])->will($this->returnSelf()); $this->select->expects($this->once())->method('where')->with('store_id > 0')->will($this->returnSelf()); $this->adapter->expects($this->once())->method('loadDataFromSelect')->with($this->select)->willReturn([['rating_id' => 1]]); $this->adapter->expects($this->once())->method('updateDocument')->with('rating', ['is_active' => 1], 'rating_id IN (1)'); $this->data->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()); }
/** * @return void */ 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\\ResourceModel\\Document', ['getRecords', 'getStructure'], [], '', false); $bulk = [['id' => 4, 'name' => 'john']]; $this->source->expects($this->any())->method('getRecords')->willReturnOnConsecutiveCalls($bulk, []); $this->source->expects($this->once())->method('getDocument')->willReturn($sourceDocument); $this->source->expects($this->any())->method('getPageSize')->willReturn(100); $this->source->expects($this->any())->method('setLastLoadedRecord')->withConsecutive([$sourceDocName, $bulk[0]], [$sourceDocName, []]); $destinationDocument = $this->getMockBuilder('\\Migration\\ResourceModel\\Document')->disableOriginalConstructor()->setMethods(['getStructure', 'getRecords'])->getMock(); $this->destination->expects($this->once())->method('getDocument')->will($this->returnValue($destinationDocument)); $structure = $this->getMockBuilder('\\Migration\\ResourceModel\\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\\ResourceModel\\Record\\Collection', [], [], '', false); $destinationDocument->expects($this->once())->method('getRecords')->will($this->returnValue($destinationRecords)); $dstRecord = $this->getMock('\\Migration\\ResourceModel\\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(); }
/** * @throws \Migration\Exception * @return void */ public function testData() { $countCmsPageRewrites = 1; $recordsAmount = 123; $progressRecordsAmount = $recordsAmount + $countCmsPageRewrites; $this->source->expects($this->once())->method('getRecordsCount')->willReturn($recordsAmount); $this->progress->expects($this->at(0))->method('start')->with($this->equalTo($progressRecordsAmount)); $sourceDocument = $this->getMockBuilder('\\Migration\\ResourceModel\\Document')->disableOriginalConstructor()->getMock(); $this->source->expects($this->once())->method('getDocument')->with($this->equalTo(\Migration\Step\UrlRewrite\Version191to2000::SOURCE))->willReturn($sourceDocument); $destinationDocument = $this->getMockBuilder('\\Migration\\ResourceModel\\Document')->disableOriginalConstructor()->getMock(); $this->destination->expects($this->at(0))->method('getDocument')->with($this->equalTo(\Migration\Step\UrlRewrite\Version191to2000::DESTINATION))->willReturn($destinationDocument); $destinationProductCategory = $this->getMockBuilder('\\Migration\\ResourceModel\\Document')->setMethods(['setValue', 'getRecords'])->disableOriginalConstructor()->getMock(); $this->destination->expects($this->at(1))->method('getDocument')->with($this->equalTo(\Migration\Step\UrlRewrite\Version191to2000::DESTINATION_PRODUCT_CATEGORY))->willReturn($destinationProductCategory); $this->destination->expects($this->exactly(2))->method('clearDocument')->withConsecutive([\Migration\Step\UrlRewrite\Version191to2000::DESTINATION], [\Migration\Step\UrlRewrite\Version191to2000::DESTINATION_PRODUCT_CATEGORY]); $this->source->expects($this->at(2))->method('getRecords')->with($this->equalTo(\Migration\Step\UrlRewrite\Version191to2000::SOURCE), $this->equalTo(0))->willReturn(['RecordData1']); $sourceRecord = $this->getMockBuilder('\\Migration\\ResourceModel\\Record')->disableOriginalConstructor()->getMock(); $this->recordFactory->expects($this->at(0))->method('create')->with($this->equalTo(['document' => $sourceDocument, 'data' => 'RecordData1']))->willReturn($sourceRecord); $destinationRecord = $this->getMockBuilder('\\Migration\\ResourceModel\\Record')->disableOriginalConstructor()->getMock(); $this->recordFactory->expects($this->at(1))->method('create')->with($this->equalTo(['document' => $destinationDocument]))->willReturn($destinationRecord); $destinationCategoryRecord = $this->getMockBuilder('\\Migration\\ResourceModel\\Record')->disableOriginalConstructor()->getMock(); $this->recordFactory->expects($this->at(2))->method('create')->with($this->equalTo(['document' => $destinationProductCategory]))->willReturn($destinationCategoryRecord); $this->mockSourceRecordGetters($sourceRecord); $this->mockDestinationRecordSetters($destinationRecord); $this->mockDestinationCategorySetters($destinationCategoryRecord); $destinationProductCategory->expects($this->once())->method('getRecords')->willReturn($this->recordCollection); $destinationDocument->expects($this->once())->method('getRecords')->willReturn($this->recordCollection); $version = new \Migration\Step\UrlRewrite\Version191to2000($this->config, $this->source, $this->destination, $this->progress, $this->recordFactory, $this->logger, 'data'); $this->assertTrue($version->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()); }
/** * @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()); }
/** * @return void */ public function testPerformFailed() { $this->volume = new Volume($this->destination, $this->logger, $this->progress); $this->progress->expects($this->once())->method('start')->with(1); $this->progress->expects($this->once())->method('advance'); $this->progress->expects($this->once())->method('finish'); $this->destination->expects($this->once())->method('getAdapter')->willReturn($this->adapter); $this->adapter->expects($this->exactly(2))->method('getSelect')->willReturn($this->select); $this->select->expects($this->at(0))->method('from')->with('rating_store', ['rating_id'])->will($this->returnSelf()); $this->select->expects($this->at(1))->method('where')->with('store_id > 0')->will($this->returnSelf()); $this->adapter->expects($this->at(1))->method('loadDataFromSelect')->with($this->select)->willReturn([['rating_id' => 1]]); $this->adapter->expects($this->at(3))->method('loadDataFromSelect')->with($this->select)->willReturn([['rating_id' => 2]]); $this->select->expects($this->at(2))->method('from')->with('rating', ['rating_id'])->will($this->returnSelf()); $this->select->expects($this->at(3))->method('where')->with('is_active = ?', 1)->will($this->returnSelf()); $this->logger->expects($this->once())->method('addRecord')->with(Logger::ERROR, 'Mismatch of entities in the documents: rating, rating_store'); $this->assertFalse($this->volume->perform()); }
/** * @return void */ public function testHandle() { $fieldNameRuleId = 'rule_id'; $fieldNameForNormalization = 'website_ids'; $idsForNormalization = '1,2,3'; $normalizedData = [[$fieldNameRuleId => 1, $this->normalizationField => 1], [$fieldNameRuleId => 1, $this->normalizationField => 2], [$fieldNameRuleId => 1, $this->normalizationField => 3]]; /** @var Record|\PHPUnit_Framework_MockObject_MockObject $recordToHandle */ $recordToHandle = $this->getMockBuilder('Migration\\ResourceModel\\Record')->setMethods(['getValue', 'getFields'])->disableOriginalConstructor()->getMock(); /** @var Record $oppositeRecord|\PHPUnit_Framework_MockObject_MockObject */ $oppositeRecord = $this->getMockBuilder('Migration\\ResourceModel\\Record')->disableOriginalConstructor()->getMock(); $recordToHandle->expects($this->once())->method('getFields')->willReturn([$fieldNameRuleId, $fieldNameForNormalization]); $recordToHandle->expects($this->any())->method('getValue')->willReturnMap([[$fieldNameRuleId, 1], [$fieldNameForNormalization, $idsForNormalization]]); $this->destination->expects($this->once())->method('clearDocument')->with($this->normalizationDocument)->willReturnSelf(); $this->destination->expects($this->once())->method('saveRecords')->with($this->normalizationDocument, $normalizedData)->willReturnSelf(); $this->handler->setField($fieldNameForNormalization); $this->handler->handle($recordToHandle, $oppositeRecord); }
/** * @return void */ 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')); }
/** * @return void */ 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('addRecord')->with(Logger::WARNING, 'Log documents in the destination resource are not cleared'); $this->assertFalse($this->volume->perform()); }
/** * @return void */ public function testPerform() { $fields = ['field_name' => []]; $structure = $this->getMockBuilder('Migration\\ResourceModel\\Structure')->disableOriginalConstructor()->setMethods(['getFields'])->getMock(); $structure->expects($this->any())->method('getFields')->will($this->returnValue($fields)); $document = $this->getMockBuilder('Migration\\ResourceModel\\Document')->disableOriginalConstructor()->setMethods(['getStructure'])->getMock(); $this->progress->expects($this->once())->method('start')->with('3'); $this->progress->expects($this->any())->method('advance'); $this->progress->expects($this->once())->method('finish'); $document->expects($this->any())->method('getStructure')->willReturn($structure); $this->source->expects($this->any())->method('getDocument')->willReturn($document); $this->destination->expects($this->any())->method('getDocument')->willReturn($document); $this->source->expects($this->any())->method('getRecordsCount')->with()->willReturn(1); $this->destination->expects($this->any())->method('getRecordsCount')->with()->willReturn(1); $this->helper->expects($this->any())->method('getDocumentList')->willReturn(['core_store' => 'store', 'core_store_group' => 'store_group', 'core_website' => 'store_website']); $this->volume = new Volume($this->progress, $this->source, $this->destination, $this->helper, $this->logger); $this->assertTrue($this->volume->perform()); }
/** * @throws \Migration\Exception * @return void */ 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); $adapter = $this->getMock('\\Migration\\ResourceModel\\Adapter\\Mysql', ['setForeignKeyChecks'], [], '', false); $adapter->expects($this->at(0))->method('setForeignKeyChecks')->with(1); $adapter->expects($this->at(1))->method('setForeignKeyChecks')->with(0); $this->destination->expects($this->any())->method('getAdapter')->willReturn($adapter); /** @var \Migration\ResourceModel\Document|\PHPUnit_Framework_MockObject_MockObject $source */ $document = $this->getMock('\\Migration\\ResourceModel\\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 testPerformDestinationFail() { $this->progress->expects($this->once())->method('start')->with(1); $this->progress->expects($this->once())->method('advance'); $this->progress->expects($this->never())->method('finish'); $this->source->expects($this->once())->method('getDocumentList')->willReturn(['core_config_data']); $this->destination->expects($this->once())->method('getDocumentList')->willReturn([]); $this->logger->expects($this->once())->method('error')->with('Integrity check failed due to "core_config_data" document does not exist in the destination resource'); $this->integrity = new Integrity($this->destination, $this->source, $this->logger, $this->progress, $this->recordFactory, $this->readerSettings, $this->handlerManagerFactory); $this->assertFalse($this->integrity->perform()); }
/** * @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->assertFalse($this->volume->perform()); }
/** * @return void */ public function testPerform() { $count = 2; $sourceRecords = [['config_id' => 1, 'scope_id' => 0, 'scope' => 'default', 'path' => 'some/path1', 'value' => 'some value4'], ['config_id' => 2, 'scope_id' => 0, 'scope' => 'default', 'path' => 'some/path3', 'value' => 'some value3']]; $destinationRecords = [['config_id' => 1, 'scope_id' => 0, 'scope' => 'default', 'path' => 'some/path1', 'value' => 'some value1'], ['config_id' => 2, 'scope_id' => 0, 'scope' => 'default', 'path' => 'some/path2', 'value' => 'some value2']]; $destinationRecordsFinal = [['scope_id' => 0, 'scope' => 'default', 'path' => 'some/path1', 'value' => 'some value1'], ['scope_id' => 0, 'scope' => 'default', 'path' => 'some/path2', 'value' => 'some value2'], ['scope_id' => 0, 'scope' => 'default', 'path' => 'some/path3', 'value' => 'some value3']]; $pathMapped = [['some/path1', 'some/path1'], ['some/path3', 'some/path3']]; $handlerParams = [['some/path1', ['class' => 'Some\\Class', 'params' => []]], ['some/path3', []]]; $document = $this->getMock('Migration\\ResourceModel\\Document', [], [], '', false); $destinationRecord = $this->getMock('Migration\\ResourceModel\\Record', [], [], '', false); $sourceRecord = $this->getMock('Migration\\ResourceModel\\Record', ['getData', 'getValue', 'setValue'], [], '', false); $sourceRecord->expects($this->any())->method('getValue')->with('value')->willReturn($destinationRecords[0]['value']); $sourceRecord->expects($this->any())->method('setValue')->with('path', $pathMapped[1][0]); $sourceRecord->expects($this->any())->method('getData')->willReturn($sourceRecords[1]); $handler = $this->getMockBuilder('\\Migration\\Handler\\HandlerInterface')->getMock(); $handler->expects($this->any())->method('handle')->with($sourceRecord, $destinationRecord); $handlerManager = $this->getMock('Migration\\Handler\\Manager', ['initHandler', 'getHandler'], [], '', false); $handlerManager->expects($this->once())->method('initHandler')->with('value', $handlerParams[0][1], 'some/path1'); $handlerManager->expects($this->once())->method('getHandler')->willReturn($handler); $this->progress->expects($this->once())->method('start')->with($count); $this->progress->expects($this->exactly($count))->method('advance'); $this->progress->expects($this->once())->method('finish'); $this->source->expects($this->once())->method('getRecordsCount')->with('core_config_data')->willReturn($count); $this->source->expects($this->once())->method('getRecords')->with('core_config_data', 0, $count)->willReturn($sourceRecords); $this->destination->expects($this->once())->method('getRecordsCount')->with('core_config_data')->willReturn($count); $this->destination->expects($this->once())->method('getDocument')->with('core_config_data')->willReturn($document); $this->destination->expects($this->once())->method('clearDocument')->with('core_config_data'); $this->destination->expects($this->once())->method('saveRecords')->with('core_config_data', $destinationRecordsFinal); $this->destination->expects($this->once())->method('getRecords')->with('core_config_data', 0, $count)->willReturn($destinationRecords); $this->readerSettings->expects($this->any())->method('isNodeIgnored')->willReturn(false); $this->readerSettings->expects($this->any())->method('getNodeMap')->willReturnMap($pathMapped); $this->readerSettings->expects($this->any())->method('getValueHandler')->willReturnMap($handlerParams); $this->recordFactory->expects($this->at(0))->method('create')->with(['document' => $document, 'data' => $sourceRecords[0]])->willReturn($sourceRecord); $this->recordFactory->expects($this->at(1))->method('create')->with(['document' => $document, 'data' => $destinationRecords[0]])->willReturn($destinationRecord); $this->recordFactory->expects($this->at(2))->method('create')->with(['document' => $document, 'data' => $sourceRecords[1]])->willReturn($sourceRecord); $this->recordFactory->expects($this->at(3))->method('create')->with(['document' => $document, 'data' => []])->willReturn($destinationRecord); $this->handlerManagerFactory->expects($this->once())->method('create')->willReturn($handlerManager); $this->data = new Data($this->destination, $this->source, $this->logger, $this->progress, $this->recordFactory, $this->readerSettings, $this->handlerManagerFactory); $this->assertTrue($this->data->perform()); }
/** * @return void */ public function testPerformFieldFail() { $this->integrity = new Integrity($this->destination, $this->logger, $this->progress); $this->progress->expects($this->once())->method('start')->with(1); $this->progress->expects($this->once())->method('advance'); $this->progress->expects($this->never())->method('finish'); $this->destination->expects($this->once())->method('getDocumentList')->willReturn(['rating', 'rating_store']); $this->structure->expects($this->once())->method('getFields')->willReturn(['field' => []]); $this->document->expects($this->once())->method('getStructure')->willReturn($this->structure); $this->destination->expects($this->once())->method('getDocument')->with('rating')->willReturn($this->document); $this->logger->expects($this->once())->method('error')->with('"is_active" field does not exist in "rating" document of the destination resource'); $this->assertFalse($this->integrity->perform()); }
/** * @param array $attributeData * @param array $expected * * @dataProvider dataProviderUpdateAttributeData * @return void */ public function testUpdateAttributeData($attributeData, $expected) { $this->getAttributeType(); $this->readerAttributes->expects($this->any())->method('getGroup')->with(self::DOCUMENT)->willReturn($this->attribute); $this->adapter->expects($this->at(2))->method('fetchAll')->with($this->select)->willReturn($attributeData); $structure = $this->getMockBuilder('Migration\\ResourceModel\\Structure')->disableOriginalConstructor()->getMock(); $record = $this->getMockBuilder('Migration\\ResourceModel\\Record')->disableOriginalConstructor()->getMock(); $this->configReader->expects($this->any())->method('getOption')->willReturn(current($attributeData)[Helper::UPGRADE_CUSTOMER_PASSWORD_HASH]); $record->expects($this->any())->method('getValue')->with('entity_id')->willReturn('1'); $record->expects($this->any())->method('getData')->willReturn([]); $record->expects($this->any())->method('setData')->with($expected); $destinationRecords = new \Migration\ResourceModel\Record\Collection($structure, [$record]); $this->helper->updateAttributeData(self::ENTITY, self::DOCUMENT, $destinationRecords); }
/** * @return void */ 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\\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->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 are missing or 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 bool|false $dataTypeMismatch * @return void */ protected function setupFieldsValidation($dataTypeMismatch = false) { $dataTypeSource = $dataTypeMismatch ? 'varchar' : 'int'; $fieldsSource = ['field1' => ['DATA_TYPE' => $dataTypeSource]]; $structureSource = $this->getMockBuilder('\\Migration\\ResourceModel\\Structure')->disableOriginalConstructor()->setMethods([])->getMock(); $structureSource->expects($this->any())->method('getFields')->will($this->returnValue($fieldsSource)); $this->documentSource = $this->getMockBuilder('\\Migration\\ResourceModel\\Document')->disableOriginalConstructor()->getMock(); $this->documentSource->expects($this->any())->method('getStructure')->will($this->returnValue($structureSource)); $dataTypeDestination = 'int'; $fieldsDestination = ['field1' => ['DATA_TYPE' => $dataTypeDestination]]; $structureDestination = $this->getMockBuilder('\\Migration\\ResourceModel\\Structure')->disableOriginalConstructor()->setMethods([])->getMock(); $structureDestination->expects($this->any())->method('getFields')->will($this->returnValue($fieldsDestination)); $this->documentDestination = $this->getMockBuilder('\\Migration\\ResourceModel\\Document')->disableOriginalConstructor()->getMock(); $this->documentDestination->expects($this->any())->method('getStructure')->will($this->returnValue($structureDestination)); $this->source->expects($this->any())->method('getDocument')->will($this->returnValue($this->documentSource)); $this->destination->expects($this->any())->method('getDocument')->will($this->returnValue($this->documentDestination)); }
/** * @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(); }