|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright 2024 Adobe |
| 4 | + * All Rights Reserved. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\SalesRule\Test\Unit\Helper; |
| 9 | + |
| 10 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
| 11 | +use Magento\Framework\Pricing\PriceCurrencyInterface; |
| 12 | +use Magento\Quote\Model\Cart\ShippingMethodConverter; |
| 13 | +use Magento\SalesRule\Helper\CartFixedDiscount; |
| 14 | +use Magento\SalesRule\Model\DeltaPriceRound; |
| 15 | +use PHPUnit\Framework\TestCase; |
| 16 | +use PHPUnit\Framework\MockObject\MockObject; |
| 17 | + |
| 18 | +class CartFixedDiscountTest extends TestCase |
| 19 | +{ |
| 20 | + /** |
| 21 | + * @var DeltaPriceRound|MockObject |
| 22 | + */ |
| 23 | + private DeltaPriceRound $deltaPriceRound; |
| 24 | + |
| 25 | + /** |
| 26 | + * @var PriceCurrencyInterface|MockObject |
| 27 | + */ |
| 28 | + private PriceCurrencyInterface $priceCurrency; |
| 29 | + |
| 30 | + /** |
| 31 | + * @var ShippingMethodConverter|MockObject |
| 32 | + */ |
| 33 | + private ShippingMethodConverter $shippingMethodConverter; |
| 34 | + |
| 35 | + /** |
| 36 | + * @var ScopeConfigInterface|MockObject |
| 37 | + */ |
| 38 | + private ScopeConfigInterface $scopeConfig; |
| 39 | + |
| 40 | + /** |
| 41 | + * @inhertidoc |
| 42 | + */ |
| 43 | + protected function setUp(): void |
| 44 | + { |
| 45 | + parent::setUp(); |
| 46 | + |
| 47 | + $this->deltaPriceRound = $this->createMock(DeltaPriceRound::class); |
| 48 | + $this->priceCurrency = $this->createMock(PriceCurrencyInterface::class); |
| 49 | + $this->shippingMethodConverter = $this->createMock(ShippingMethodConverter::class); |
| 50 | + $this->scopeConfig = $this->createMock(ScopeConfigInterface::class); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * @return void |
| 55 | + */ |
| 56 | + public function testGetDiscountedAmountProportionally(): void |
| 57 | + { |
| 58 | + $ruleDiscount = 5; |
| 59 | + $qty = 2.0; |
| 60 | + $baseItemPrice = 10.0; |
| 61 | + $baseItemDiscountAmount = 0.0; |
| 62 | + $baseRuleTotalsDiscount = 10; |
| 63 | + $discountType = 'fixed'; |
| 64 | + $expected = 5.0; |
| 65 | + |
| 66 | + $cartFixedDiscount = new CartFixedDiscount( |
| 67 | + $this->deltaPriceRound, |
| 68 | + $this->priceCurrency, |
| 69 | + $this->shippingMethodConverter, |
| 70 | + $this->scopeConfig |
| 71 | + ); |
| 72 | + $this->deltaPriceRound->expects($this->once()) |
| 73 | + ->method('round') |
| 74 | + ->with(5, $discountType) |
| 75 | + ->willReturn($expected); |
| 76 | + $this->assertSame( |
| 77 | + $expected, |
| 78 | + $cartFixedDiscount->getDiscountedAmountProportionally( |
| 79 | + $ruleDiscount, |
| 80 | + $qty, |
| 81 | + $baseItemPrice, |
| 82 | + $baseItemDiscountAmount, |
| 83 | + $baseRuleTotalsDiscount, |
| 84 | + $discountType |
| 85 | + ) |
| 86 | + ); |
| 87 | + } |
| 88 | +} |
0 commit comments