15
15
use Magento \Quote \Model \Quote \Address \Rate ;
16
16
use Magento \Quote \Model \Quote \TotalsCollector ;
17
17
use Magento \Quote \Model \QuoteRepository ;
18
+ use Magento \Quote \Model \ResourceModel \Quote \Address as QuoteAddressResource ;
18
19
use Magento \Quote \Model \ShippingMethodManagement ;
20
+ use Magento \Store \Model \Store ;
19
21
use PHPUnit_Framework_MockObject_MockObject as MockObject ;
20
22
21
23
/**
@@ -83,6 +85,16 @@ class ShippingMethodManagementTest extends \PHPUnit\Framework\TestCase
83
85
*/
84
86
private $ totalsCollector ;
85
87
88
+ /**
89
+ * @var Store|MockObject
90
+ */
91
+ private $ storeMock ;
92
+
93
+ /**
94
+ * @var QuoteAddressResource|MockObject
95
+ */
96
+ private $ quoteAddressResource ;
97
+
86
98
protected function setUp ()
87
99
{
88
100
$ this ->objectManager = new ObjectManager ($ this );
@@ -98,7 +110,8 @@ protected function setUp()
98
110
$ className = \Magento \Framework \Reflection \DataObjectProcessor::class;
99
111
$ this ->dataProcessor = $ this ->createMock ($ className );
100
112
101
- $ this ->storeMock = $ this ->createMock (\Magento \Store \Model \Store::class);
113
+ $ this ->quoteAddressResource = $ this ->createMock (QuoteAddressResource::class);
114
+ $ this ->storeMock = $ this ->createMock (Store::class);
102
115
$ this ->quote = $ this ->getMockBuilder (Quote::class)
103
116
->disableOriginalConstructor ()
104
117
->setMethods ([
@@ -150,6 +163,7 @@ protected function setUp()
150
163
'converter ' => $ this ->converter ,
151
164
'totalsCollector ' => $ this ->totalsCollector ,
152
165
'addressRepository ' => $ this ->addressRepository ,
166
+ 'quoteAddressResource ' => $ this ->quoteAddressResource ,
153
167
]
154
168
);
155
169
@@ -344,6 +358,10 @@ public function testSetMethodWithVirtualProduct()
344
358
$ this ->model ->set ($ cartId , $ carrierCode , $ methodCode );
345
359
}
346
360
361
+ /**
362
+ * @expectedException \Magento\Framework\Exception\StateException
363
+ * @expectedExceptionMessage The shipping address is missing. Set the address and try again.
364
+ */
347
365
public function testSetMethodWithoutShippingAddress ()
348
366
{
349
367
$ cartId = 12 ;
@@ -357,8 +375,8 @@ public function testSetMethodWithoutShippingAddress()
357
375
$ this ->quote ->expects ($ this ->once ())->method ('isVirtual ' )->will ($ this ->returnValue (false ));
358
376
$ this ->quote ->expects ($ this ->once ())
359
377
->method ('getShippingAddress ' )->will ($ this ->returnValue ($ this ->shippingAddress ));
360
- $ this ->quote ->expects ($ this ->once ())->method ('collectTotals ' )->willReturnSelf ();
361
378
$ this ->shippingAddress ->expects ($ this ->once ())->method ('getCountryId ' )->will ($ this ->returnValue (null ));
379
+ $ this ->quoteAddressResource ->expects ($ this ->once ())->method ('delete ' )->with ($ this ->shippingAddress );
362
380
363
381
$ this ->model ->set ($ cartId , $ carrierCode , $ methodCode );
364
382
}
@@ -399,6 +417,10 @@ public function testSetMethodWithCouldNotSaveException()
399
417
$ this ->model ->set ($ cartId , $ carrierCode , $ methodCode );
400
418
}
401
419
420
+ /**
421
+ * @expectedException \Magento\Framework\Exception\StateException
422
+ * @expectedExceptionMessage The shipping address is missing. Set the address and try again.
423
+ */
402
424
public function testSetMethodWithoutAddress ()
403
425
{
404
426
$ cartId = 12 ;
@@ -413,8 +435,8 @@ public function testSetMethodWithoutAddress()
413
435
$ this ->quote ->expects ($ this ->once ())
414
436
->method ('getShippingAddress ' )
415
437
->willReturn ($ this ->shippingAddress );
416
- $ this ->quote ->expects ($ this ->once ())->method ('collectTotals ' )->willReturnSelf ();
417
438
$ this ->shippingAddress ->expects ($ this ->once ())->method ('getCountryId ' );
439
+ $ this ->quoteAddressResource ->expects ($ this ->once ())->method ('delete ' )->with ($ this ->shippingAddress );
418
440
419
441
$ this ->model ->set ($ cartId , $ carrierCode , $ methodCode );
420
442
}
0 commit comments