Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CreateQuantityValidatorTest.php
Go to the documentation of this file.
1 <?php
7 
13 
17 class CreateQuantityValidatorTest extends \PHPUnit\Framework\TestCase
18 {
22  private $orderItemRepositoryMock;
23 
27  private $orderItemMock;
28 
32  private $createQuantityValidator;
33 
37  private $contexMock;
38 
42  private $entity;
43 
44  protected function setUp()
45  {
46  $this->orderItemRepositoryMock = $this->getMockBuilder(OrderItemRepositoryInterface::class)
47  ->disableOriginalConstructor()
48  ->setMethods(['get'])
49  ->getMockForAbstractClass();
50 
51  $this->orderItemMock = $this->getMockBuilder(Item::class)
52  ->disableOriginalConstructor()
53  ->getMockForAbstractClass();
54 
55  $this->entity = $this->getMockBuilder(\stdClass::class)
56  ->disableOriginalConstructor()
57  ->setMethods(['getOrderItemId', 'getQty'])
58  ->getMock();
59  }
60 
64  public function testValidateCreditMemoProductItems($orderItemId, $expectedResult, $withContext = false)
65  {
66  if ($orderItemId) {
67  $this->entity->expects($this->once())
68  ->method('getOrderItemId')
69  ->willReturn($orderItemId);
70 
71  $this->orderItemRepositoryMock->expects($this->once())
72  ->method('get')
73  ->with($orderItemId)
74  ->willReturn($this->orderItemMock);
75  } else {
76  $this->entity->expects($this->once())
77  ->method('getOrderItemId')
78  ->willThrowException(new NoSuchEntityException());
79  }
80 
81  $this->contexMock = null;
82  if ($withContext) {
83  $this->contexMock = $this->getMockBuilder(OrderInterface::class)
84  ->disableOriginalConstructor()
85  ->getMockForAbstractClass();
86 
87  $this->entity->expects($this->once())
88  ->method('getQty')
89  ->willReturn(11);
90  }
91 
92  $this->createQuantityValidator = new CreationQuantityValidator(
93  $this->orderItemRepositoryMock,
94  $this->contexMock
95  );
96 
97  $this->assertEquals($expectedResult, $this->createQuantityValidator->validate($this->entity));
98  }
99 
103  public function dataProvider()
104  {
105  return [
106  'testValidateCreditMemoProductItems' => [
107  1,
108  [__('The creditmemo contains product item that is not part of the original order.')],
109  ],
110  'testValidateWithException' => [
111  null,
112  [__('The creditmemo contains product item that is not part of the original order.')]
113  ],
114  'testValidateWithContext' => [
115  1,
116  [__('The quantity to refund must not be greater than the unrefunded quantity.')],
117  true
118  ],
119  ];
120  }
121 }
__()
Definition: __.php:13