Example #1
0
 public function testIntegrityWithoutMap()
 {
     $objectManager = \Migration\TestFramework\Helper::getInstance()->getObjectManager();
     $objectManager->get('\\Migration\\Config')->init(dirname(__DIR__) . '/../_files/config-with-empty-map.xml');
     $logManager = $objectManager->create('\\Migration\\Logger\\Manager');
     $logger = $objectManager->create('\\Migration\\Logger\\Logger');
     $logger->pushHandler($objectManager->create('\\Migration\\Logger\\ConsoleHandler'));
     $config = $objectManager->get('\\Migration\\Config');
     /** @var \Migration\Logger\Manager $logManager */
     $logManager->process(\Migration\Logger\Manager::LOG_LEVEL_ERROR);
     \Migration\Logger\Logger::clearMessages();
     /** @var \Migration\Step\Map\Integrity $map */
     $map = $objectManager->create('\\Migration\\Step\\Map\\Integrity', ['logger' => $logger, 'config' => $config]);
     ob_start();
     $map->perform();
     ob_end_clean();
     $messages = [];
     $messages[] = 'Source documents not mapped: ';
     $messages[] = 'source_table_1,source_table_2,source_table_ignored,source_table_renamed,table_with_data';
     $messages[] = 'Destination documents not mapped: ';
     $messages[] = 'dest_table_1,dest_table_2,dest_table_ignored,dest_table_renamed,table_without_data';
     $messages[] = 'Source fields not mapped. ';
     $messages[] = 'Document: common_table. Fields: source_field_ignored';
     $messages[] = 'Destination fields not mapped. ';
     $messages[] = 'Document: common_table. Fields: dest_field_ignored';
     $logOutput = \Migration\Logger\Logger::getMessages();
     $this->assertTrue(isset($logOutput[\Monolog\Logger::ERROR]));
     $errors = implode("\n", $logOutput[\Monolog\Logger::ERROR]);
     foreach ($messages as $text) {
         $this->assertContains($text, $errors);
     }
 }
Example #2
0
 public function testPerform()
 {
     $progress = $this->getMock('Migration\\App\\Progress', ['getProcessedEntities', 'addProcessedEntity'], [], '', false);
     $progress->expects($this->once())->method('getProcessedEntities')->will($this->returnValue([]));
     $progress->expects($this->any())->method('addProcessedEntity');
     $helper = \Migration\TestFramework\Helper::getInstance();
     $objectManager = $helper->getObjectManager();
     $objectManager->get('\\Migration\\Config')->init(dirname(__DIR__) . '/../_files/' . $helper->getFixturePrefix() . 'config.xml');
     $logManager = $objectManager->create('\\Migration\\Logger\\Manager');
     $logger = $objectManager->create('\\Migration\\Logger\\Logger');
     $logger->pushHandler($objectManager->create('\\Migration\\Logger\\ConsoleHandler'));
     $config = $objectManager->get('\\Migration\\Config');
     $destination = $objectManager->get('\\Migration\\Resource\\Destination');
     /** @var \Migration\Logger\Manager $logManager */
     $logManager->process(\Migration\Logger\Manager::LOG_LEVEL_ERROR);
     \Migration\Logger\Logger::clearMessages();
     $map = $objectManager->create('\\Migration\\Step\\Map\\Data', ['logger' => $logger, 'config' => $config, 'progress' => $progress]);
     ob_start();
     $map->perform();
     ob_end_clean();
     $migratedData = $destination->getRecords('table_without_data', 0);
     $migratedDataExpected = [['key' => 1, 'field1' => 1, 'field2' => 2, 'field3' => 3], ['key' => 2, 'field1' => 2, 'field2' => 3, 'field3' => 4], ['key' => 3, 'field1' => 3, 'field2' => 4, 'field3' => 5], ['key' => 4, 'field1' => 4, 'field2' => 5, 'field3' => 6], ['key' => 5, 'field1' => 5, 'field2' => 5, 'field3' => 5], ['key' => 6, 'field1' => 6, 'field2' => 6, 'field3' => 7], ['key' => 7, 'field1' => 7, 'field2' => 7, 'field3' => 7]];
     $migratedDataIgnored = $destination->getRecords('table_ignored', 0);
     $migratedDataIgnoredExpected = [];
     $migratedDataPresetValue = $destination->getRecords('common_table', 0);
     $migratedDataPresetValueExpected = [['key' => 1, 'dest_field_ignored' => 0, 'common_field' => 123], ['key' => 2, 'dest_field_ignored' => 0, 'common_field' => 123], ['key' => 3, 'dest_field_ignored' => 0, 'common_field' => 123], ['key' => 4, 'dest_field_ignored' => 0, 'common_field' => 123], ['key' => 5, 'dest_field_ignored' => 0, 'common_field' => 123], ['key' => 6, 'dest_field_ignored' => 0, 'common_field' => 123], ['key' => 7, 'dest_field_ignored' => 0, 'common_field' => 123]];
     $logOutput = \Migration\Logger\Logger::getMessages();
     $this->assertFalse(isset($logOutput[\Monolog\Logger::ERROR]));
     $this->assertEquals($migratedDataExpected, $migratedData);
     $this->assertEquals($migratedDataIgnoredExpected, $migratedDataIgnored);
     $this->assertEquals($migratedDataPresetValueExpected, $migratedDataPresetValue);
 }
 /**
  * @throws \Migration\Exception
  * @return void
  */
 public function testPerform()
 {
     $helper = \Migration\TestFramework\Helper::getInstance();
     $objectManager = $helper->getObjectManager();
     $objectManager->get('\\Migration\\Config')->init(dirname(__DIR__) . '/../_files/' . $helper->getFixturePrefix() . 'config.xml');
     $logManager = $objectManager->create('\\Migration\\Logger\\Manager');
     $recordFactory = $objectManager->create('\\Migration\\ResourceModel\\RecordFactory');
     $progress = $objectManager->create('\\Migration\\App\\ProgressBar\\LogLevelProcessor');
     $logger = $objectManager->create('\\Migration\\Logger\\Logger');
     $mapReader = $objectManager->create('\\Migration\\Reader\\Settings');
     $handlerManagerFactory = $objectManager->get('\\Migration\\Handler\\ManagerFactory');
     $destination = $objectManager->get('\\Migration\\ResourceModel\\Destination');
     $source = $objectManager->get('\\Migration\\ResourceModel\\Source');
     /** @var \Migration\Logger\Manager $logManager */
     $logManager->process(\Migration\Logger\Manager::LOG_LEVEL_ERROR);
     \Migration\Logger\Logger::clearMessages();
     $data = $objectManager->create('\\Migration\\Step\\Settings\\Data', ['destination' => $destination, 'source' => $source, 'logger' => $logger, 'progress' => $progress, 'recordFactory' => $recordFactory, 'mapReader' => $mapReader, 'handlerManagerFactory' => $handlerManagerFactory]);
     ob_start();
     $data->perform();
     ob_end_clean();
     $migratedData = $destination->getRecords('core_config_data', 0);
     $migratedDataExpected = [['config_id' => 1, 'scope' => 'default', 'scope_id' => 0, 'path' => 'web/seo/use_rewrites', 'value' => 1], ['config_id' => 2, 'scope' => 'default', 'scope_id' => 0, 'path' => 'web/unsecure/base_url', 'value' => 'http://magento2.dev/'], ['config_id' => 3, 'scope' => 'default', 'scope_id' => 0, 'path' => 'admin/security/session_lifetime', 'value' => 90], ['config_id' => 4, 'scope' => 'default', 'scope_id' => 0, 'path' => 'catalog/seo/product_url_suffix', 'value' => '.phtml'], ['config_id' => 5, 'scope' => 'default', 'scope_id' => 0, 'path' => 'my/extension/path', 'value' => 'value1']];
     $logOutput = \Migration\Logger\Logger::getMessages();
     $this->assertFalse(isset($logOutput[\Monolog\Logger::ERROR]));
     $this->assertEquals($migratedDataExpected, $migratedData);
 }
 /**
  * @throws \Migration\Exception
  * @return void
  */
 public function testPerform()
 {
     $salesOrderToMigrate = [['entity_id' => '1', 'store_id' => '1'], ['entity_id' => '2', 'store_id' => '1'], ['entity_id' => '3', 'store_id' => '1']];
     $eavAttributesToMigrate = [['value_id' => '1', 'entity_type_id' => '1', 'attribute_id' => '1', 'store_id' => '1', 'entity_id' => '1', 'value' => '1'], ['value_id' => '2', 'entity_type_id' => '1', 'attribute_id' => '2', 'store_id' => '1', 'entity_id' => '1', 'value' => '2'], ['value_id' => '3', 'entity_type_id' => '1', 'attribute_id' => '1', 'store_id' => '1', 'entity_id' => '2', 'value' => '1'], ['value_id' => '4', 'entity_type_id' => '1', 'attribute_id' => '2', 'store_id' => '1', 'entity_id' => '3', 'value' => '2']];
     $objectManager = \Migration\TestFramework\Helper::getInstance()->getObjectManager();
     $objectManager->get('\\Migration\\Config')->init(dirname(__DIR__) . '/../_files/config.xml');
     $logManager = $objectManager->create('\\Migration\\Logger\\Manager');
     $logger = $objectManager->create('\\Migration\\Logger\\Logger');
     $config = $objectManager->get('\\Migration\\Config');
     $initialData = $objectManager->get('\\Migration\\Step\\SalesOrder\\InitialData');
     $destination = $objectManager->get('\\Migration\\ResourceModel\\Destination');
     /** @var \Migration\Logger\Manager $logManager */
     $logManager->process(\Migration\Logger\Manager::LOG_LEVEL_ERROR);
     \Migration\Logger\Logger::clearMessages();
     $data = $objectManager->create('\\Migration\\Step\\SalesOrder\\Data', ['logger' => $logger, 'config' => $config, 'initialData' => $initialData]);
     $volume = $objectManager->create('\\Migration\\Step\\SalesOrder\\Volume', ['logger' => $logger, 'config' => $config, 'initialData' => $initialData]);
     ob_start();
     $data->perform();
     $this->assertTrue($volume->perform());
     ob_end_clean();
     $this->assertEquals($eavAttributesToMigrate, $destination->getRecords('eav_entity_int', 0));
     $this->assertEquals($salesOrderToMigrate, $destination->getRecords('sales_order', 0));
     $logOutput = \Migration\Logger\Logger::getMessages();
     $this->assertFalse(isset($logOutput[\Monolog\Logger::ERROR]));
 }
 /**
  * @covers Migration\Logger\Logger::addRecord
  * @covers Migration\Logger\Logger::getMessages
  * @return void
  */
 public function testAddRecord()
 {
     $infoMessage = 'info1';
     $errorMessage = 'error1';
     $consoleHandler = $this->getMockBuilder('\\Migration\\Logger\\ConsoleHandler')->disableOriginalConstructor()->setMethods(['handle'])->getMock();
     $consoleHandler->expects($this->any())->method('handle')->will($this->returnValue(true));
     $this->logger->pushHandler($consoleHandler);
     $this->logger->addRecord(\Monolog\Logger::INFO, $infoMessage);
     $this->logger->addRecord(\Monolog\Logger::ERROR, $errorMessage);
     $messages = \Migration\Logger\Logger::getMessages();
     $this->assertEquals($infoMessage, $messages[\Monolog\Logger::INFO][0]);
     $this->assertEquals($errorMessage, $messages[\Monolog\Logger::ERROR][0]);
     $this->logger->clearMessages();
     $this->assertEmpty(\Migration\Logger\Logger::getMessages());
 }
 /**
  * @return void
  */
 public function testData()
 {
     $urlRewrite = $this->objectManager->create('\\Migration\\Step\\UrlRewrite\\Version11410to2000', ['logger' => $this->logger, 'config' => $this->config, 'stage' => 'data']);
     /** @var \Migration\ResourceModel\Destination $destination */
     $destination = $this->objectManager->get('\\Migration\\ResourceModel\\Destination');
     ob_start();
     $urlRewrite->perform();
     ob_end_clean();
     $logOutput = \Migration\Logger\Logger::getMessages();
     $this->assertTrue(empty($logOutput[\Monolog\Logger::ERROR]));
     $this->assertEquals(48, $destination->getRecordsCount('url_rewrite'));
     $this->assertEquals(11, $destination->getRecordsCount('catalog_category_entity_varchar'));
     $this->assertEquals(4, $destination->getRecordsCount('catalog_product_entity_varchar'));
     $urlRewrite = $this->objectManager->create('\\Migration\\Step\\UrlRewrite\\Version11410to2000', ['logger' => $this->logger, 'config' => $this->config, 'stage' => 'volume']);
     $result = $urlRewrite->perform();
     $this->assertTrue($result);
 }
 /**
  * @throws \Migration\Exception
  * @return void
  */
 public function testPerform()
 {
     $objectManager = \Migration\TestFramework\Helper::getInstance()->getObjectManager();
     $objectManager->get('\\Migration\\Config')->init(dirname(__DIR__) . '/../_files/config.xml');
     $logManager = $objectManager->create('\\Migration\\Logger\\Manager');
     $logger = $objectManager->create('\\Migration\\Logger\\Logger');
     $config = $objectManager->get('\\Migration\\Config');
     $initialData = $objectManager->get('\\Migration\\Step\\SalesOrder\\InitialData');
     /** @var \Migration\Logger\Manager $logManager */
     $logManager->process(\Migration\Logger\Manager::LOG_LEVEL_ERROR);
     \Migration\Logger\Logger::clearMessages();
     /** @var \Migration\Step\SalesOrder\Integrity $salesOrder */
     $salesOrder = $objectManager->create('\\Migration\\Step\\SalesOrder\\Integrity', ['logger' => $logger, 'config' => $config, 'initialData' => $initialData]);
     ob_start();
     $salesOrder->perform();
     ob_end_clean();
     $logOutput = \Migration\Logger\Logger::getMessages();
     $this->assertFalse(isset($logOutput[\Monolog\Logger::ERROR]));
 }