Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CanShipTest.php
Go to the documentation of this file.
1 <?php
8 
10 
14 class CanShipTest extends \PHPUnit\Framework\TestCase
15 {
19  private $model;
20 
24  private $objectManager;
25 
29  private $orderMock;
30 
34  private $orderItemMock;
35 
36  protected function setUp()
37  {
38  $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
39 
40  $this->orderMock = $this->getMockBuilder(\Magento\Sales\Api\Data\OrderInterface::class)
41  ->disableOriginalConstructor()
42  ->setMethods(['getStatus', 'getItems'])
43  ->getMockForAbstractClass();
44 
45  $this->orderItemMock = $this->getMockBuilder(\Magento\Sales\Api\Data\OrderItemInterface::class)
46  ->disableOriginalConstructor()
47  ->setMethods(['getQtyToShip', 'getLockedDoShip'])
48  ->getMockForAbstractClass();
49 
50  $this->model = new \Magento\Sales\Model\Order\Validation\CanShip();
51  }
52 
58  public function testCanShipWrongState($state)
59  {
60  $this->orderMock->expects($this->any())
61  ->method('getState')
62  ->willReturn($state);
63  $this->orderMock->expects($this->once())
64  ->method('getStatus')
65  ->willReturn('status');
66  $this->orderMock->expects($this->never())
67  ->method('getItems');
68  $this->assertEquals(
69  [__('A shipment cannot be created when an order has a status of %1', 'status')],
70  $this->model->validate($this->orderMock)
71  );
72  }
73 
79  {
80  return [
84  ];
85  }
86 
87  public function testCanShipNoItems()
88  {
89  $this->orderMock->expects($this->any())
90  ->method('getState')
91  ->willReturn(Order::STATE_PROCESSING);
92 
93  $this->orderMock->expects($this->once())
94  ->method('getItems')
95  ->willReturn([]);
96 
97  $this->assertNotEmpty(
98  $this->model->validate($this->orderMock)
99  );
100  }
101 
109  public function testCanShip($qtyToShipment, $itemLockedDoShipment, $expectedResult)
110  {
111  $this->orderMock->expects($this->any())
112  ->method('getState')
113  ->willReturn(Order::STATE_PROCESSING);
114 
115  $items = [$this->orderItemMock];
116  $this->orderMock->expects($this->once())
117  ->method('getItems')
118  ->willReturn($items);
119  $this->orderItemMock->expects($this->any())
120  ->method('getQtyToShip')
121  ->willReturn($qtyToShipment);
122  $this->orderItemMock->expects($this->any())
123  ->method('getLockedDoShip')
124  ->willReturn($itemLockedDoShipment);
125 
126  $this->assertEquals(
127  $expectedResult,
128  $this->model->validate($this->orderMock)
129  );
130  }
131 
137  public function canShipDataProvider()
138  {
139  return [
140  [0, null, [__('The order does not allow a shipment to be created.')]],
141  [-1, null, [__('The order does not allow a shipment to be created.')]],
142  [1, true, [__('The order does not allow a shipment to be created.')]],
143  [0.5, false, []],
144  ];
145  }
146 }
__()
Definition: __.php:13
testCanShip($qtyToShipment, $itemLockedDoShipment, $expectedResult)
$items