GuestShippingAddressManagementTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Quote\Test\Unit\Model\GuestCart;
  8. class GuestShippingAddressManagementTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var \Magento\Quote\Model\GuestCart\GuestShippingAddressManagementInterface
  12. */
  13. protected $model;
  14. /**
  15. * @var \PHPUnit_Framework_MockObject_MockObject
  16. */
  17. protected $quoteAddressMock;
  18. /**
  19. * @var \PHPUnit_Framework_MockObject_MockObject
  20. */
  21. protected $quoteIdMaskFactoryMock;
  22. /**
  23. * @var \PHPUnit_Framework_MockObject_MockObject
  24. */
  25. protected $quoteIdMaskMock;
  26. /**
  27. * @var \PHPUnit_Framework_MockObject_MockObject
  28. */
  29. protected $shippingAddressManagementMock;
  30. /**
  31. * @var string
  32. */
  33. protected $maskedCartId;
  34. /**
  35. * @var int
  36. */
  37. protected $cartId;
  38. protected function setUp()
  39. {
  40. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  41. $this->shippingAddressManagementMock = $this->createMock(
  42. \Magento\Quote\Model\ShippingAddressManagementInterface::class
  43. );
  44. $this->quoteAddressMock = $this->createMock(\Magento\Quote\Model\Quote\Address::class);
  45. $this->maskedCartId = 'f216207248d65c789b17be8545e0aa73';
  46. $this->cartId = 123;
  47. $guestCartTestHelper = new GuestCartTestHelper($this);
  48. list($this->quoteIdMaskFactoryMock, $this->quoteIdMaskMock) = $guestCartTestHelper->mockQuoteIdMask(
  49. $this->maskedCartId,
  50. $this->cartId
  51. );
  52. $this->model = $objectManager->getObject(
  53. \Magento\Quote\Model\GuestCart\GuestShippingAddressManagement::class,
  54. [
  55. 'shippingAddressManagement' => $this->shippingAddressManagementMock,
  56. 'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock
  57. ]
  58. );
  59. }
  60. public function testAssign()
  61. {
  62. $addressId = 1;
  63. $this->shippingAddressManagementMock->expects($this->once())->method('assign')->willReturn($addressId);
  64. $this->assertEquals($addressId, $this->model->assign($this->maskedCartId, $this->quoteAddressMock));
  65. }
  66. public function testGet()
  67. {
  68. $this->shippingAddressManagementMock->expects($this->once())->method('get')->willReturn(
  69. $this->quoteAddressMock
  70. );
  71. $this->assertEquals($this->quoteAddressMock, $this->model->get($this->maskedCartId));
  72. }
  73. }