6
6
namespace Magento \Sales \Test \Unit \Controller \Adminhtml \Order \Invoice ;
7
7
8
8
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
9
+ use Magento \Sales \Api \OrderRepositoryInterface ;
9
10
10
11
/**
11
12
* Class NewActionTest
12
13
* @package Magento\Sales\Controller\Adminhtml\Order\Invoice
13
14
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
14
15
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
16
+ * @SuppressWarnings(PHPMD.TooManyFields)
15
17
*/
16
18
class NewActionTest extends \PHPUnit \Framework \TestCase
17
19
{
@@ -90,6 +92,11 @@ class NewActionTest extends \PHPUnit\Framework\TestCase
90
92
*/
91
93
protected $ invoiceServiceMock ;
92
94
95
+ /**
96
+ * @var OrderRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
97
+ */
98
+ private $ orderRepositoryMock ;
99
+
93
100
protected function setUp ()
94
101
{
95
102
$ objectManager = new ObjectManager ($ this );
@@ -215,12 +222,15 @@ protected function setUp()
215
222
->disableOriginalConstructor ()
216
223
->getMock ();
217
224
225
+ $ this ->orderRepositoryMock = $ this ->createMock (OrderRepositoryInterface::class);
226
+
218
227
$ this ->controller = $ objectManager ->getObject (
219
228
\Magento \Sales \Controller \Adminhtml \Order \Invoice \NewAction::class,
220
229
[
221
230
'context ' => $ contextMock ,
222
231
'resultPageFactory ' => $ this ->resultPageFactoryMock ,
223
- 'invoiceService ' => $ this ->invoiceServiceMock
232
+ 'invoiceService ' => $ this ->invoiceServiceMock ,
233
+ 'orderRepository ' => $ this ->orderRepositoryMock
224
234
]
225
235
);
226
236
}
@@ -250,19 +260,17 @@ public function testExecute()
250
260
251
261
$ orderMock = $ this ->getMockBuilder (\Magento \Sales \Model \Order::class)
252
262
->disableOriginalConstructor ()
253
- ->setMethods (['load ' , 'getId ' , ' canInvoice ' ])
263
+ ->setMethods (['load ' , 'canInvoice ' ])
254
264
->getMock ();
255
- $ orderMock ->expects ($ this ->once ())
256
- ->method ('load ' )
257
- ->with ($ orderId )
258
- ->willReturnSelf ();
259
- $ orderMock ->expects ($ this ->once ())
260
- ->method ('getId ' )
261
- ->willReturn ($ orderId );
262
265
$ orderMock ->expects ($ this ->once ())
263
266
->method ('canInvoice ' )
264
267
->willReturn (true );
265
268
269
+ $ this ->orderRepositoryMock ->expects ($ this ->once ())
270
+ ->method ('get ' )
271
+ ->with ($ orderId )
272
+ ->willReturn ($ orderMock );
273
+
266
274
$ this ->invoiceServiceMock ->expects ($ this ->once ())
267
275
->method ('prepareInvoice ' )
268
276
->with ($ orderMock , [])
@@ -285,11 +293,7 @@ public function testExecute()
285
293
->with (true )
286
294
->will ($ this ->returnValue ($ commentText ));
287
295
288
- $ this ->objectManagerMock ->expects ($ this ->at (0 ))
289
- ->method ('create ' )
290
- ->with (\Magento \Sales \Model \Order::class)
291
- ->willReturn ($ orderMock );
292
- $ this ->objectManagerMock ->expects ($ this ->at (1 ))
296
+ $ this ->objectManagerMock ->expects ($ this ->once ())
293
297
->method ('get ' )
294
298
->with (\Magento \Backend \Model \Session::class)
295
299
->will ($ this ->returnValue ($ this ->sessionMock ));
@@ -318,19 +322,12 @@ public function testExecuteNoOrder()
318
322
319
323
$ orderMock = $ this ->getMockBuilder (\Magento \Sales \Model \Order::class)
320
324
->disableOriginalConstructor ()
321
- ->setMethods (['load ' , ' getId ' , ' canInvoice ' ])
325
+ ->setMethods (['canInvoice ' ])
322
326
->getMock ();
323
- $ orderMock ->expects ($ this ->once ())
324
- ->method ('load ' )
325
- ->with ($ orderId )
326
- ->willReturnSelf ();
327
- $ orderMock ->expects ($ this ->once ())
328
- ->method ('getId ' )
329
- ->willReturn (null );
330
327
331
- $ this ->objectManagerMock ->expects ($ this ->at ( 0 ))
332
- ->method ('create ' )
333
- ->with (\ Magento \ Sales \ Model \Order::class )
328
+ $ this ->orderRepositoryMock ->expects ($ this ->once ( ))
329
+ ->method ('get ' )
330
+ ->with ($ orderId )
334
331
->willReturn ($ orderMock );
335
332
336
333
$ resultRedirect = $ this ->getMockBuilder (\Magento \Backend \Model \View \Result \Redirect::class)
0 commit comments