13
13
use PHPUnit \Framework \MockObject \MockObject ;
14
14
15
15
/**
16
- * Class ValidatorTest
16
+ * Tests for Magento\SalesRule\Model\Validator
17
17
* @@SuppressWarnings(PHPMD.CouplingBetweenObjects)
18
18
*/
19
19
class ValidatorTest extends \PHPUnit \Framework \TestCase
@@ -346,11 +346,14 @@ public function testInitTotalsCanApplyDiscount()
346
346
'getDiscountCalculationPrice ' ,
347
347
'getBaseDiscountCalculationPrice ' ,
348
348
'getCalculationPrice ' ,
349
- 'getParentItemId '
349
+ 'getParentItemId ' ,
350
+ 'getParentItem '
350
351
]
351
352
);
352
353
$ item2 = clone $ item1 ;
353
- $ items = [$ item1 , $ item2 ];
354
+ $ item3 = clone $ item1 ;
355
+ $ item4 = clone $ item1 ;
356
+ $ items = [$ item1 , $ item2 , $ item3 , $ item4 ];
354
357
355
358
$ rule ->expects ($ this ->any ())
356
359
->method ('getSimpleAction ' )
@@ -367,12 +370,22 @@ public function testInitTotalsCanApplyDiscount()
367
370
$ validator ->expects ($ this ->at (0 ))->method ('isValid ' )->with ($ item1 )->willReturn (false );
368
371
$ validator ->expects ($ this ->at (1 ))->method ('isValid ' )->with ($ item2 )->willReturn (true );
369
372
370
- $ item1 ->expects ($ this ->any ())->method ('getParentItemId ' )->willReturn (false );
373
+ $ item1 ->expects ($ this ->any ())->method ('getParentItemId ' )->willReturn (null );
374
+ $ item1 ->expects ($ this ->any ())->method ('getParentItem ' )->willReturn (null );
371
375
$ item1 ->expects ($ this ->never ())->method ('getDiscountCalculationPrice ' );
372
376
$ item1 ->expects ($ this ->never ())->method ('getBaseDiscountCalculationPrice ' );
373
- $ item2 ->expects ($ this ->any ())->method ('getParentItemId ' )->willReturn (false );
377
+ $ item2 ->expects ($ this ->any ())->method ('getParentItemId ' )->willReturn (null );
378
+ $ item2 ->expects ($ this ->any ())->method ('getParentItem ' )->willReturn (null );
374
379
$ item2 ->expects ($ this ->any ())->method ('getDiscountCalculationPrice ' )->willReturn (50 );
375
380
$ item2 ->expects ($ this ->once ())->method ('getBaseDiscountCalculationPrice ' )->willReturn (50 );
381
+ $ item3 ->expects ($ this ->any ())->method ('getParentItemId ' )->willReturn (null );
382
+ $ item3 ->expects ($ this ->any ())->method ('getParentItem ' )->willReturn ($ item1 );
383
+ $ item3 ->expects ($ this ->never ())->method ('getDiscountCalculationPrice ' );
384
+ $ item3 ->expects ($ this ->never ())->method ('getBaseDiscountCalculationPrice ' );
385
+ $ item4 ->expects ($ this ->any ())->method ('getParentItemId ' )->willReturn (12345 );
386
+ $ item4 ->expects ($ this ->any ())->method ('getParentItem ' )->willReturn (null );
387
+ $ item4 ->expects ($ this ->never ())->method ('getDiscountCalculationPrice ' );
388
+ $ item4 ->expects ($ this ->never ())->method ('getBaseDiscountCalculationPrice ' );
376
389
$ this ->utility ->expects ($ this ->once ())->method ('getItemQty ' )->willReturn (1 );
377
390
$ this ->utility ->expects ($ this ->any ())->method ('canProcessRule ' )->willReturn (true );
378
391
0 commit comments