Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
IndexerShowModeCommandTest.php
Go to the documentation of this file.
1 <?php
7 
10 use Symfony\Component\Console\Tester\CommandTester;
11 
13 {
19  private $command;
20 
21  public function testGetOptions()
22  {
23  $this->stateMock->expects($this->never())->method('setAreaCode')->with(FrontNameResolver::AREA_CODE);
24  $this->command = new IndexerShowModeCommand($this->objectManagerFactory);
25  $optionsList = $this->command->getInputList();
26  $this->assertSame(1, sizeof($optionsList));
27  $this->assertSame('index', $optionsList[0]->getName());
28  }
29 
30  public function testExecuteAll()
31  {
32  $this->configureAdminArea();
33  $indexerOne = $this->getIndexerMock(
34  ['isScheduled', 'setScheduled'],
35  ['indexer_id' => 'indexer_1', 'title' => 'Title_indexerOne']
36  );
37  $indexerOne->expects($this->once())->method('isScheduled')->willReturn(true);
38  $indexerTwo = $this->getIndexerMock(
39  ['isScheduled', 'setScheduled'],
40  ['indexer_id' => 'indexer_2', 'title' => 'Title_indexerTwo']
41  );
42  $indexerTwo->expects($this->once())->method('isScheduled')->willReturn(false);
43  $this->initIndexerCollectionByItems([$indexerOne, $indexerTwo]);
44 
45  $this->command = new IndexerShowModeCommand($this->objectManagerFactory);
46  $commandTester = new CommandTester($this->command);
47  $commandTester->execute([]);
48  $actualValue = $commandTester->getDisplay();
49  $expectedValue = sprintf('%-50s ', 'Title_indexerOne' . ':') . 'Update by Schedule' . PHP_EOL
50  . sprintf('%-50s ', 'Title_indexerTwo' . ':') . 'Update on Save';
51  $this->assertStringStartsWith($expectedValue, $actualValue);
52  }
53 
60  public function testExecuteWithIndex(array $inputIndexers, array $indexers, array $isScheduled)
61  {
62  $this->configureAdminArea();
63  $indexerMocks = [];
64  foreach ($indexers as $indexerData) {
65  $indexerMock = $this->getIndexerMock(
66  ['isScheduled', 'setScheduled'],
67  $indexerData
68  );
69  $indexerMock->method('isScheduled')
70  ->willReturn($isScheduled[$indexerData['indexer_id']]);
71  $indexerMocks[] = $indexerMock;
72  }
73 
74  $this->initIndexerCollectionByItems($indexerMocks);
75 
76  $this->command = new IndexerShowModeCommand($this->objectManagerFactory);
77  $commandTester = new CommandTester($this->command);
78  $commandTester->execute(['index' => $inputIndexers]);
79  $actualValue = $commandTester->getDisplay();
80  $expectedValue = sprintf('%-50s ', 'Title_indexerOne' . ':') . 'Update by Schedule' . PHP_EOL
81  . sprintf('%-50s ', 'Title_indexerTwo' . ':') . 'Update on Save';
82  $this->assertStringStartsWith($expectedValue, $actualValue);
83  }
84 
88  public function executeWithIndexDataProvider()
89  {
90  return [
91  [
92  'inputIndexers' => [
93  'id_indexerOne',
94  'id_indexerTwo'
95  ],
96  'indexers' => [
97  'id_indexerOne' => [
98  'indexer_id' => 'id_indexerOne',
99  'title' => 'Title_indexerOne'
100  ],
101  'id_indexerTwo' => [
102  'indexer_id' => 'id_indexerTwo',
103  'title' => 'Title_indexerTwo'
104  ],
105  'id_indexerThree' => [
106  'indexer_id' => 'id_indexerThree',
107  'title' => 'Title_indexerThree'
108  ],
109  ],
110  'Is Scheduled' => [
111  'id_indexerOne' => true,
112  'id_indexerTwo' => false,
113  'id_indexerThree' => false,
114  ]
115  ],
116  ];
117  }
118 }
testExecuteWithIndex(array $inputIndexers, array $indexers, array $isScheduled)