8
8
use Magento \Framework \Indexer \StateInterface ;
9
9
use Magento \Indexer \Console \Command \IndexerStatusCommand ;
10
10
use Symfony \Component \Console \Tester \CommandTester ;
11
+ use Symfony \Component \Console \Helper \HelperSet ;
12
+ use Symfony \Component \Console \Helper \TableHelper ;
11
13
12
14
class IndexerStatusCommandTest extends AbstractIndexerCommandCommonSetup
13
15
{
@@ -18,35 +20,134 @@ class IndexerStatusCommandTest extends AbstractIndexerCommandCommonSetup
18
20
*/
19
21
private $ command ;
20
22
23
+ /**
24
+ * @param \PHPUnit_Framework_MockObject_MockObject $indexerMock
25
+ * @param array $data
26
+ * @return mixed
27
+ */
28
+ private function attachViewToIndexerMock ($ indexerMock , array $ data )
29
+ {
30
+ /** @var \Magento\Framework\Mview\View\Changelog|\PHPUnit_Framework_MockObject_MockObject $changelog */
31
+ $ changelog = $ this ->getMockBuilder (\Magento \Framework \Mview \View \Changelog::class)
32
+ ->disableOriginalConstructor ()
33
+ ->getMock ();
34
+
35
+ $ changelog ->expects ($ this ->any ())
36
+ ->method ('getList ' )
37
+ ->willReturn (range (0 , $ data ['view ' ]['changelog ' ]['list_size ' ]-1 ));
38
+
39
+ /** @var \Magento\Indexer\Model\Mview\View\State|\PHPUnit_Framework_MockObject_MockObject $stateMock */
40
+ $ stateMock = $ this ->getMockBuilder (\Magento \Indexer \Model \Mview \View \State::class)
41
+ ->disableOriginalConstructor ()
42
+ ->setMethods (null )
43
+ ->getMock ();
44
+
45
+ $ stateMock ->addData ($ data ['view ' ]['state ' ]);
46
+
47
+ /** @var \Magento\Framework\Mview\View|\PHPUnit_Framework_MockObject_MockObject $viewMock */
48
+ $ viewMock = $ this ->getMockBuilder (\Magento \Framework \Mview \View::class)
49
+ ->disableOriginalConstructor ()
50
+ ->setMethods (['getChangelog ' , 'getState ' ])
51
+ ->getMock ();
52
+
53
+ $ viewMock ->expects ($ this ->any ())
54
+ ->method ('getState ' )
55
+ ->willReturn ($ stateMock );
56
+ $ viewMock ->expects ($ this ->any ())
57
+ ->method ('getChangelog ' )
58
+ ->willReturn ($ changelog );
59
+
60
+ $ indexerMock ->method ('getView ' )
61
+ ->willReturn ($ viewMock );
62
+
63
+ return $ indexerMock ;
64
+ }
65
+
21
66
/**
22
67
* @param array $indexers
23
- * @param array $statuses
68
+ *
24
69
* @dataProvider executeAllDataProvider
25
70
*/
26
- public function testExecuteAll (array $ indexers, array $ statuses )
71
+ public function testExecuteAll (array $ indexers )
27
72
{
28
73
$ this ->configureAdminArea ();
29
74
$ indexerMocks = [];
30
75
foreach ($ indexers as $ indexerData ) {
31
76
$ indexerMock = $ this ->getIndexerMock (
32
- ['getStatus ' ],
77
+ ['getStatus ' , ' isScheduled ' , ' getState ' , ' getView ' ],
33
78
$ indexerData
34
79
);
80
+
35
81
$ indexerMock ->method ('getStatus ' )
36
- ->willReturn ($ statuses [$ indexerData ['indexer_id ' ]]);
82
+ ->willReturn ($ indexerData ['status ' ]);
83
+ $ indexerMock ->method ('isScheduled ' )
84
+ ->willReturn ($ indexerData ['is_scheduled ' ]);
85
+
86
+ if ($ indexerData ['is_scheduled ' ]) {
87
+ $ this ->attachViewToIndexerMock ($ indexerMock , $ indexerData );
88
+ }
89
+
37
90
$ indexerMocks [] = $ indexerMock ;
38
91
}
92
+
39
93
$ this ->initIndexerCollectionByItems ($ indexerMocks );
40
94
$ this ->command = new IndexerStatusCommand ($ this ->objectManagerFactory );
95
+
96
+ $ objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
97
+
98
+ $ this ->command ->setHelperSet (
99
+ $ objectManager ->getObject (
100
+ HelperSet::class,
101
+ ['helpers ' => [$ objectManager ->getObject (TableHelper::class)]]
102
+ )
103
+ );
104
+
41
105
$ commandTester = new CommandTester ($ this ->command );
42
106
$ commandTester ->execute ([]);
43
- $ actualValue = $ commandTester ->getDisplay ();
44
- $ expectedValue = sprintf ('%-50s ' , 'Title_indexerOne ' . ': ' ) . 'Ready ' . PHP_EOL
45
- . sprintf ('%-50s ' , 'Title_indexerTwo ' . ': ' ) . 'Reindex required ' . PHP_EOL
46
- . sprintf ('%-50s ' , 'Title_indexerThree ' . ': ' ) . 'Processing ' . PHP_EOL
47
- . sprintf ('%-50s ' , 'Title_indexerFour ' . ': ' ) . 'unknown ' . PHP_EOL ;
48
107
49
- $ this ->assertStringStartsWith ($ expectedValue , $ actualValue );
108
+ $ linesOutput = array_filter (explode (PHP_EOL , $ commandTester ->getDisplay ()));
109
+
110
+ $ spacer = '+----------------+------------------+-----------+-------------------------+---------------------+ ' ;
111
+
112
+ $ this ->assertCount (8 , $ linesOutput , 'There should be 8 lines output. 3 Spacers, 1 header, 4 content. ' );
113
+ $ this ->assertEquals ($ linesOutput [0 ], $ spacer , "Lines 0, 2, 7 should be spacer lines " );
114
+ $ this ->assertEquals ($ linesOutput [2 ], $ spacer , "Lines 0, 2, 7 should be spacer lines " );
115
+ $ this ->assertEquals ($ linesOutput [7 ], $ spacer , "Lines 0, 2, 7 should be spacer lines " );
116
+
117
+ $ headerValues = array_values (array_filter (explode ('| ' , $ linesOutput [1 ])));
118
+ $ this ->assertEquals ('Title ' , trim ($ headerValues [0 ]));
119
+ $ this ->assertEquals ('Status ' , trim ($ headerValues [1 ]));
120
+ $ this ->assertEquals ('Update On ' , trim ($ headerValues [2 ]));
121
+ $ this ->assertEquals ('Schedule Status ' , trim ($ headerValues [3 ]));
122
+ $ this ->assertEquals ('Schedule Updated ' , trim ($ headerValues [4 ]));
123
+
124
+ $ indexer1 = array_values (array_filter (explode ('| ' , $ linesOutput [3 ])));
125
+ $ this ->assertEquals ('Title_indexer1 ' , trim ($ indexer1 [0 ]));
126
+ $ this ->assertEquals ('Ready ' , trim ($ indexer1 [1 ]));
127
+ $ this ->assertEquals ('Schedule ' , trim ($ indexer1 [2 ]));
128
+ $ this ->assertEquals ('idle (10 in backlog) ' , trim ($ indexer1 [3 ]));
129
+ $ this ->assertEquals ('2017-01-01 11:11:11 ' , trim ($ indexer1 [4 ]));
130
+
131
+ $ indexer2 = array_values (array_filter (explode ('| ' , $ linesOutput [4 ])));
132
+ $ this ->assertEquals ('Title_indexer2 ' , trim ($ indexer2 [0 ]));
133
+ $ this ->assertEquals ('Reindex required ' , trim ($ indexer2 [1 ]));
134
+ $ this ->assertEquals ('Save ' , trim ($ indexer2 [2 ]));
135
+ $ this ->assertEquals ('' , trim ($ indexer2 [3 ]));
136
+ $ this ->assertEquals ('' , trim ($ indexer2 [4 ]));
137
+
138
+ $ indexer3 = array_values (array_filter (explode ('| ' , $ linesOutput [5 ])));
139
+ $ this ->assertEquals ('Title_indexer3 ' , trim ($ indexer3 [0 ]));
140
+ $ this ->assertEquals ('Processing ' , trim ($ indexer3 [1 ]));
141
+ $ this ->assertEquals ('Schedule ' , trim ($ indexer3 [2 ]));
142
+ $ this ->assertEquals ('idle (100 in backlog) ' , trim ($ indexer3 [3 ]));
143
+ $ this ->assertEquals ('2017-01-01 11:11:11 ' , trim ($ indexer3 [4 ]));
144
+
145
+ $ indexer4 = array_values (array_filter (explode ('| ' , $ linesOutput [6 ])));
146
+ $ this ->assertEquals ('Title_indexer4 ' , trim ($ indexer4 [0 ]));
147
+ $ this ->assertEquals ('unknown ' , trim ($ indexer4 [1 ]));
148
+ $ this ->assertEquals ('Schedule ' , trim ($ indexer4 [2 ]));
149
+ $ this ->assertEquals ('running (20 in backlog) ' , trim ($ indexer4 [3 ]));
150
+ $ this ->assertEquals ('2017-01-01 11:11:11 ' , trim ($ indexer4 [4 ]));
50
151
}
51
152
52
153
/**
@@ -59,27 +160,65 @@ public function executeAllDataProvider()
59
160
'indexers ' => [
60
161
'indexer_1 ' => [
61
162
'indexer_id ' => 'indexer_1 ' ,
62
- 'title ' => 'Title_indexerOne '
163
+ 'title ' => 'Title_indexer1 ' ,
164
+ 'status ' => StateInterface::STATUS_VALID ,
165
+ 'is_scheduled ' => true ,
166
+ 'view ' => [
167
+ 'state ' => [
168
+ 'status ' => 'idle ' ,
169
+ 'updated ' => '2017-01-01 11:11:11 ' ,
170
+ ],
171
+ 'changelog ' => [
172
+ 'list_size ' => 10
173
+ ]
174
+ ]
63
175
],
64
176
'indexer_2 ' => [
65
177
'indexer_id ' => 'indexer_2 ' ,
66
- 'title ' => 'Title_indexerTwo '
178
+ 'title ' => 'Title_indexer2 ' ,
179
+ 'status ' => StateInterface::STATUS_INVALID ,
180
+ 'is_scheduled ' => false ,
181
+ 'view ' => [
182
+ 'state ' => [
183
+ 'status ' => 'idle ' ,
184
+ 'updated ' => '2017-01-01 11:11:11 ' ,
185
+ ],
186
+ 'changelog ' => [
187
+ 'list_size ' => 99999999
188
+ ]
189
+ ]
67
190
],
68
191
'indexer_3 ' => [
69
192
'indexer_id ' => 'indexer_3 ' ,
70
- 'title ' => 'Title_indexerThree '
193
+ 'title ' => 'Title_indexer3 ' ,
194
+ 'status ' => StateInterface::STATUS_WORKING ,
195
+ 'is_scheduled ' => true ,
196
+ 'view ' => [
197
+ 'state ' => [
198
+ 'status ' => 'idle ' ,
199
+ 'updated ' => '2017-01-01 11:11:11 ' ,
200
+ ],
201
+ 'changelog ' => [
202
+ 'list_size ' => 100
203
+ ]
204
+ ]
71
205
],
72
206
'indexer_4 ' => [
73
207
'indexer_id ' => 'indexer_4 ' ,
74
- 'title ' => 'Title_indexerFour '
208
+ 'title ' => 'Title_indexer4 ' ,
209
+ 'status ' => null ,
210
+ 'is_scheduled ' => true ,
211
+ 'view ' => [
212
+ 'state ' => [
213
+ 'status ' => 'running ' ,
214
+ 'updated ' => '2017-01-01 11:11:11 ' ,
215
+ ],
216
+ 'changelog ' => [
217
+ 'list_size ' => 20
218
+ ]
219
+ ]
75
220
],
76
221
],
77
- 'Statuses ' => [
78
- 'indexer_1 ' => StateInterface::STATUS_VALID ,
79
- 'indexer_2 ' => StateInterface::STATUS_INVALID ,
80
- 'indexer_3 ' => StateInterface::STATUS_WORKING ,
81
- 'indexer_4 ' => null ,
82
- ]
83
222
],
84
223
];
85
224
}
0 commit comments