24 private $objectManager;
34 private $orderItemMock;
38 $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
40 $this->orderMock = $this->getMockBuilder(\
Magento\Sales\Api\
Data\OrderInterface::class)
41 ->disableOriginalConstructor()
42 ->setMethods([
'getStatus',
'getItems'])
43 ->getMockForAbstractClass();
45 $this->orderItemMock = $this->getMockBuilder(\
Magento\Sales\Api\
Data\OrderItemInterface::class)
46 ->disableOriginalConstructor()
47 ->setMethods([
'getQtyToInvoice',
'getLockedDoInvoice'])
48 ->getMockForAbstractClass();
50 $this->model = new \Magento\Sales\Model\Order\Validation\CanInvoice();
60 $this->orderMock->expects($this->any())
63 $this->orderMock->expects($this->never())
65 $this->orderMock->expects($this->once())
67 ->willReturn(
'status');
69 [
__(
'An invoice cannot be created when an order has a status of %1',
'status')],
70 $this->model->validate($this->orderMock)
91 $this->orderMock->expects($this->any())
95 $this->orderMock->expects($this->once())
99 $this->assertNotEmpty(
100 $this->model->validate($this->orderMock)
111 public function testCanInvoice($qtyToInvoice, $itemLockedDoInvoice, $expectedResult)
113 $this->orderMock->expects($this->any())
117 $items = [$this->orderItemMock];
118 $this->orderMock->expects($this->once())
121 $this->orderItemMock->expects($this->any())
122 ->method(
'getQtyToInvoice')
123 ->willReturn($qtyToInvoice);
124 $this->orderItemMock->expects($this->any())
125 ->method(
'getLockedDoInvoice')
126 ->willReturn($itemLockedDoInvoice);
130 $this->model->validate($this->orderMock)
142 [0,
null, [
__(
'The order does not allow an invoice to be created.')]],
143 [-1,
null, [
__(
'The order does not allow an invoice to be created.')]],
144 [1,
true, [
__(
'The order does not allow an invoice to be created.')]],
canInvoiceWrongStateDataProvider()
testCanInvoice($qtyToInvoice, $itemLockedDoInvoice, $expectedResult)
testCanInvoiceWrongState($state)
const STATE_PAYMENT_REVIEW