Ejemplo n.º 1
0
 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();
 }
Ejemplo n.º 2
0
 public function testData()
 {
     $this->source->expects($this->once())->method('getRecordsCount')->willReturn(123);
     $this->progress->expects($this->at(0))->method('start')->with($this->equalTo(123));
     $sourceDocument = $this->getMockBuilder('\\Migration\\Resource\\Document')->disableOriginalConstructor()->getMock();
     $this->source->expects($this->once())->method('getDocument')->with($this->equalTo(\Migration\Step\UrlRewrite\Version191to2000::SOURCE))->willReturn($sourceDocument);
     $destinationDocument = $this->getMockBuilder('\\Migration\\Resource\\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\\Resource\\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\\Resource\\Record')->disableOriginalConstructor()->getMock();
     $this->recordFactory->expects($this->at(0))->method('create')->with($this->equalTo(['document' => $sourceDocument, 'data' => 'RecordData1']))->willReturn($sourceRecord);
     $destinationRecord = $this->getMockBuilder('\\Migration\\Resource\\Record')->disableOriginalConstructor()->getMock();
     $this->recordFactory->expects($this->at(1))->method('create')->with($this->equalTo(['document' => $destinationDocument]))->willReturn($destinationRecord);
     $destinationCategoryRecord = $this->getMockBuilder('\\Migration\\Resource\\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());
 }
Ejemplo n.º 3
0
 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());
 }
Ejemplo n.º 4
0
 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();
 }
 /**
  * @covers \Migration\Step\Log\Integrity::getIterationsCount
  */
 public function testPerformMainFlow()
 {
     $fields = ['field1' => []];
     $structure = $this->getMockBuilder('\\Migration\\Resource\\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\\Resource\\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());
 }
Ejemplo n.º 6
0
 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\\Resource\\Record')->setMethods(['getValue', 'getFields'])->disableOriginalConstructor()->getMock();
     /** @var Record $oppositeRecord|\PHPUnit_Framework_MockObject_MockObject */
     $oppositeRecord = $this->getMockBuilder('Migration\\Resource\\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);
 }
Ejemplo n.º 7
0
 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'));
 }
Ejemplo n.º 8
0
 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());
 }
 protected function setupFieldsValidation()
 {
     $fields = ['field1' => []];
     $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->any())->method('getDocument')->will($this->returnValue($document));
     $this->destination->expects($this->any())->method('getDocument')->will($this->returnValue($document));
 }
Ejemplo n.º 10
0
 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());
 }
Ejemplo n.º 11
0
 public function testVolumeCheckFailed()
 {
     $this->ratings = new Ratings($this->destination, $this->logger, $this->progress, 'volume');
     $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('warning')->with('Mismatch of entities in the documents: rating, rating_store');
     $this->assertFalse($this->ratings->perform());
 }
Ejemplo n.º 12
0
 /**
  * @param bool|false $dataTypeMismatch
  */
 protected function setupFieldsValidation($dataTypeMismatch = false)
 {
     $dataTypeSource = $dataTypeMismatch ? 'varchar' : 'int';
     $fieldsSource = ['field1' => ['DATA_TYPE' => $dataTypeSource]];
     $structureSource = $this->getMockBuilder('\\Migration\\Resource\\Structure')->disableOriginalConstructor()->setMethods([])->getMock();
     $structureSource->expects($this->any())->method('getFields')->will($this->returnValue($fieldsSource));
     $this->documentSource = $this->getMockBuilder('\\Migration\\Resource\\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\\Resource\\Structure')->disableOriginalConstructor()->setMethods([])->getMock();
     $structureDestination->expects($this->any())->method('getFields')->will($this->returnValue($fieldsDestination));
     $this->documentDestination = $this->getMockBuilder('\\Migration\\Resource\\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));
 }
Ejemplo n.º 13
0
 public function testVolumeCheck()
 {
     $fields = ['field_name' => []];
     $structure = $this->getMockBuilder('Migration\\Resource\\Structure')->disableOriginalConstructor()->setMethods(['getFields'])->getMock();
     $structure->expects($this->any())->method('getFields')->will($this->returnValue($fields));
     $document = $this->getMockBuilder('Migration\\Resource\\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->stores = new Stores($this->progress, $this->logger, $this->source, $this->destination, $this->recordTransformerFactory, $this->recordFactory, 'volume');
     $this->assertTrue($this->stores->perform());
 }
Ejemplo n.º 14
0
 public function testData()
 {
     $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\\Resource\\Document', [], [], '', false);
     $destinationRecord = $this->getMock('Migration\\Resource\\Record', [], [], '', false);
     $sourceRecord = $this->getMock('Migration\\Resource\\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->settings = new Settings($this->destination, $this->source, $this->logger, $this->progress, $this->recordFactory, $this->readerSettings, $this->handlerManagerFactory, 'data');
     $this->assertTrue($this->settings->perform());
 }