IndexerShowModeCommandTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Indexer\Test\Unit\Console\Command;
  7. use Magento\Backend\App\Area\FrontNameResolver;
  8. use Magento\Indexer\Console\Command\IndexerShowModeCommand;
  9. use Symfony\Component\Console\Tester\CommandTester;
  10. class IndexerShowModeCommandTest extends AbstractIndexerCommandCommonSetup
  11. {
  12. /**
  13. * Command being tested
  14. *
  15. * @var IndexerShowModeCommand
  16. */
  17. private $command;
  18. public function testGetOptions()
  19. {
  20. $this->stateMock->expects($this->never())->method('setAreaCode')->with(FrontNameResolver::AREA_CODE);
  21. $this->command = new IndexerShowModeCommand($this->objectManagerFactory);
  22. $optionsList = $this->command->getInputList();
  23. $this->assertSame(1, sizeof($optionsList));
  24. $this->assertSame('index', $optionsList[0]->getName());
  25. }
  26. public function testExecuteAll()
  27. {
  28. $this->configureAdminArea();
  29. $indexerOne = $this->getIndexerMock(
  30. ['isScheduled', 'setScheduled'],
  31. ['indexer_id' => 'indexer_1', 'title' => 'Title_indexerOne']
  32. );
  33. $indexerOne->expects($this->once())->method('isScheduled')->willReturn(true);
  34. $indexerTwo = $this->getIndexerMock(
  35. ['isScheduled', 'setScheduled'],
  36. ['indexer_id' => 'indexer_2', 'title' => 'Title_indexerTwo']
  37. );
  38. $indexerTwo->expects($this->once())->method('isScheduled')->willReturn(false);
  39. $this->initIndexerCollectionByItems([$indexerOne, $indexerTwo]);
  40. $this->command = new IndexerShowModeCommand($this->objectManagerFactory);
  41. $commandTester = new CommandTester($this->command);
  42. $commandTester->execute([]);
  43. $actualValue = $commandTester->getDisplay();
  44. $expectedValue = sprintf('%-50s ', 'Title_indexerOne' . ':') . 'Update by Schedule' . PHP_EOL
  45. . sprintf('%-50s ', 'Title_indexerTwo' . ':') . 'Update on Save';
  46. $this->assertStringStartsWith($expectedValue, $actualValue);
  47. }
  48. /**
  49. * @param array $inputIndexers
  50. * @param array $indexers
  51. * @param array $isScheduled
  52. * @dataProvider executeWithIndexDataProvider
  53. */
  54. public function testExecuteWithIndex(array $inputIndexers, array $indexers, array $isScheduled)
  55. {
  56. $this->configureAdminArea();
  57. $indexerMocks = [];
  58. foreach ($indexers as $indexerData) {
  59. $indexerMock = $this->getIndexerMock(
  60. ['isScheduled', 'setScheduled'],
  61. $indexerData
  62. );
  63. $indexerMock->method('isScheduled')
  64. ->willReturn($isScheduled[$indexerData['indexer_id']]);
  65. $indexerMocks[] = $indexerMock;
  66. }
  67. $this->initIndexerCollectionByItems($indexerMocks);
  68. $this->command = new IndexerShowModeCommand($this->objectManagerFactory);
  69. $commandTester = new CommandTester($this->command);
  70. $commandTester->execute(['index' => $inputIndexers]);
  71. $actualValue = $commandTester->getDisplay();
  72. $expectedValue = sprintf('%-50s ', 'Title_indexerOne' . ':') . 'Update by Schedule' . PHP_EOL
  73. . sprintf('%-50s ', 'Title_indexerTwo' . ':') . 'Update on Save';
  74. $this->assertStringStartsWith($expectedValue, $actualValue);
  75. }
  76. /**
  77. * @return array
  78. */
  79. public function executeWithIndexDataProvider()
  80. {
  81. return [
  82. [
  83. 'inputIndexers' => [
  84. 'id_indexerOne',
  85. 'id_indexerTwo'
  86. ],
  87. 'indexers' => [
  88. 'id_indexerOne' => [
  89. 'indexer_id' => 'id_indexerOne',
  90. 'title' => 'Title_indexerOne'
  91. ],
  92. 'id_indexerTwo' => [
  93. 'indexer_id' => 'id_indexerTwo',
  94. 'title' => 'Title_indexerTwo'
  95. ],
  96. 'id_indexerThree' => [
  97. 'indexer_id' => 'id_indexerThree',
  98. 'title' => 'Title_indexerThree'
  99. ],
  100. ],
  101. 'Is Scheduled' => [
  102. 'id_indexerOne' => true,
  103. 'id_indexerTwo' => false,
  104. 'id_indexerThree' => false,
  105. ]
  106. ],
  107. ];
  108. }
  109. }