Skip to content

Commit 2c546c4

Browse files
committed
Update PHPUnit tests
1 parent 9868428 commit 2c546c4

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

app/code/Magento/Quote/Test/Unit/Model/ShippingMethodManagementTest.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
use Magento\Quote\Model\Quote\Address\Rate;
1616
use Magento\Quote\Model\Quote\TotalsCollector;
1717
use Magento\Quote\Model\QuoteRepository;
18+
use Magento\Quote\Model\ResourceModel\Quote\Address as QuoteAddressResource;
1819
use Magento\Quote\Model\ShippingMethodManagement;
20+
use Magento\Store\Model\Store;
1921
use PHPUnit_Framework_MockObject_MockObject as MockObject;
2022

2123
/**
@@ -83,6 +85,16 @@ class ShippingMethodManagementTest extends \PHPUnit\Framework\TestCase
8385
*/
8486
private $totalsCollector;
8587

88+
/**
89+
* @var Store|MockObject
90+
*/
91+
private $storeMock;
92+
93+
/**
94+
* @var QuoteAddressResource|MockObject
95+
*/
96+
private $quoteAddressResource;
97+
8698
protected function setUp()
8799
{
88100
$this->objectManager = new ObjectManager($this);
@@ -98,7 +110,8 @@ protected function setUp()
98110
$className = \Magento\Framework\Reflection\DataObjectProcessor::class;
99111
$this->dataProcessor = $this->createMock($className);
100112

101-
$this->storeMock = $this->createMock(\Magento\Store\Model\Store::class);
113+
$this->quoteAddressResource = $this->createMock(QuoteAddressResource::class);
114+
$this->storeMock = $this->createMock(Store::class);
102115
$this->quote = $this->getMockBuilder(Quote::class)
103116
->disableOriginalConstructor()
104117
->setMethods([
@@ -150,6 +163,7 @@ protected function setUp()
150163
'converter' => $this->converter,
151164
'totalsCollector' => $this->totalsCollector,
152165
'addressRepository' => $this->addressRepository,
166+
'quoteAddressResource' => $this->quoteAddressResource,
153167
]
154168
);
155169

@@ -344,6 +358,10 @@ public function testSetMethodWithVirtualProduct()
344358
$this->model->set($cartId, $carrierCode, $methodCode);
345359
}
346360

361+
/**
362+
* @expectedException \Magento\Framework\Exception\StateException
363+
* @expectedExceptionMessage The shipping address is missing. Set the address and try again.
364+
*/
347365
public function testSetMethodWithoutShippingAddress()
348366
{
349367
$cartId = 12;
@@ -357,8 +375,8 @@ public function testSetMethodWithoutShippingAddress()
357375
$this->quote->expects($this->once())->method('isVirtual')->will($this->returnValue(false));
358376
$this->quote->expects($this->once())
359377
->method('getShippingAddress')->will($this->returnValue($this->shippingAddress));
360-
$this->quote->expects($this->once())->method('collectTotals')->willReturnSelf();
361378
$this->shippingAddress->expects($this->once())->method('getCountryId')->will($this->returnValue(null));
379+
$this->quoteAddressResource->expects($this->once())->method('delete')->with($this->shippingAddress);
362380

363381
$this->model->set($cartId, $carrierCode, $methodCode);
364382
}
@@ -399,6 +417,10 @@ public function testSetMethodWithCouldNotSaveException()
399417
$this->model->set($cartId, $carrierCode, $methodCode);
400418
}
401419

420+
/**
421+
* @expectedException \Magento\Framework\Exception\StateException
422+
* @expectedExceptionMessage The shipping address is missing. Set the address and try again.
423+
*/
402424
public function testSetMethodWithoutAddress()
403425
{
404426
$cartId = 12;
@@ -413,8 +435,8 @@ public function testSetMethodWithoutAddress()
413435
$this->quote->expects($this->once())
414436
->method('getShippingAddress')
415437
->willReturn($this->shippingAddress);
416-
$this->quote->expects($this->once())->method('collectTotals')->willReturnSelf();
417438
$this->shippingAddress->expects($this->once())->method('getCountryId');
439+
$this->quoteAddressResource->expects($this->once())->method('delete')->with($this->shippingAddress);
418440

419441
$this->model->set($cartId, $carrierCode, $methodCode);
420442
}

0 commit comments

Comments
 (0)