12
12
use Symfony \Component \Console \Helper \TableHelper ;
13
13
use Magento \Store \Model \Website ;
14
14
use Magento \Framework \Console \Cli ;
15
+ use Magento \Framework \Mview \View \CollectionFactory ;
15
16
16
17
/**
17
18
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -45,9 +46,15 @@ protected function setUp()
45
46
$ isLoadedProperty ->setAccessible (true );
46
47
$ isLoadedProperty ->setValue ($ this ->collection , true );
47
48
49
+ $ collectionFactory = $ this ->getMockBuilder (CollectionFactory::class)
50
+ ->disableOriginalConstructor ()
51
+ ->getMock ();
52
+ $ collectionFactory ->method ('create ' )
53
+ ->willReturn ($ this ->collection );
54
+
48
55
$ this ->command = $ this ->objectManager ->getObject (
49
56
IndexerStatusMviewCommand::class,
50
- ['collection ' => $ this -> collection ]
57
+ ['collectionFactory ' => $ collectionFactory ]
51
58
);
52
59
53
60
/** @var HelperSet $helperSet */
@@ -66,6 +73,8 @@ public function testExecute()
66
73
[
67
74
'view ' => [
68
75
'view_id ' => 'catalog_category_product ' ,
76
+ ],
77
+ 'state ' => [
69
78
'mode ' => 'enabled ' ,
70
79
'status ' => 'idle ' ,
71
80
'updated ' => '2017-01-01 11:11:11 ' ,
@@ -78,6 +87,8 @@ public function testExecute()
78
87
[
79
88
'view ' => [
80
89
'view_id ' => 'catalog_product_category ' ,
90
+ ],
91
+ 'state ' => [
81
92
'mode ' => 'disabled ' ,
82
93
'status ' => 'idle ' ,
83
94
'updated ' => '2017-01-01 11:11:11 ' ,
@@ -90,6 +101,8 @@ public function testExecute()
90
101
[
91
102
'view ' => [
92
103
'view_id ' => 'catalog_product_attribute ' ,
104
+ ],
105
+ 'state ' => [
93
106
'mode ' => 'enabled ' ,
94
107
'status ' => 'idle ' ,
95
108
'updated ' => '2017-01-01 11:11:11 ' ,
@@ -102,7 +115,7 @@ public function testExecute()
102
115
];
103
116
104
117
foreach ($ mviews as $ data ) {
105
- $ this ->collection ->addItem ($ this ->generateMviewStub ($ data ['view ' ], $ data ['changelog ' ]));
118
+ $ this ->collection ->addItem ($ this ->generateMviewStub ($ data ['view ' ], $ data ['changelog ' ], $ data [ ' state ' ] ));
106
119
}
107
120
$ this ->collection ->addItem ($ this ->getNeverEnabledMviewIndexerWithNoTable ());
108
121
@@ -153,18 +166,19 @@ public function testExecute()
153
166
/**
154
167
* @param array $viewData
155
168
* @param array $changelogData
169
+ * @param array $stateData
156
170
* @return Mview\View|Mview\View\Changelog|\PHPUnit_Framework_MockObject_MockObject
157
171
*/
158
- protected function generateMviewStub (array $ viewData , array $ changelogData )
172
+ protected function generateMviewStub (array $ viewData , array $ changelogData, array $ stateData )
159
173
{
160
174
/** @var Mview\View\Changelog|\PHPUnit_Framework_MockObject_MockObject $stub */
161
175
$ changelog = $ this ->getMockBuilder (\Magento \Framework \Mview \View \Changelog::class)
162
176
->disableOriginalConstructor ()
163
177
->getMock ();
164
178
165
179
$ list = [];
166
- if ($ changelogData ['version_id ' ] !== $ viewData ['version_id ' ]) {
167
- $ list = range ($ viewData ['version_id ' ]+1 , $ changelogData ['version_id ' ]);
180
+ if ($ changelogData ['version_id ' ] !== $ stateData ['version_id ' ]) {
181
+ $ list = range ($ stateData ['version_id ' ]+1 , $ changelogData ['version_id ' ]);
168
182
}
169
183
170
184
$ changelog ->expects ($ this ->any ())
@@ -175,6 +189,14 @@ protected function generateMviewStub(array $viewData, array $changelogData)
175
189
->method ('getVersion ' )
176
190
->willReturn ($ changelogData ['version_id ' ]);
177
191
192
+ /** @var \Magento\Indexer\Model\Mview\View\State|\PHPUnit_Framework_MockObject_MockObject $stub */
193
+ $ state = $ this ->getMockBuilder (\Magento \Indexer \Model \Mview \View \State::class)
194
+ ->disableOriginalConstructor ()
195
+ ->setMethods (['loadByView ' ])
196
+ ->getMock ();
197
+
198
+ $ state ->setData ($ stateData );
199
+
178
200
/** @var Mview\View|\PHPUnit_Framework_MockObject_MockObject $stub */
179
201
$ stub = $ this ->getMockBuilder (\Magento \Framework \Mview \View::class)
180
202
->disableOriginalConstructor ()
@@ -187,7 +209,7 @@ protected function generateMviewStub(array $viewData, array $changelogData)
187
209
188
210
$ stub ->expects ($ this ->any ())
189
211
->method ('getState ' )
190
- ->willReturnSelf ( );
212
+ ->willReturn ( $ state );
191
213
192
214
$ stub ->setData ($ viewData );
193
215
0 commit comments