Skip to content

Commit

Permalink
Update PHPUnit tests #16555
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytro-ch committed Aug 4, 2018
1 parent 6f88af5 commit cc44078
Showing 1 changed file with 26 additions and 3 deletions.
Expand Up @@ -15,7 +15,9 @@
use Magento\Quote\Model\Quote\Address\Rate;
use Magento\Quote\Model\Quote\TotalsCollector;
use Magento\Quote\Model\QuoteRepository;
use Magento\Quote\Model\ResourceModel\Quote\Address as QuoteAddressResource;
use Magento\Quote\Model\ShippingMethodManagement;
use Magento\Store\Model\Store;
use PHPUnit_Framework_MockObject_MockObject as MockObject;

/**
Expand Down Expand Up @@ -83,6 +85,17 @@ class ShippingMethodManagementTest extends \PHPUnit\Framework\TestCase
*/
private $totalsCollector;

/**
* @var Store|MockObject
*/
private $storeMock;

/**
* @var QuoteAddressResource|MockObject
*/
private $quoteAddressResource;


protected function setUp()
{
$this->objectManager = new ObjectManager($this);
Expand All @@ -98,7 +111,8 @@ protected function setUp()
$className = \Magento\Framework\Reflection\DataObjectProcessor::class;
$this->dataProcessor = $this->createMock($className);

$this->storeMock = $this->createMock(\Magento\Store\Model\Store::class);
$this->quoteAddressResource = $this->createMock(QuoteAddressResource::class);
$this->storeMock = $this->createMock(Store::class);
$this->quote = $this->getMockBuilder(Quote::class)
->disableOriginalConstructor()
->setMethods([
Expand Down Expand Up @@ -150,6 +164,7 @@ protected function setUp()
'converter' => $this->converter,
'totalsCollector' => $this->totalsCollector,
'addressRepository' => $this->addressRepository,
'quoteAddressResource' => $this->quoteAddressResource,
]
);

Expand Down Expand Up @@ -344,6 +359,10 @@ public function testSetMethodWithVirtualProduct()
$this->model->set($cartId, $carrierCode, $methodCode);
}

/**
* @expectedException \Magento\Framework\Exception\StateException
* @expectedExceptionMessage Shipping address is not set
*/
public function testSetMethodWithoutShippingAddress()
{
$cartId = 12;
Expand All @@ -357,8 +376,8 @@ public function testSetMethodWithoutShippingAddress()
$this->quote->expects($this->once())->method('isVirtual')->will($this->returnValue(false));
$this->quote->expects($this->once())
->method('getShippingAddress')->will($this->returnValue($this->shippingAddress));
$this->quote->expects($this->once())->method('collectTotals')->willReturnSelf();
$this->shippingAddress->expects($this->once())->method('getCountryId')->will($this->returnValue(null));
$this->quoteAddressResource->expects($this->once())->method('delete')->with($this->shippingAddress);

$this->model->set($cartId, $carrierCode, $methodCode);
}
Expand Down Expand Up @@ -399,6 +418,10 @@ public function testSetMethodWithCouldNotSaveException()
$this->model->set($cartId, $carrierCode, $methodCode);
}

/**
* @expectedException \Magento\Framework\Exception\StateException
* @expectedExceptionMessage Shipping address is not set
*/
public function testSetMethodWithoutAddress()
{
$cartId = 12;
Expand All @@ -413,8 +436,8 @@ public function testSetMethodWithoutAddress()
$this->quote->expects($this->once())
->method('getShippingAddress')
->willReturn($this->shippingAddress);
$this->quote->expects($this->once())->method('collectTotals')->willReturnSelf();
$this->shippingAddress->expects($this->once())->method('getCountryId');
$this->quoteAddressResource->expects($this->once())->method('delete')->with($this->shippingAddress);

$this->model->set($cartId, $carrierCode, $methodCode);
}
Expand Down

0 comments on commit cc44078

Please sign in to comment.