OrderAdapterTest.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Test\Unit\Gateway\Data\Order;
  7. use Magento\Payment\Gateway\Data\Order\OrderAdapter;
  8. use Magento\Sales\Api\Data\OrderInterface;
  9. use Magento\Payment\Gateway\Data\AddressAdapterInterface;
  10. /**
  11. * Class OrderAdapterTest
  12. */
  13. class OrderAdapterTest extends \PHPUnit\Framework\TestCase
  14. {
  15. /** @var OrderAdapter */
  16. protected $model;
  17. /**
  18. * @var OrderInterface|\PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $orderMock;
  21. /**
  22. * @var \Magento\Payment\Gateway\Data\Order\AddressAdapterFactory|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $addressAdapterFactoryMock;
  25. protected function setUp()
  26. {
  27. $this->orderMock = $this->getMockBuilder(\Magento\Sales\Model\Order::class)
  28. ->disableOriginalConstructor()
  29. ->getMock();
  30. $this->addressAdapterFactoryMock =
  31. $this->getMockBuilder(\Magento\Payment\Gateway\Data\Order\AddressAdapterFactory::class)
  32. ->setMethods(['create'])
  33. ->disableOriginalConstructor()
  34. ->getMock();
  35. $this->model = new OrderAdapter($this->orderMock, $this->addressAdapterFactoryMock);
  36. }
  37. public function testGetCurrencyCode()
  38. {
  39. $expected = 'USD';
  40. $this->orderMock->expects($this->once())->method('getBaseCurrencyCode')->willReturn($expected);
  41. $this->assertEquals($expected, $this->model->getCurrencyCode());
  42. }
  43. public function testGetOrderIncrementId()
  44. {
  45. $expected = '1';
  46. $this->orderMock->expects($this->once())->method('getIncrementId')->willReturn($expected);
  47. $this->assertEquals($expected, $this->model->getOrderIncrementId());
  48. }
  49. public function testGetCustomerId()
  50. {
  51. $expected = 1;
  52. $this->orderMock->expects($this->once())->method('getCustomerId')->willReturn($expected);
  53. $this->assertEquals($expected, $this->model->getCustomerId());
  54. }
  55. public function testGetBillingAddressIsNull()
  56. {
  57. $this->orderMock->expects($this->once())->method('getBillingAddress')->willReturn(null);
  58. $this->assertSame(null, $this->model->getBillingAddress());
  59. }
  60. public function testGetBillingAddress()
  61. {
  62. /** @var AddressAdapterInterface $addressAdapterMock */
  63. $addressAdapterMock = $this->getMockBuilder(\Magento\Payment\Gateway\Data\AddressAdapterInterface::class)
  64. ->getMockForAbstractClass();
  65. /** @var \Magento\Sales\Api\Data\OrderAddressInterface $orderAddressMock */
  66. $orderAddressMock = $this->getMockBuilder(\Magento\Sales\Api\Data\OrderAddressInterface::class)
  67. ->getMockForAbstractClass();
  68. $this->addressAdapterFactoryMock->expects($this->once())
  69. ->method('create')
  70. ->with(['address' => $orderAddressMock])
  71. ->willReturn($addressAdapterMock);
  72. $this->orderMock->expects($this->exactly(2))->method('getBillingAddress')->willReturn($orderAddressMock);
  73. $this->assertSame($addressAdapterMock, $this->model->getBillingAddress());
  74. }
  75. public function testGetShippingAddressIsNull()
  76. {
  77. $this->orderMock->expects($this->once())->method('getShippingAddress')->willReturn(null);
  78. $this->assertSame(null, $this->model->getShippingAddress());
  79. }
  80. public function testGetShippingAddress()
  81. {
  82. /** @var AddressAdapterInterface $addressAdapterMock */
  83. $addressAdapterMock = $this->getMockBuilder(\Magento\Payment\Gateway\Data\AddressAdapterInterface::class)
  84. ->getMockForAbstractClass();
  85. /** @var \Magento\Sales\Api\Data\OrderAddressInterface $orderAddressMock */
  86. $orderAddressMock = $this->getMockBuilder(\Magento\Sales\Api\Data\OrderAddressInterface::class)
  87. ->getMockForAbstractClass();
  88. $this->addressAdapterFactoryMock->expects($this->once())
  89. ->method('create')
  90. ->with(['address' => $orderAddressMock])
  91. ->willReturn($addressAdapterMock);
  92. $this->orderMock->expects($this->exactly(2))->method('getShippingAddress')->willReturn($orderAddressMock);
  93. $this->assertSame($addressAdapterMock, $this->model->getShippingAddress());
  94. }
  95. }