SettingsTest.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Migration\Mode;
  7. class SettingsTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var Settings
  11. */
  12. protected $settings;
  13. /**
  14. * @var \Migration\App\Mode\StepList|\PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $stepList;
  17. /**
  18. * @var \Migration\Logger\Logger|\PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $logger;
  21. /**
  22. * @var \Migration\Config|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $config;
  25. /**
  26. * @var \Migration\App\Progress|\PHPUnit_Framework_MockObject_MockObject
  27. */
  28. protected $progress;
  29. /**
  30. * @var \Migration\Config|\PHPUnit_Framework_MockObject_MockObject
  31. */
  32. protected $configReader;
  33. /**
  34. * @return void
  35. */
  36. public function setUp()
  37. {
  38. $this->stepList = $this->getMockBuilder(\Migration\App\Mode\StepList::class)->disableOriginalConstructor()
  39. ->setMethods(['getSteps'])
  40. ->getMock();
  41. /** @var \Migration\App\Mode\StepListFactory|\PHPUnit_Framework_MockObject_MockObject $stepListFactory */
  42. $stepListFactory = $this->getMockBuilder(\Migration\App\Mode\StepListFactory::class)
  43. ->disableOriginalConstructor()
  44. ->setMethods(['create'])
  45. ->getMock();
  46. $stepListFactory->expects($this->any())->method('create')->with(['mode' => 'settings'])
  47. ->willReturn($this->stepList);
  48. $this->logger = $this->getMockBuilder(\Migration\Logger\Logger::class)->disableOriginalConstructor()
  49. ->setMethods(['info', 'warning', 'notice'])
  50. ->getMock();
  51. $this->progress = $this->getMockBuilder(\Migration\App\Progress::class)->disableOriginalConstructor()
  52. ->setMethods(['saveResult', 'isCompleted'])
  53. ->getMock();
  54. $this->configReader = $this->getMockBuilder(\Migration\Config::class)->disableOriginalConstructor()
  55. ->getMock();
  56. $this->settings = new Settings($this->progress, $this->logger, $stepListFactory, $this->configReader);
  57. }
  58. /**
  59. * @return void
  60. */
  61. public function testRunStepsIntegrityFail()
  62. {
  63. $this->expectException(\Migration\Exception::class);
  64. $this->expectExceptionMessage('Integrity Check failed');
  65. $step = $this->getMockBuilder(\Migration\App\Step\StageInterface::class)->getMock();
  66. $step->expects($this->once())->method('perform')->will($this->returnValue(false));
  67. $this->progress->expects($this->any())->method('saveResult')->willReturnSelf();
  68. $this->progress->expects($this->any())->method('isCompleted')->willReturn(false);
  69. $this->stepList->expects($this->once())->method('getSteps')
  70. ->willReturn(['Title' => ['integrity' => $step]]);
  71. $this->assertSame($this->settings, $this->settings->run());
  72. }
  73. /**
  74. * @return void
  75. */
  76. public function testRunStepsVolumeFail()
  77. {
  78. $this->logger->expects($this->once())->method('warning')->with('Volume Check failed');
  79. $stepIntegrity = $this->getMockBuilder(\Migration\App\Step\StageInterface::class)->getMock();
  80. $stepIntegrity->expects($this->once())->method('perform')->will($this->returnValue(true));
  81. $stepData = $this->getMockBuilder(\Migration\App\Step\StageInterface::class)->getMock();
  82. $stepData->expects($this->once())->method('perform')->will($this->returnValue(true));
  83. $stepVolume = $this->getMockBuilder(\Migration\App\Step\StageInterface::class)->getMock();
  84. $stepVolume->expects($this->once())->method('perform')->will($this->returnValue(false));
  85. $this->progress->expects($this->any())->method('saveResult')->willReturnSelf();
  86. $this->progress->expects($this->any())->method('isCompleted')->willReturn(false);
  87. $this->logger->expects($this->any())->method('info');
  88. $this->stepList->expects($this->any())->method('getSteps')
  89. ->willReturn(['Title' => ['integrity' => $stepIntegrity, 'data' => $stepData, 'volume' => $stepVolume]]);
  90. $this->assertTrue($this->settings->run());
  91. }
  92. /**
  93. * @return void
  94. */
  95. public function testRunStepsDataMigrationFail()
  96. {
  97. $this->expectException(\Migration\Exception::class);
  98. $this->expectExceptionMessage('Data Migration failed');
  99. $stepIntegrity = $this->getMockBuilder(\Migration\App\Step\StageInterface::class)->getMock();
  100. $stepIntegrity->expects($this->once())->method('perform')->will($this->returnValue(true));
  101. $stepData = $this->getMockBuilder(\Migration\App\Step\StageInterface::class)->getMock();
  102. $stepData->expects($this->once())->method('perform')->will($this->returnValue(false));
  103. $stepVolume = $this->getMockBuilder(\Migration\App\Step\StageInterface::class)->getMock();
  104. $stepVolume->expects($this->never())->method('perform');
  105. $this->progress->expects($this->any())->method('saveResult')->willReturnSelf();
  106. $this->progress->expects($this->any())->method('isCompleted')->willReturn(false);
  107. $this->logger->expects($this->any())->method('info');
  108. $this->stepList->expects($this->any())->method('getSteps')
  109. ->willReturn(['Title' => ['integrity' => $stepIntegrity, 'data' => $stepData, 'volume' => $stepVolume]]);
  110. $this->assertSame($this->settings, $this->settings->run());
  111. }
  112. /**
  113. * @return void
  114. */
  115. public function testRunStepsSuccess()
  116. {
  117. $stepIntegrity = $this->getMockBuilder(\Migration\App\Step\StageInterface::class)->getMock();
  118. $stepIntegrity->expects($this->once())->method('perform')->will($this->returnValue(true));
  119. $stepData = $this->getMockBuilder(\Migration\App\Step\StageInterface::class)->getMock();
  120. $stepData->expects($this->once())->method('perform')->will($this->returnValue(true));
  121. $stepVolume = $this->getMockBuilder(\Migration\App\Step\StageInterface::class)->getMock();
  122. $stepVolume->expects($this->once())->method('perform')->will($this->returnValue(true));
  123. $this->progress->expects($this->any())->method('saveResult')->willReturnSelf();
  124. $this->progress->expects($this->any())->method('isCompleted')->willReturn(false);
  125. $this->logger->expects($this->at(0))->method('info')->with("started");
  126. $this->logger->expects($this->at(1))->method('info')->with("started");
  127. $this->logger->expects($this->at(2))->method('info')->with("started");
  128. $this->logger->expects($this->at(3))->method('info')->with("Migration completed");
  129. $this->stepList->expects($this->any())->method('getSteps')
  130. ->willReturn(['Title' => ['integrity' => $stepIntegrity, 'data' => $stepData, 'volume' => $stepVolume]]);
  131. $this->assertTrue($this->settings->run());
  132. }
  133. /**
  134. * @return void
  135. */
  136. public function testRunStepsWithSuccessProgress()
  137. {
  138. $stepIntegrity = $this->getMockBuilder(\Migration\App\Step\StageInterface::class)->getMock();
  139. $stepIntegrity->expects($this->never())->method('perform');
  140. $stepData = $this->getMockBuilder(\Migration\App\Step\StageInterface::class)->getMock();
  141. $stepData->expects($this->never())->method('perform');
  142. $stepVolume = $this->getMockBuilder(\Migration\App\Step\StageInterface::class)->getMock();
  143. $stepVolume->expects($this->never())->method('perform');
  144. $this->progress->expects($this->never())->method('saveResult');
  145. $this->progress->expects($this->any())->method('isCompleted')->willReturn(true);
  146. $this->logger->expects($this->at(0))->method('info')->with("started");
  147. $this->logger->expects($this->at(1))->method('info')->with("started");
  148. $this->logger->expects($this->at(2))->method('info')->with("started");
  149. $this->logger->expects($this->at(3))->method('info')->with("Migration completed");
  150. $this->stepList->expects($this->any())->method('getSteps')
  151. ->willReturn(['Title' => ['integrity' => $stepIntegrity, 'data' => $stepData, 'volume' => $stepVolume]]);
  152. $this->assertTrue($this->settings->run());
  153. }
  154. }