diff --git a/app/code/Magento/Sales/Model/Order/InvoiceQuantityValidator.php b/app/code/Magento/Sales/Model/Order/InvoiceQuantityValidator.php index 51e98f8277b3b..a7c1008968926 100644 --- a/app/code/Magento/Sales/Model/Order/InvoiceQuantityValidator.php +++ b/app/code/Magento/Sales/Model/Order/InvoiceQuantityValidator.php @@ -10,7 +10,6 @@ use Magento\Sales\Api\Data\InvoiceItemInterface; use Magento\Sales\Api\Data\OrderInterface; use Magento\Sales\Api\OrderRepositoryInterface; -use Magento\Sales\Model\Order\Invoice\Validator\InvoiceValidatorRunner; use Magento\Sales\Model\ValidatorInterface; /** @@ -18,10 +17,6 @@ */ class InvoiceQuantityValidator implements ValidatorInterface { - /** - * @var InvoiceValidatorRunner - */ - private $invoiceValidatorRunner; /** * @var OrderRepositoryInterface */ @@ -29,11 +24,10 @@ class InvoiceQuantityValidator implements ValidatorInterface /** * InvoiceValidator constructor. - * @param InvoiceValidatorRunner $invoiceValidatorRunner + * @param OrderRepositoryInterface $orderRepository */ - public function __construct(InvoiceValidatorRunner $invoiceValidatorRunner, OrderRepositoryInterface $orderRepository) + public function __construct(OrderRepositoryInterface $orderRepository) { - $this->invoiceValidatorRunner = $invoiceValidatorRunner; $this->orderRepository = $orderRepository; } diff --git a/app/code/Magento/Sales/Model/Order/OrderValidatorInterface.php b/app/code/Magento/Sales/Model/Order/OrderValidatorInterface.php deleted file mode 100644 index 6ed3bacc05797..0000000000000 --- a/app/code/Magento/Sales/Model/Order/OrderValidatorInterface.php +++ /dev/null @@ -1,23 +0,0 @@ -objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->orderValidatorMock = $this->getMockBuilder(\Magento\Sales\Model\Order\OrderValidatorInterface::class) - ->disableOriginalConstructor() - ->setMethods(['canInvoice']) - ->getMockForAbstractClass(); - $this->orderMock = $this->getMockBuilder(\Magento\Sales\Api\Data\OrderInterface::class) ->disableOriginalConstructor() ->setMethods(['getStatus']) @@ -56,10 +51,13 @@ protected function setUp() ->disableOriginalConstructor() ->setMethods(['getTotalQty', 'getItems']) ->getMockForAbstractClass(); - + $this->orderRepositoryMock = $this->getMockBuilder( + OrderRepositoryInterface::class + )->disableOriginalConstructor()->getMockForAbstractClass(); + $this->orderRepositoryMock->expects($this->any())->method('get')->willReturn($this->orderMock); $this->model = $this->objectManager->getObject( \Magento\Sales\Model\Order\InvoiceQuantityValidator::class, - ['orderValidator' => $this->orderValidatorMock] + ['orderRepository' => $this->orderRepositoryMock] ); } @@ -75,39 +73,9 @@ public function testValidate() $this->orderMock->expects($this->once()) ->method('getItems') ->willReturn([$orderItemMock]); - $this->orderValidatorMock->expects($this->once()) - ->method('canInvoice') - ->with($this->orderMock) - ->willReturn(true); - $this->assertEquals( - $expectedResult, - $this->model->validate($this->invoiceMock, $this->orderMock) - ); - } - - public function testValidateCanNotInvoiceOrder() - { - $orderStatus = 'Test Status'; - $expectedResult = [__('An invoice cannot be created when an order has a status of %1.', $orderStatus)]; - $invoiceItemMock = $this->getInvoiceItemMock(1, 1); - $this->invoiceMock->expects($this->once()) - ->method('getItems') - ->willReturn([$invoiceItemMock]); - - $orderItemMock = $this->getOrderItemMock(1, 1, true); - $this->orderMock->expects($this->once()) - ->method('getItems') - ->willReturn([$orderItemMock]); - $this->orderMock->expects($this->once()) - ->method('getStatus') - ->willReturn($orderStatus); - $this->orderValidatorMock->expects($this->once()) - ->method('canInvoice') - ->with($this->orderMock) - ->willReturn(false); $this->assertEquals( $expectedResult, - $this->model->validate($this->invoiceMock, $this->orderMock) + $this->model->validate($this->invoiceMock) ); } @@ -125,13 +93,9 @@ public function testValidateInvoiceQtyBiggerThanOrder() $this->orderMock->expects($this->once()) ->method('getItems') ->willReturn([$orderItemMock]); - $this->orderValidatorMock->expects($this->once()) - ->method('canInvoice') - ->with($this->orderMock) - ->willReturn(true); $this->assertEquals( $expectedResult, - $this->model->validate($this->invoiceMock, $this->orderMock) + $this->model->validate($this->invoiceMock) ); } @@ -146,13 +110,9 @@ public function testValidateNoOrderItems() $this->orderMock->expects($this->once()) ->method('getItems') ->willReturn([]); - $this->orderValidatorMock->expects($this->once()) - ->method('canInvoice') - ->with($this->orderMock) - ->willReturn(true); $this->assertEquals( $expectedResult, - $this->model->validate($this->invoiceMock, $this->orderMock) + $this->model->validate($this->invoiceMock) ); } @@ -169,13 +129,9 @@ public function testValidateNoInvoiceItems() $this->orderMock->expects($this->once()) ->method('getItems') ->willReturn([$orderItemMock]); - $this->orderValidatorMock->expects($this->once()) - ->method('canInvoice') - ->with($this->orderMock) - ->willReturn(true); $this->assertEquals( $expectedResult, - $this->model->validate($this->invoiceMock, $this->orderMock) + $this->model->validate($this->invoiceMock) ); } diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/Invoice/Validator/InvoiceOrderTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/Validation/CanInvoiceTest.php similarity index 89% rename from app/code/Magento/Sales/Test/Unit/Model/Order/Invoice/Validator/InvoiceOrderTest.php rename to app/code/Magento/Sales/Test/Unit/Model/Order/Validation/CanInvoiceTest.php index 6942567ec143f..7d33050ad3aaa 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/Invoice/Validator/InvoiceOrderTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/Validation/CanInvoiceTest.php @@ -11,10 +11,10 @@ /** * Test for \Magento\Sales\Model\Order\OrderValidator class */ -class InvoiceOrderTest extends \PHPUnit_Framework_TestCase +class CanInvoiceTest extends \PHPUnit_Framework_TestCase { /** - * @var \Magento\Sales\Model\Order\OrderValidatorInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Sales\Model\Order\Validation\CanInvoice|\PHPUnit_Framework_MockObject_MockObject */ private $model; @@ -47,7 +47,7 @@ protected function setUp() ->setMethods(['getQtyToInvoice', 'getLockedDoInvoice']) ->getMockForAbstractClass(); - $this->model = new \Magento\Sales\Model\Order\Invoice\Validator\InvoiceOrder(); + $this->model = new \Magento\Sales\Model\Order\Validation\CanInvoice(); } /** @@ -62,8 +62,7 @@ public function testCanInvoiceWrongState($state) ->willReturn($state); $this->orderMock->expects($this->never()) ->method('getItems'); - $this->assertEquals( - false, + $this->assertNotEmpty( $this->model->validate($this->orderMock) ); } @@ -93,8 +92,7 @@ public function testCanInvoiceNoItems() ->method('getItems') ->willReturn([]); - $this->assertEquals( - false, + $this->assertNotEmpty( $this->model->validate($this->orderMock) ); } @@ -124,8 +122,7 @@ public function testCanInvoice($qtyToInvoice, $itemLockedDoInvoice, $expectedRes ->willReturn($itemLockedDoInvoice); $this->assertEquals( - $expectedResult, - $this->model->validate($this->orderMock) + $expectedResult, empty($this->model->validate($this->orderMock)) ); }