@@ -55,6 +55,21 @@ class UpdateQtyTest extends \PHPUnit_Framework_TestCase
55
55
*/
56
56
protected $ controller ;
57
57
58
+ /**
59
+ * @var \Magento\Framework\View\Result\PageFactory|\PHPUnit_Framework_MockObject_MockObject
60
+ */
61
+ protected $ resultPageFactoryMock ;
62
+
63
+ /**
64
+ * @var \Magento\Framework\Controller\Result\RawFactory|\PHPUnit_Framework_MockObject_MockObject
65
+ */
66
+ protected $ resultRawFactoryMock ;
67
+
68
+ /**
69
+ * @var \Magento\Framework\Controller\Result\JSONFactory|\PHPUnit_Framework_MockObject_MockObject
70
+ */
71
+ protected $ resultJsonFactoryMock ;
72
+
58
73
public function setUp ()
59
74
{
60
75
$ objectManager = new ObjectManager ($ this );
@@ -69,8 +84,8 @@ public function setUp()
69
84
$ this ->responseMock = $ this ->getMockBuilder ('Magento\Framework\App\Response\Http ' )
70
85
->disableOriginalConstructor ()
71
86
->getMock ();
72
- $ this ->resultPageMock = $ this ->getMockBuilder ('Magento\Framework \View\Result\Page ' )
73
- ->setMethods ([' getConfig ' ])
87
+ $ this ->resultPageMock = $ this ->getMockBuilder ('Magento\Backend\Model \View\Result\Page ' )
88
+ ->setMethods ([])
74
89
->disableOriginalConstructor ()
75
90
->getMock ();
76
91
$ this ->pageConfigMock = $ this ->getMockBuilder ('Magento\Framework\View\Page\Config ' )
@@ -110,10 +125,28 @@ public function setUp()
110
125
->method ('getObjectManager ' )
111
126
->will ($ this ->returnValue ($ this ->objectManagerMock ));
112
127
128
+ $ this ->resultPageFactoryMock = $ this ->getMockBuilder ('Magento\Framework\View\Result\PageFactory ' )
129
+ ->disableOriginalConstructor ()
130
+ ->setMethods ([])
131
+ ->getMock ();
132
+
133
+ $ this ->resultRawFactoryMock = $ this ->getMockBuilder ('Magento\Framework\Controller\Result\RawFactory ' )
134
+ ->disableOriginalConstructor ()
135
+ ->setMethods ([])
136
+ ->getMock ();
137
+
138
+ $ this ->resultJsonFactoryMock = $ this ->getMockBuilder ('Magento\Framework\Controller\Result\JSONFactory ' )
139
+ ->disableOriginalConstructor ()
140
+ ->setMethods ([])
141
+ ->getMock ();
142
+
113
143
$ this ->controller = $ objectManager ->getObject (
114
144
'Magento\Sales\Controller\Adminhtml\Order\Invoice\UpdateQty ' ,
115
145
[
116
- 'context ' => $ contextMock
146
+ 'context ' => $ contextMock ,
147
+ 'resultPageFactory ' => $ this ->resultPageFactoryMock ,
148
+ 'resultRawFactory ' => $ this ->resultRawFactoryMock ,
149
+ 'resultJsonFactory ' => $ this ->resultJsonFactoryMock
117
150
]
118
151
);
119
152
}
@@ -173,10 +206,6 @@ public function testExecute()
173
206
->with ('Magento\Sales\Model\Service\Order ' )
174
207
->willReturn ($ orderService );
175
208
176
- $ this ->responseMock ->expects ($ this ->once ())
177
- ->method ('setBody ' )
178
- ->with ($ response );
179
-
180
209
$ blockItemMock = $ this ->getMockBuilder ('Magento\Sales\Block\Order\Items ' )
181
210
->disableOriginalConstructor ()
182
211
->setMethods ([])
@@ -193,16 +222,29 @@ public function testExecute()
193
222
->method ('getBlock ' )
194
223
->with ('order_items ' )
195
224
->will ($ this ->returnValue ($ blockItemMock ));
196
- $ this -> viewMock -> expects ( $ this -> once ())-> method ( ' getPage ' )-> will ( $ this -> returnValue ( $ this -> resultPageMock ));
197
- $ this ->viewMock ->expects ($ this ->once ())
225
+
226
+ $ this ->resultPageMock ->expects ($ this ->once ())
198
227
->method ('getLayout ' )
199
228
->will ($ this ->returnValue ($ layoutMock ));
200
- $ this ->resultPageMock ->expects ($ this ->once ())->method ('getConfig ' )->will (
201
- $ this ->returnValue ($ this ->pageConfigMock )
202
- );
229
+ $ this ->resultPageMock ->expects ($ this ->once ())
230
+ ->method ('getConfig ' )
231
+ ->will ($ this ->returnValue ($ this ->pageConfigMock ));
232
+
203
233
$ this ->pageConfigMock ->expects ($ this ->once ())->method ('getTitle ' )->will ($ this ->returnValue ($ this ->titleMock ));
204
234
205
- $ this ->assertNull ($ this ->controller ->execute ());
235
+ $ this ->resultPageFactoryMock ->expects ($ this ->once ())
236
+ ->method ('create ' )
237
+ ->will ($ this ->returnValue ($ this ->resultPageMock ));
238
+
239
+ $ resultRaw = $ this ->getMockBuilder ('Magento\Framework\Controller\Result\Raw ' )
240
+ ->disableOriginalConstructor ()
241
+ ->setMethods ([])
242
+ ->getMock ();
243
+ $ resultRaw ->expects ($ this ->once ())->method ('setContents ' )->with ($ response );
244
+
245
+ $ this ->resultRawFactoryMock ->expects ($ this ->once ())->method ('create ' )->will ($ this ->returnValue ($ resultRaw ));
246
+
247
+ $ this ->assertSame ($ resultRaw , $ this ->controller ->execute ());
206
248
}
207
249
208
250
public function testExecuteModelException ()
@@ -229,10 +271,6 @@ public function testExecuteModelException()
229
271
->method ('prepend ' )
230
272
->with ('Invoices ' );
231
273
232
- $ this ->responseMock ->expects ($ this ->once ())
233
- ->method ('representJson ' )
234
- ->with (json_encode ($ response ));
235
-
236
274
$ helperMock = $ this ->getMockBuilder ('Magento\Core\Helper\Data ' )
237
275
->disableOriginalConstructor ()
238
276
->setMethods ([])
@@ -247,7 +285,18 @@ public function testExecuteModelException()
247
285
->with ('Magento\Core\Helper\Data ' )
248
286
->will ($ this ->returnValue ($ helperMock ));
249
287
250
- $ this ->assertNull ($ this ->controller ->execute ());
288
+ /** @var \Magento\Framework\Controller\Result\JSON|\PHPUnit_Framework_MockObject_MockObject */
289
+ $ resultJsonMock = $ this ->getMockBuilder ('Magento\Framework\Controller\Result\JSON ' )
290
+ ->disableOriginalConstructor ()
291
+ ->setMethods ([])
292
+ ->getMock ();
293
+ $ resultJsonMock ->expects ($ this ->once ())->method ('setJsonData ' )->with (json_encode ($ response ));
294
+
295
+ $ this ->resultJsonFactoryMock ->expects ($ this ->once ())
296
+ ->method ('create ' )
297
+ ->will ($ this ->returnValue ($ resultJsonMock ));
298
+
299
+ $ this ->assertSame ($ resultJsonMock , $ this ->controller ->execute ());
251
300
}
252
301
253
302
public function testExecuteException ()
@@ -269,14 +318,11 @@ public function testExecuteException()
269
318
->method ('create ' )
270
319
->with ('Magento\Sales\Model\Order ' )
271
320
->willReturn ($ orderMock );
321
+
272
322
$ this ->titleMock ->expects ($ this ->never ())
273
323
->method ('prepend ' )
274
324
->with ('Invoices ' );
275
325
276
- $ this ->responseMock ->expects ($ this ->once ())
277
- ->method ('representJson ' )
278
- ->with (json_encode ($ response ));
279
-
280
326
$ helperMock = $ this ->getMockBuilder ('Magento\Core\Helper\Data ' )
281
327
->disableOriginalConstructor ()
282
328
->setMethods ([])
@@ -291,6 +337,17 @@ public function testExecuteException()
291
337
->with ('Magento\Core\Helper\Data ' )
292
338
->will ($ this ->returnValue ($ helperMock ));
293
339
294
- $ this ->assertNull ($ this ->controller ->execute ());
340
+ /** @var \Magento\Framework\Controller\Result\JSON|\PHPUnit_Framework_MockObject_MockObject */
341
+ $ resultJsonMock = $ this ->getMockBuilder ('Magento\Framework\Controller\Result\JSON ' )
342
+ ->disableOriginalConstructor ()
343
+ ->setMethods ([])
344
+ ->getMock ();
345
+ $ resultJsonMock ->expects ($ this ->once ())->method ('setJsonData ' )->with (json_encode ($ response ));
346
+
347
+ $ this ->resultJsonFactoryMock ->expects ($ this ->once ())
348
+ ->method ('create ' )
349
+ ->will ($ this ->returnValue ($ resultJsonMock ));
350
+
351
+ $ this ->assertSame ($ resultJsonMock , $ this ->controller ->execute ());
295
352
}
296
353
}
0 commit comments