ConfigTest.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Migration;
  7. /**
  8. * Class ConfigTest
  9. */
  10. class ConfigTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var Config
  14. */
  15. protected $config;
  16. /**
  17. * @throws Exception
  18. * @return void
  19. */
  20. protected function setUp()
  21. {
  22. $validationState = $this->getMockBuilder(\Magento\Framework\App\Arguments\ValidationState::class)
  23. ->disableOriginalConstructor()
  24. ->setMethods(['isValidationRequired'])
  25. ->getMock();
  26. $validationState->expects($this->any())->method('isValidationRequired')->willReturn(true);
  27. $this->config = new Config($validationState);
  28. $this->config->init(realpath(__DIR__ . '/_files/test-config.xml'));
  29. }
  30. /**
  31. * @return void
  32. */
  33. public function testDefaultConfigFile()
  34. {
  35. $this->assertNotEmpty($this->config->getOption('map_file'));
  36. }
  37. /**
  38. * @throws Exception
  39. * @return void
  40. */
  41. public function testInvalidConfigFile()
  42. {
  43. $this->expectException(\Migration\Exception::class);
  44. $this->expectExceptionMessage('Invalid config filename: non-existent.xml');
  45. $validationState = $this->getMockBuilder(\Magento\Framework\App\Arguments\ValidationState::class)
  46. ->disableOriginalConstructor()
  47. ->setMethods(['isValidationRequired'])
  48. ->getMock();
  49. $validationState->expects($this->any())->method('isValidationRequired')->willReturn(true);
  50. $config = new Config($validationState);
  51. $config->init('non-existent.xml');
  52. }
  53. /**
  54. * @throws Exception
  55. * @return void
  56. */
  57. public function testInvalidXml()
  58. {
  59. $this->expectException(\Migration\Exception::class);
  60. $this->expectExceptionMessage('XML file is invalid');
  61. $validationState = $this->getMockBuilder(\Magento\Framework\App\Arguments\ValidationState::class)
  62. ->disableOriginalConstructor()
  63. ->setMethods(['isValidationRequired'])
  64. ->getMock();
  65. $validationState->expects($this->any())->method('isValidationRequired')->willReturn(true);
  66. $config = new Config($validationState);
  67. $config->init(__DIR__ . '/_files/invalid-config.xml');
  68. }
  69. /**
  70. * @return void
  71. */
  72. public function testGetSteps()
  73. {
  74. $steps = [
  75. 'Step1' => [
  76. 'integrity' => \Migration\Step\SomeStep\Integrity::class,
  77. 'volume' => \Migration\Step\SomeStep\Volume::class
  78. ],
  79. 'Step2' => [
  80. 'integrity' => \Migration\Step\SomeStep\Integrity::class,
  81. 'volume' => \Migration\Step\SomeStep\Volume::class
  82. ]
  83. ];
  84. $this->assertEquals($steps, $this->config->getSteps('data'));
  85. }
  86. /**
  87. * @return void
  88. */
  89. public function testGetStep()
  90. {
  91. $step = ['delta' => \Migration\Step\SomeStep\Integrity::class];
  92. $this->assertEquals($step, $this->config->getStep('delta', 'Step1'));
  93. }
  94. /**
  95. * @return void
  96. */
  97. public function testGetSource()
  98. {
  99. $source = [
  100. 'type' => 'database',
  101. 'database' => [
  102. 'host' => 'localhost',
  103. 'user' => 'root',
  104. 'name' => 'magento1'
  105. ]
  106. ];
  107. $this->assertEquals($source, $this->config->getSource());
  108. }
  109. /**
  110. * @return void
  111. */
  112. public function testGetDestination()
  113. {
  114. $destination = [
  115. 'type' => 'database',
  116. 'database' => [
  117. 'host' => 'localhost',
  118. 'user' => 'root',
  119. 'name' => 'magento2',
  120. 'password' => '123123q'
  121. ]
  122. ];
  123. $this->assertEquals($destination, $this->config->getDestination());
  124. }
  125. /**
  126. * @return void
  127. */
  128. public function testGetOption()
  129. {
  130. $this->assertEquals('map-file.xml', $this->config->getOption('map_file'));
  131. $this->assertEquals('etc/settings.xml', $this->config->getOption('settings_map_file'));
  132. $this->assertEquals('100', $this->config->getOption('bulk_size'));
  133. $this->assertEquals('custom_option_value', $this->config->getOption('custom_option'));
  134. $this->assertEquals('map-sales.xml', $this->config->getOption('sales_order_map_file'));
  135. }
  136. /**
  137. * @return void
  138. */
  139. public function testSetOption()
  140. {
  141. $this->config->setOption('option1', 'value1');
  142. $this->assertEquals('value1', $this->config->getOption('option1'));
  143. }
  144. }