GuestShippingInformationManagementTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Checkout\Test\Unit\Model;
  7. class GuestShippingInformationManagementTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \PHPUnit_Framework_MockObject_MockObject
  11. */
  12. protected $shippingInformationManagementMock;
  13. /**
  14. * @var \PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $quoteIdMaskFactoryMock;
  17. /**
  18. * @var \Magento\Checkout\Model\GuestShippingInformationManagement
  19. */
  20. protected $model;
  21. protected function setUp()
  22. {
  23. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  24. $this->quoteIdMaskFactoryMock = $this->createPartialMock(
  25. \Magento\Quote\Model\QuoteIdMaskFactory::class,
  26. ['create']
  27. );
  28. $this->shippingInformationManagementMock = $this->createMock(
  29. \Magento\Checkout\Api\ShippingInformationManagementInterface::class
  30. );
  31. $this->model = $objectManager->getObject(
  32. \Magento\Checkout\Model\GuestShippingInformationManagement::class,
  33. [
  34. 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock,
  35. 'shippingInformationManagement' => $this->shippingInformationManagementMock
  36. ]
  37. );
  38. }
  39. public function testSaveAddressInformation()
  40. {
  41. $cartId = 'masked_id';
  42. $quoteId = 100;
  43. $addressInformationMock = $this->createMock(\Magento\Checkout\Api\Data\ShippingInformationInterface::class);
  44. $quoteIdMaskMock = $this->createPartialMock(\Magento\Quote\Model\QuoteIdMask::class, ['load', 'getQuoteId']);
  45. $this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($quoteIdMaskMock);
  46. $quoteIdMaskMock->expects($this->once())->method('load')->with($cartId, 'masked_id')->willReturnSelf();
  47. $quoteIdMaskMock->expects($this->once())->method('getQuoteId')->willReturn($quoteId);
  48. $paymentInformationMock = $this->createMock(\Magento\Checkout\Api\Data\PaymentDetailsInterface::class);
  49. $this->shippingInformationManagementMock->expects($this->once())
  50. ->method('saveAddressInformation')
  51. ->with($quoteId, $addressInformationMock)
  52. ->willReturn($paymentInformationMock);
  53. $this->model->saveAddressInformation($cartId, $addressInformationMock);
  54. }
  55. }