Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GuestShippingInformationManagementTest.php
Go to the documentation of this file.
1 <?php
7 
8 class GuestShippingInformationManagementTest extends \PHPUnit\Framework\TestCase
9 {
14 
19 
23  protected $model;
24 
25  protected function setUp()
26  {
27  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
28  $this->quoteIdMaskFactoryMock = $this->createPartialMock(
29  \Magento\Quote\Model\QuoteIdMaskFactory::class,
30  ['create']
31  );
32  $this->shippingInformationManagementMock = $this->createMock(
33  \Magento\Checkout\Api\ShippingInformationManagementInterface::class
34  );
35 
36  $this->model = $objectManager->getObject(
37  \Magento\Checkout\Model\GuestShippingInformationManagement::class,
38  [
39  'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock,
40  'shippingInformationManagement' => $this->shippingInformationManagementMock
41  ]
42  );
43  }
44 
45  public function testSaveAddressInformation()
46  {
47  $cartId = 'masked_id';
48  $quoteId = 100;
49  $addressInformationMock = $this->createMock(\Magento\Checkout\Api\Data\ShippingInformationInterface::class);
50 
51  $quoteIdMaskMock = $this->createPartialMock(\Magento\Quote\Model\QuoteIdMask::class, ['load', 'getQuoteId']);
52  $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($quoteIdMaskMock);
53 
54  $quoteIdMaskMock->expects($this->once())->method('load')->with($cartId, 'masked_id')->willReturnSelf();
55  $quoteIdMaskMock->expects($this->once())->method('getQuoteId')->willReturn($quoteId);
56 
57  $paymentInformationMock = $this->createMock(\Magento\Checkout\Api\Data\PaymentDetailsInterface::class);
58  $this->shippingInformationManagementMock->expects($this->once())
59  ->method('saveAddressInformation')
60  ->with($quoteId, $addressInformationMock)
61  ->willReturn($paymentInformationMock);
62 
63  $this->model->saveAddressInformation($cartId, $addressInformationMock);
64  }
65 }
$objectManager
Definition: bootstrap.php:17
$cartId
Definition: quote.php:22