InvoiceDocumentFactoryTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Test\Unit\Model\Order;
  7. use Magento\Sales\Api\Data\InvoiceCommentCreationInterface;
  8. use Magento\Sales\Api\Data\InvoiceCreationArgumentsInterface;
  9. use Magento\Sales\Api\Data\InvoiceInterface;
  10. use Magento\Sales\Api\Data\InvoiceItemCreationInterface;
  11. use Magento\Sales\Model\Order;
  12. use Magento\Sales\Model\Order\InvoiceDocumentFactory;
  13. use Magento\Sales\Model\Service\InvoiceService;
  14. /**
  15. * Class InvoiceDocumentFactoryTest
  16. */
  17. class InvoiceDocumentFactoryTest extends \PHPUnit\Framework\TestCase
  18. {
  19. /**
  20. * @var \PHPUnit_Framework_MockObject_MockObject|InvoiceService
  21. */
  22. private $invoiceServiceMock;
  23. /**
  24. * @var \PHPUnit_Framework_MockObject_MockObject|InvoiceInterface
  25. */
  26. private $invoiceMock;
  27. /**
  28. * @var \PHPUnit_Framework_MockObject_MockObject|InvoiceDocumentFactory
  29. */
  30. private $invoiceDocumentFactory;
  31. /**
  32. * @var \PHPUnit_Framework_MockObject_MockObject|InvoiceCreationArgumentsInterface
  33. */
  34. private $itemMock;
  35. /**
  36. * @var \PHPUnit_Framework_MockObject_MockObject|Order
  37. */
  38. private $orderMock;
  39. /**
  40. * @var \PHPUnit_Framework_MockObject_MockObject|InvoiceCommentCreationInterface
  41. */
  42. private $commentMock;
  43. protected function setUp()
  44. {
  45. $this->invoiceServiceMock = $this->getMockBuilder(InvoiceService::class)
  46. ->disableOriginalConstructor()
  47. ->getMock();
  48. $this->orderMock = $this->getMockBuilder(Order::class)
  49. ->disableOriginalConstructor()
  50. ->getMock();
  51. $this->invoiceMock = $this->getMockBuilder(InvoiceInterface::class)
  52. ->disableOriginalConstructor()
  53. ->setMethods(['addComment'])
  54. ->getMockForAbstractClass();
  55. $this->itemMock = $this->getMockBuilder(InvoiceItemCreationInterface::class)
  56. ->disableOriginalConstructor()
  57. ->getMock();
  58. $this->commentMock = $this->getMockBuilder(InvoiceCommentCreationInterface::class)
  59. ->disableOriginalConstructor()
  60. ->getMock();
  61. $this->invoiceDocumentFactory = new InvoiceDocumentFactory($this->invoiceServiceMock);
  62. }
  63. public function testCreate()
  64. {
  65. $orderId = 10;
  66. $orderQty = 3;
  67. $comment = "Comment!";
  68. $this->itemMock->expects($this->once())
  69. ->method('getOrderItemId')
  70. ->willReturn($orderId);
  71. $this->itemMock->expects($this->once())
  72. ->method('getQty')
  73. ->willReturn($orderQty);
  74. $this->invoiceMock->expects($this->once())
  75. ->method('addComment')
  76. ->with($comment, null, null)
  77. ->willReturnSelf();
  78. $this->invoiceServiceMock->expects($this->once())
  79. ->method('prepareInvoice')
  80. ->with($this->orderMock, [$orderId => $orderQty])
  81. ->willReturn($this->invoiceMock);
  82. $this->commentMock->expects($this->once())
  83. ->method('getComment')
  84. ->willReturn($comment);
  85. $this->commentMock->expects($this->once())
  86. ->method('getIsVisibleOnFront')
  87. ->willReturn(false);
  88. $this->assertEquals(
  89. $this->invoiceMock,
  90. $this->invoiceDocumentFactory->create($this->orderMock, [$this->itemMock], $this->commentMock)
  91. );
  92. }
  93. }