Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InvoiceDocumentFactoryTest.php
Go to the documentation of this file.
1 <?php
7 
15 
19 class InvoiceDocumentFactoryTest extends \PHPUnit\Framework\TestCase
20 {
24  private $invoiceServiceMock;
25 
29  private $invoiceMock;
30 
34  private $invoiceDocumentFactory;
35 
39  private $itemMock;
40 
44  private $orderMock;
45 
49  private $commentMock;
50 
51  protected function setUp()
52  {
53  $this->invoiceServiceMock = $this->getMockBuilder(InvoiceService::class)
54  ->disableOriginalConstructor()
55  ->getMock();
56 
57  $this->orderMock = $this->getMockBuilder(Order::class)
58  ->disableOriginalConstructor()
59  ->getMock();
60 
61  $this->invoiceMock = $this->getMockBuilder(InvoiceInterface::class)
62  ->disableOriginalConstructor()
63  ->setMethods(['addComment'])
64  ->getMockForAbstractClass();
65 
66  $this->itemMock = $this->getMockBuilder(InvoiceItemCreationInterface::class)
67  ->disableOriginalConstructor()
68  ->getMock();
69 
70  $this->commentMock = $this->getMockBuilder(InvoiceCommentCreationInterface::class)
71  ->disableOriginalConstructor()
72  ->getMock();
73 
74  $this->invoiceDocumentFactory = new InvoiceDocumentFactory($this->invoiceServiceMock);
75  }
76 
77  public function testCreate()
78  {
79  $orderId = 10;
80  $orderQty = 3;
81  $comment = "Comment!";
82 
83  $this->itemMock->expects($this->once())
84  ->method('getOrderItemId')
85  ->willReturn($orderId);
86 
87  $this->itemMock->expects($this->once())
88  ->method('getQty')
89  ->willReturn($orderQty);
90 
91  $this->invoiceMock->expects($this->once())
92  ->method('addComment')
93  ->with($comment, null, null)
94  ->willReturnSelf();
95 
96  $this->invoiceServiceMock->expects($this->once())
97  ->method('prepareInvoice')
98  ->with($this->orderMock, [$orderId => $orderQty])
99  ->willReturn($this->invoiceMock);
100 
101  $this->commentMock->expects($this->once())
102  ->method('getComment')
103  ->willReturn($comment);
104 
105  $this->commentMock->expects($this->once())
106  ->method('getIsVisibleOnFront')
107  ->willReturn(false);
108 
109  $this->assertEquals(
110  $this->invoiceMock,
111  $this->invoiceDocumentFactory->create($this->orderMock, [$this->itemMock], $this->commentMock)
112  );
113  }
114 }