/** * @return void */ public function testCalculateWhenVoucherDiscountIsUsedButValidationFailsShouldSkipDiscount() { $queryContainerMock = $this->createDiscountQueryContainerMock(); $discounts[] = $this->createDiscountEntity(100, 123); $discountQueryMock = $this->createDiscountQueryMock(); $discountQueryMock->method('find')->willReturn($discounts); $queryContainerMock->expects($this->once())->method('queryActiveCartRules')->willReturn($discountQueryMock); $decisionRuleSpecificationMock = $this->createDecisionRuleSpecificationMock(); $decisionRuleSpecificationMock->method('isSatisfiedBy')->willReturn(true); $specificationBuilderMock = $this->createSpecificationBuilderMock(); $specificationBuilderMock->method('buildFromQueryString')->willReturn($decisionRuleSpecificationMock); $calculatorMock = $this->createCalculatorMock(); $collectedDiscounts = []; $collectedDiscountTransfer = new CollectedDiscountTransfer(); $discountTransfer = new DiscountTransfer(); $discountTransfer->setAmount(250); $discountTransfer->setVoucherCode(123); $collectedDiscountTransfer->setDiscount($discountTransfer); $collectedDiscounts[] = $collectedDiscountTransfer; $calculatorMock->method('calculate')->willReturn($collectedDiscounts); $voucherValidatorMock = $this->createVoucherValidatorMock(); $voucherValidatorMock->method('isUsable')->willReturn(false); $discount = $this->createDiscount($queryContainerMock, null, $specificationBuilderMock, $voucherValidatorMock); $quoteTransfer = $this->createQuoteTransfer(); $updatedQuoteTransfer = $discount->calculate($quoteTransfer); $this->assertCount(0, $updatedQuoteTransfer->getVoucherDiscounts()); $this->assertCount(0, $updatedQuoteTransfer->getCartRuleDiscounts()); }
/** * @return void */ public function testWhenMultipleVouchersFromSamePoolUsedShouldUseOnlyOnce() { $discountEntity = $this->createDiscountFixtures('', 'sku = "*"', DiscountConstants::TYPE_VOUCHER); $code1 = 'code1'; $code2 = 'code2'; $code3 = 'code3'; $this->createVoucherCode($code1, $discountEntity); $this->createVoucherCode($code2, $discountEntity); $this->createVoucherCode($code3, $discountEntity); $quoteTransfer = $this->createQuoteTransfer(); $discountTransfer = new DiscountTransfer(); $discountTransfer->setVoucherCode($code1); $quoteTransfer->addVoucherDiscount($discountTransfer); $discountTransfer = new DiscountTransfer(); $discountTransfer->setVoucherCode($code2); $quoteTransfer->addVoucherDiscount($discountTransfer); $discountFacade = new DiscountFacade(); $quoteTransfer = $discountFacade->calculateDiscounts($quoteTransfer); $discountTransfer = $quoteTransfer->getVoucherDiscounts()[0]; $this->assertCount(1, $quoteTransfer->getVoucherDiscounts()); $this->assertEquals($code1, $discountTransfer->getVoucherCode()); }