/** * Test validateCartCouponMinimumPrice. * * @covers validateCartCouponMinimumPrice * @dataProvider dataValidateCartCouponMinimumPrice */ public function testValidateCartCouponMinimumPrice($minimumPurchaseAmount, $minimumPurchaseCurrencyCode, $productMoneyAmount, $productMoneyCurrencyCode, $moneyIsConverted, $isLess, $throwException) { $currencyConverter = $this->prophesize('Elcodi\\Component\\Currency\\Services\\CurrencyConverter'); $cart = $this->prophesize('Elcodi\\Component\\Cart\\Entity\\Interfaces\\CartInterface'); $coupon = $this->prophesize('Elcodi\\Component\\Coupon\\Entity\\Interfaces\\CouponInterface'); $minimumPurchaseCurrency = $this->prophesize('Elcodi\\Component\\Currency\\Entity\\Interfaces\\CurrencyInterface')->reveal(); $minimumPurchase = $this->prophesize('Elcodi\\Component\\Currency\\Entity\\Interfaces\\MoneyInterface'); $minimumPurchase->getAmount()->willReturn($minimumPurchaseAmount); $minimumPurchase->getCurrency()->willReturn($minimumPurchaseCurrency); $productMoneyCurrency = $minimumPurchaseCurrencyCode === $productMoneyCurrencyCode ? $minimumPurchaseCurrency : $this->prophesize('Elcodi\\Component\\Currency\\Entity\\Interfaces\\CurrencyInterface')->reveal(); $productMoney = $this->prophesize('Elcodi\\Component\\Currency\\Entity\\Interfaces\\MoneyInterface'); $productMoney->getAmount()->willReturn($productMoneyAmount); $productMoney->getCurrency()->willReturn($productMoneyCurrency); $productMoney->isLessThan(Argument::any())->willReturn($isLess); $currencyConverterConvertMoney = $currencyConverter->convertMoney(Argument::any(), Argument::any())->willReturn($this->prophesize('Elcodi\\Component\\Currency\\Entity\\Interfaces\\MoneyInterface')->reveal()); if ($moneyIsConverted) { $currencyConverterConvertMoney->shouldBeCalled(); } else { $currencyConverterConvertMoney->shouldNotBeCalled(); } $coupon->getMinimumPurchase()->willReturn($minimumPurchase->reveal()); $cart->getProductAmount()->willReturn($productMoney->reveal()); try { $cartCouponMinimumPriceValidator = new CartCouponMinimumPriceValidator($currencyConverter->reveal()); $cartCouponMinimumPriceValidator->validateCartCouponMinimumPrice($cart->reveal(), $coupon->reveal()); } catch (CouponBelowMinimumPurchaseException $e) { if (!$throwException) { throw $e; } } }
/** * Check if cart meets minimum price requirements for a coupon * * @param CartCouponOnCheckEvent $event Event */ public function validateCartCouponMinimumPrice(CartCouponOnCheckEvent $event) { $this->cartCouponMinimumPriceValidator->validateCartCouponMinimumPrice($event->getCart(), $event->getCoupon()); }