@@ -92,87 +92,9 @@ public function testGetOrderItemFromFactory()
92
92
$ this ->assertInstanceOf ('Magento\Sales\Model\Order\Item ' , $ result );
93
93
}
94
94
95
- /**
96
- * @expectedException \Magento\Framework\Exception\LocalizedException
97
- * @expectedExceptionMessage We found an invalid quantity to refund item "test_item_name".
98
- */
99
- public function testSetQtyDecimalException ()
100
- {
101
- $ qty = 100 ;
102
- $ orderItemQty = 10 ;
103
- $ name = 'test_item_name ' ;
104
-
105
- $ orderItemMock = $ this ->getMockBuilder ('Magento\Sales\Model\Order\Item ' )
106
- ->disableOriginalConstructor ()
107
- ->getMock ();
108
- $ orderItemMock ->expects ($ this ->once ())
109
- ->method ('getIsQtyDecimal ' )
110
- ->willReturn (true );
111
- $ orderItemMock ->expects ($ this ->once ())
112
- ->method ('getQtyToRefund ' )
113
- ->willReturn ($ orderItemQty );
114
- $ orderItemMock ->expects ($ this ->atLeastOnce ())
115
- ->method ('load ' )
116
- ->willReturnSelf ();
117
- $ this ->orderItemFactoryMock ->expects ($ this ->atLeastOnce ())
118
- ->method ('create ' )
119
- ->willReturn ($ orderItemMock );
120
- $ this ->item ->setData (CreditmemoItemInterface::NAME , $ name );
121
- $ this ->item ->setOrderItem ($ orderItemMock );
122
- $ this ->item ->setQty ($ qty );
123
- }
124
-
125
- /**
126
- * @expectedException \Magento\Framework\Exception\LocalizedException
127
- * @expectedExceptionMessage We found an invalid quantity to refund item "test_item_name2".
128
- */
129
- public function testSetQtyNumericException ()
130
- {
131
- $ qty = 100 ;
132
- $ orderItemQty = 10 ;
133
- $ name = 'test_item_name2 ' ;
134
-
135
- $ orderItemMock = $ this ->getMockBuilder ('Magento\Sales\Model\Order\Item ' )
136
- ->disableOriginalConstructor ()
137
- ->getMock ();
138
- $ orderItemMock ->expects ($ this ->once ())
139
- ->method ('getIsQtyDecimal ' )
140
- ->willReturn (false );
141
- $ orderItemMock ->expects ($ this ->once ())
142
- ->method ('getQtyToRefund ' )
143
- ->willReturn ($ orderItemQty );
144
- $ orderItemMock ->expects ($ this ->atLeastOnce ())
145
- ->method ('load ' )
146
- ->willReturnSelf ();
147
- $ this ->orderItemFactoryMock ->expects ($ this ->atLeastOnce ())
148
- ->method ('create ' )
149
- ->willReturn ($ orderItemMock );
150
- $ this ->item ->setData (CreditmemoItemInterface::NAME , $ name );
151
- $ this ->item ->setOrderItem ($ orderItemMock );
152
- $ this ->item ->setQty ($ qty );
153
- }
154
-
155
95
public function testSetQty ()
156
96
{
157
97
$ qty = 10 ;
158
- $ orderItemQty = 100 ;
159
-
160
- $ orderItemMock = $ this ->getMockBuilder ('Magento\Sales\Model\Order\Item ' )
161
- ->disableOriginalConstructor ()
162
- ->getMock ();
163
- $ orderItemMock ->expects ($ this ->once ())
164
- ->method ('getIsQtyDecimal ' )
165
- ->willReturn (false );
166
- $ orderItemMock ->expects ($ this ->once ())
167
- ->method ('getQtyToRefund ' )
168
- ->willReturn ($ orderItemQty );
169
- $ orderItemMock ->expects ($ this ->atLeastOnce ())
170
- ->method ('load ' )
171
- ->willReturnSelf ();
172
- $ this ->orderItemFactoryMock ->expects ($ this ->atLeastOnce ())
173
- ->method ('create ' )
174
- ->willReturn ($ orderItemMock );
175
- $ this ->item ->setOrderItem ($ orderItemMock );
176
98
$ this ->item ->setQty ($ qty );
177
99
$ this ->assertEquals ($ qty , $ this ->item ->getQty ());
178
100
}
@@ -209,19 +131,39 @@ public function testRegister()
209
131
$ orderItemMock ->expects ($ this ->once ())
210
132
->method ('getBaseDiscountRefunded ' )
211
133
->willReturn (1 );
212
- $ data = [
213
- 'qty ' => 1 ,
214
- 'tax_amount ' => 1 ,
215
- 'base_tax_amount ' => 1 ,
216
- 'discount_tax_compensation_amount ' => 1 ,
217
- 'base_discount_tax_compensation_amount ' => 1 ,
218
- 'row_total ' => 1 ,
219
- 'base_row_total ' => 1 ,
220
- 'discount_amount ' => 1 ,
221
- 'base_discount_amount ' => 1
222
- ];
134
+ $ orderItemMock ->expects ($ this ->once ())
135
+ ->method ('getQtyToRefund ' )
136
+ ->willReturn (1 );
137
+ $ this ->item ->setQty (1 );
138
+ $ this ->item ->setTaxAmount (1 );
139
+ $ this ->item ->setBaseTaxAmount (1 );
140
+ $ this ->item ->setDiscountTaxCompensationAmount (1 );
141
+ $ this ->item ->setBaseDiscountTaxCompensationAmount (1 );
142
+ $ this ->item ->setRowTotal (1 );
143
+ $ this ->item ->setBaseRowTotal (1 );
144
+ $ this ->item ->setDiscountAmount (1 );
145
+ $ this ->item ->setBaseDiscountAmount (1 );
146
+ $ this ->item ->setOrderItem ($ orderItemMock );
147
+ $ result = $ this ->item ->register ();
148
+ $ this ->assertInstanceOf ('Magento\Sales\Model\Order\Creditmemo\Item ' , $ result );
149
+ }
150
+
151
+ /**
152
+ * @expectedException \Magento\Framework\Exception\LocalizedException
153
+ * @expectedExceptionMessage We found an invalid quantity to refund item "test".
154
+ */
155
+ public function testRegisterWithException ()
156
+ {
157
+ $ orderItemMock = $ this ->getMockBuilder ('Magento\Sales\Model\Order\Item ' )
158
+ ->disableOriginalConstructor ()
159
+ ->setMethods (['getQtyRefunded ' ])
160
+ ->getMock ();
161
+ $ orderItemMock ->expects ($ this ->once ())
162
+ ->method ('getQtyRefunded ' )
163
+ ->willReturn (1 );
164
+ $ this ->item ->setQty (2 );
223
165
$ this ->item ->setOrderItem ($ orderItemMock );
224
- $ this ->item ->setData ( $ data );
166
+ $ this ->item ->setName ( ' test ' );
225
167
$ result = $ this ->item ->register ();
226
168
$ this ->assertInstanceOf ('Magento\Sales\Model\Order\Creditmemo\Item ' , $ result );
227
169
}
@@ -230,19 +172,6 @@ public function testCancel()
230
172
{
231
173
$ orderItemMock = $ this ->getMockBuilder ('Magento\Sales\Model\Order\Item ' )
232
174
->disableOriginalConstructor ()
233
- ->setMethods (
234
- [
235
- 'setQtyRefunded ' ,
236
- 'getQtyRefunded ' ,
237
- 'getTaxRefunded ' ,
238
- 'getBaseTaxAmount ' ,
239
- 'getQtyOrdered ' ,
240
- 'setTaxRefunded ' ,
241
- 'setDiscountTaxCompensationRefunded ' ,
242
- 'getDiscountTaxCompensationRefunded ' ,
243
- 'getDiscountTaxCompensationAmount '
244
- ]
245
- )
246
175
->getMock ();
247
176
$ orderItemMock ->expects ($ this ->once ())
248
177
->method ('getQtyRefunded ' )
@@ -272,8 +201,11 @@ public function testCancel()
272
201
$ orderItemMock ->expects ($ this ->once ())
273
202
->method ('getDiscountTaxCompensationAmount ' )
274
203
->willReturn (10 );
204
+ $ orderItemMock ->expects ($ this ->once ())
205
+ ->method ('getQtyToRefund ' )
206
+ ->willReturn (1 );
275
207
276
- $ this ->item ->setData ( ' qty ' , 1 );
208
+ $ this ->item ->setQty ( 1 );
277
209
$ this ->item ->setOrderItem ($ orderItemMock );
278
210
$ result = $ this ->item ->cancel ();
279
211
$ this ->assertInstanceOf ('Magento\Sales\Model\Order\Creditmemo\Item ' , $ result );
@@ -342,7 +274,7 @@ function ($arg) {
342
274
->method ('getQtyToRefund ' )
343
275
->willReturn ($ qtyAvailable );
344
276
345
- $ this ->item ->setData ( ' qty ' , $ qty );
277
+ $ this ->item ->setQty ( $ qty );
346
278
$ this ->item ->setCreditmemo ($ creditmemoMock );
347
279
$ this ->item ->setOrderItem ($ orderItemMock );
348
280
$ result = $ this ->item ->calcRowTotal ();
0 commit comments