From febf0c332fb634df7625fe261200411880401cf7 Mon Sep 17 00:00:00 2001 From: Kamil Kokot Date: Tue, 18 May 2021 19:16:27 +0100 Subject: [PATCH] Remove support for Sylius 1.8 --- .github/workflows/build.yml | 2 +- composer.json | 2 +- .../ShipmentLineItemsConverterSpec.php | 4 +- .../OrderTaxesProcessorSpec.php | 143 ------- .../ShippingChargesProcessorSpec.php | 90 ---- ...tageDiscountPromotionActionCommandSpec.php | 172 -------- spec/Provider/RemainingTotalProviderSpec.php | 4 +- spec/Provider/TaxRateProviderSpec.php | 2 +- .../OrderItemUnitsTaxesApplicatorSpec.php | 208 ---------- .../OrderItemsTaxesApplicatorSpec.php | 202 --------- .../OrderShipmentTaxesApplicatorSpec.php | 390 ------------------ src/Converter/ShipmentLineItemsConverter.php | 4 +- src/Entity/AdjustmentInterface.php | 34 -- src/Entity/AdjustmentTrait.php | 70 ---- src/Entity/ShipmentInterface.php | 33 -- src/Entity/ShipmentTrait.php | 115 ------ src/Migrations/Version20201130071338.php | 57 --- src/Migrations/Version20201204071301.php | 51 --- src/Migrations/Version20201208105207.php | 109 ----- src/OrderProcessor/OrderTaxesProcessor.php | 110 ----- .../ShippingChargesProcessor.php | 80 ---- ...rcentageDiscountPromotionActionCommand.php | 131 ------ src/Provider/RemainingTotalProvider.php | 2 +- src/Provider/TaxRateProvider.php | 3 +- src/Resources/config/services.xml | 37 -- .../OrderItemUnitsTaxesApplicator.php | 101 ----- .../OrderItemsTaxesApplicator.php | 117 ------ .../OrderShipmentTaxesApplicator.php | 124 ------ tests/Application/Kernel.php | 34 +- tests/Application/config/bundles.php | 2 + .../Application/config/packages/_sylius.yaml | 12 - .../1.9 => }/packages/dev/jms_serializer.yaml | 0 .../Application/config/packages/doctrine.yaml | 6 - .../1.9 => }/packages/jms_serializer.yaml | 0 .../packages/prod/jms_serializer.yaml | 0 .../Application/config/sylius/1.8/bundles.php | 6 - .../1.8/packages/dev/jms_serializer.yaml | 7 - .../config/sylius/1.8/packages/framework.yaml | 2 - .../sylius/1.8/packages/jms_serializer.yaml | 4 - .../1.8/packages/prod/jms_serializer.yaml | 6 - .../config/sylius/1.8/routes/dev/twig.yaml | 3 - .../Application/config/sylius/1.9/bundles.php | 6 - tests/Application/src/Entity/Adjustment.php | 28 -- tests/Application/src/Entity/Shipment.php | 37 -- .../Behat/Context/Setup/RefundingContext.php | 2 +- 45 files changed, 41 insertions(+), 2511 deletions(-) delete mode 100644 spec/OrderProcessor/OrderTaxesProcessorSpec.php delete mode 100644 spec/OrderProcessor/ShippingChargesProcessorSpec.php delete mode 100644 spec/PromotionAction/ShippingPercentageDiscountPromotionActionCommandSpec.php delete mode 100644 spec/TaxesApplicator/OrderItemUnitsTaxesApplicatorSpec.php delete mode 100644 spec/TaxesApplicator/OrderItemsTaxesApplicatorSpec.php delete mode 100644 spec/TaxesApplicator/OrderShipmentTaxesApplicatorSpec.php delete mode 100644 src/Entity/AdjustmentInterface.php delete mode 100644 src/Entity/AdjustmentTrait.php delete mode 100644 src/Entity/ShipmentInterface.php delete mode 100644 src/Entity/ShipmentTrait.php delete mode 100644 src/Migrations/Version20201130071338.php delete mode 100644 src/Migrations/Version20201204071301.php delete mode 100644 src/Migrations/Version20201208105207.php delete mode 100644 src/OrderProcessor/OrderTaxesProcessor.php delete mode 100644 src/OrderProcessor/ShippingChargesProcessor.php delete mode 100644 src/PromotionAction/ShippingPercentageDiscountPromotionActionCommand.php delete mode 100644 src/TaxesApplicator/OrderItemUnitsTaxesApplicator.php delete mode 100644 src/TaxesApplicator/OrderItemsTaxesApplicator.php delete mode 100644 src/TaxesApplicator/OrderShipmentTaxesApplicator.php rename tests/Application/config/{sylius/1.9 => }/packages/dev/jms_serializer.yaml (100%) rename tests/Application/config/{sylius/1.9 => }/packages/jms_serializer.yaml (100%) rename tests/Application/config/{sylius/1.9 => }/packages/prod/jms_serializer.yaml (100%) delete mode 100644 tests/Application/config/sylius/1.8/bundles.php delete mode 100644 tests/Application/config/sylius/1.8/packages/dev/jms_serializer.yaml delete mode 100644 tests/Application/config/sylius/1.8/packages/framework.yaml delete mode 100644 tests/Application/config/sylius/1.8/packages/jms_serializer.yaml delete mode 100644 tests/Application/config/sylius/1.8/packages/prod/jms_serializer.yaml delete mode 100644 tests/Application/config/sylius/1.8/routes/dev/twig.yaml delete mode 100644 tests/Application/config/sylius/1.9/bundles.php delete mode 100644 tests/Application/src/Entity/Adjustment.php delete mode 100644 tests/Application/src/Entity/Shipment.php diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dc16dd05..aeb42e54 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,7 +20,7 @@ jobs: matrix: php: [7.4, 7.3] symfony: [^4.4, ^5.2] - sylius: [~1.8.0, ~1.9.0] + sylius: [~1.9.0] node: [10.x] mysql: [5.7, 8.0] diff --git a/composer.json b/composer.json index 789b088d..736d716f 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "knplabs/knp-snappy-bundle": "^1.7", "myclabs/php-enum": "^1.7", "sylius/resource-bundle": "^1.6", - "sylius/sylius": "^1.8", + "sylius/sylius": "^1.9", "symfony/messenger": "^4.4 || ^5.2" }, "require-dev": { diff --git a/spec/Converter/ShipmentLineItemsConverterSpec.php b/spec/Converter/ShipmentLineItemsConverterSpec.php index 73fe1dc3..d7aec2f7 100644 --- a/spec/Converter/ShipmentLineItemsConverterSpec.php +++ b/spec/Converter/ShipmentLineItemsConverterSpec.php @@ -6,11 +6,11 @@ use Doctrine\Common\Collections\ArrayCollection; use PhpSpec\ObjectBehavior; +use Sylius\Component\Core\Model\AdjustmentInterface; +use Sylius\Component\Core\Model\ShipmentInterface; use Sylius\Component\Resource\Repository\RepositoryInterface; use Sylius\RefundPlugin\Converter\LineItemsConverterInterface; -use Sylius\RefundPlugin\Entity\AdjustmentInterface; use Sylius\RefundPlugin\Entity\LineItem; -use Sylius\RefundPlugin\Entity\ShipmentInterface; use Sylius\RefundPlugin\Exception\MoreThanOneTaxAdjustment; use Sylius\RefundPlugin\Model\ShipmentRefund; use Sylius\RefundPlugin\Provider\TaxRateProviderInterface; diff --git a/spec/OrderProcessor/OrderTaxesProcessorSpec.php b/spec/OrderProcessor/OrderTaxesProcessorSpec.php deleted file mode 100644 index 4fc93bb6..00000000 --- a/spec/OrderProcessor/OrderTaxesProcessorSpec.php +++ /dev/null @@ -1,143 +0,0 @@ -beConstructedWith($defaultTaxZoneProvider, $zoneMatcher, $strategyRegistry); - } - - function it_is_an_order_processor(): void - { - $this->shouldImplement(OrderProcessorInterface::class); - } - - function it_processes_taxes_using_a_supported_tax_calculation_strategy( - ZoneMatcherInterface $zoneMatcher, - PrioritizedServiceRegistryInterface $strategyRegistry, - OrderInterface $order, - OrderItemInterface $orderItem, - ShipmentInterface $shipment, - AddressInterface $address, - ZoneInterface $zone, - TaxCalculationStrategyInterface $strategyOne, - TaxCalculationStrategyInterface $strategyTwo - ): void { - $order->getItems()->willReturn(new ArrayCollection([$orderItem->getWrappedObject()])); - $order->getShipments()->willReturn(new ArrayCollection([$shipment->getWrappedObject()])); - $order->isEmpty()->willReturn(false); - $order->getBillingAddress()->willReturn($address); - - $order->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT)->shouldBeCalled(); - $orderItem->removeAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT)->shouldBeCalled(); - $shipment->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT)->shouldBeCalled(); - - $strategyRegistry->all()->willReturn([$strategyOne, $strategyTwo]); - $zoneMatcher->match($address, Scope::TAX)->willReturn($zone); - - $strategyOne->supports($order, $zone)->willReturn(false); - $strategyOne->applyTaxes($order, $zone)->shouldNotBeCalled(); - - $strategyTwo->supports($order, $zone)->willReturn(true); - $strategyTwo->applyTaxes($order, $zone)->shouldBeCalled(); - - $this->process($order); - } - - function it_throws_an_exception_if_there_are_no_supported_tax_calculation_strategies( - ZoneMatcherInterface $zoneMatcher, - PrioritizedServiceRegistryInterface $strategyRegistry, - OrderInterface $order, - OrderItemInterface $orderItem, - AddressInterface $address, - ZoneInterface $zone, - TaxCalculationStrategyInterface $strategy - ): void { - $order->getItems()->willReturn(new ArrayCollection([$orderItem->getWrappedObject()])); - $order->getShipments()->willReturn(new ArrayCollection([])); - $order->isEmpty()->willReturn(false); - $order->getBillingAddress()->willReturn($address); - - $order->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT)->shouldBeCalled(); - $orderItem->removeAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT)->shouldBeCalled(); - - $zoneMatcher->match($address, Scope::TAX)->willReturn($zone); - - $strategyRegistry->all()->willReturn([$strategy]); - - $strategy->supports($order, $zone)->willReturn(false); - $strategy->applyTaxes($order, $zone)->shouldNotBeCalled(); - - $this->shouldThrow(UnsupportedTaxCalculationStrategyException::class)->during('process', [$order]); - } - - function it_does_not_process_taxes_if_there_is_no_order_item(OrderInterface $order): void - { - $order->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT)->shouldBeCalled(); - $order->getItems()->willReturn(new ArrayCollection([])); - $order->getShipments()->willReturn(new ArrayCollection([])); - $order->isEmpty()->willReturn(true); - - $order->getBillingAddress()->shouldNotBeCalled(); - - $this->process($order); - } - - function it_does_not_process_taxes_if_there_is_no_tax_zone( - ZoneProviderInterface $defaultTaxZoneProvider, - ZoneMatcherInterface $zoneMatcher, - PrioritizedServiceRegistryInterface $strategyRegistry, - OrderInterface $order, - OrderItemInterface $orderItem, - AddressInterface $address - ): void { - $order->getItems()->willReturn(new ArrayCollection([$orderItem->getWrappedObject()])); - $order->getShipments()->willReturn(new ArrayCollection([])); - $order->isEmpty()->willReturn(false); - - $order->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT)->shouldBeCalled(); - $orderItem->removeAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT)->shouldBeCalled(); - - $order->getBillingAddress()->willReturn($address); - - $zoneMatcher->match($address, Scope::TAX)->willReturn(null); - - $defaultTaxZoneProvider->getZone($order)->willReturn(null); - - $strategyRegistry->all()->shouldNotBeCalled(); - - $this->process($order); - } -} diff --git a/spec/OrderProcessor/ShippingChargesProcessorSpec.php b/spec/OrderProcessor/ShippingChargesProcessorSpec.php deleted file mode 100644 index aebc5ec0..00000000 --- a/spec/OrderProcessor/ShippingChargesProcessorSpec.php +++ /dev/null @@ -1,90 +0,0 @@ -beConstructedWith($adjustmentFactory, $calculator); - } - - function it_is_an_order_processor(): void - { - $this->shouldImplement(OrderProcessorInterface::class); - } - - function it_removes_existing_shipping_adjustments(OrderInterface $order): void - { - $order->getShipments()->willReturn(new ArrayCollection([])); - $order->removeAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT)->shouldBeCalled(); - - $this->process($order); - } - - function it_does_not_apply_any_shipping_charge_if_order_has_no_shipments(OrderInterface $order): void - { - $order->removeAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT)->shouldBeCalled(); - $order->getShipments()->willReturn(new ArrayCollection([])); - $order->addAdjustment(Argument::any())->shouldNotBeCalled(); - - $this->process($order); - } - - function it_applies_calculated_shipping_charge_for_each_shipment_associated_with_the_order( - FactoryInterface $adjustmentFactory, - DelegatingCalculatorInterface $calculator, - AdjustmentInterface $adjustment, - OrderInterface $order, - ShipmentInterface $shipment, - ShippingMethodInterface $shippingMethod - ): void { - $adjustmentFactory->createNew()->willReturn($adjustment); - $order->getShipments()->willReturn(new ArrayCollection([$shipment->getWrappedObject()])); - - $calculator->calculate($shipment)->willReturn(450); - - $shipment->getMethod()->willReturn($shippingMethod); - $shippingMethod->getCode()->willReturn('fedex'); - $shippingMethod->getName()->willReturn('FedEx'); - - $adjustment->setAmount(450)->shouldBeCalled(); - $adjustment->setType(AdjustmentInterface::SHIPPING_ADJUSTMENT)->shouldBeCalled(); - $adjustment->setLabel('FedEx')->shouldBeCalled(); - $adjustment - ->setDetails([ - 'shippingMethodCode' => 'fedex', - 'shippingMethodName' => 'FedEx', - ]) - ->shouldBeCalled() - ; - - $order->removeAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT)->shouldBeCalled(); - $shipment->removeAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT)->shouldBeCalled(); - $shipment->addAdjustment($adjustment)->shouldBeCalled(); - - $this->process($order); - } -} diff --git a/spec/PromotionAction/ShippingPercentageDiscountPromotionActionCommandSpec.php b/spec/PromotionAction/ShippingPercentageDiscountPromotionActionCommandSpec.php deleted file mode 100644 index 4ead5468..00000000 --- a/spec/PromotionAction/ShippingPercentageDiscountPromotionActionCommandSpec.php +++ /dev/null @@ -1,172 +0,0 @@ -beConstructedWith($adjustmentFactory); - } - - function it_implements_a_promotion_action_interface(): void - { - $this->shouldImplement(PromotionActionCommandInterface::class); - } - - function it_applies_percentage_discount_on_every_shipment( - FactoryInterface $adjustmentFactory, - OrderInterface $order, - PromotionInterface $promotion, - ShipmentInterface $firstShipment, - ShipmentInterface $secondShipment, - AdjustmentInterface $firstAdjustment, - AdjustmentInterface $secondAdjustment - ): void { - $promotion->getName()->willReturn('Promotion'); - $promotion->getCode()->willReturn('PROMOTION'); - - $order->hasShipments()->willReturn(true); - $order->getShipments()->willReturn(new ArrayCollection([ - $firstShipment->getWrappedObject(), - $secondShipment->getWrappedObject(), - ])); - - $firstShipment->getAdjustmentsTotal(AdjustmentInterface::SHIPPING_ADJUSTMENT)->willReturn(400); - $firstShipment->getAdjustmentsTotal(AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT)->willReturn(0); - $adjustmentFactory->createNew()->willReturn($firstAdjustment, $secondAdjustment); - $firstAdjustment->setType(AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT)->shouldBeCalled(); - $firstAdjustment->setLabel('Promotion')->shouldBeCalled(); - $firstAdjustment->setOriginCode('PROMOTION')->shouldBeCalled(); - $firstAdjustment->setAmount(-200); - $firstShipment->addAdjustment($firstAdjustment); - - $secondShipment->getAdjustmentsTotal(AdjustmentInterface::SHIPPING_ADJUSTMENT)->willReturn(600); - $secondShipment->getAdjustmentsTotal(AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT)->willReturn(0); - $secondAdjustment->setType(AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT)->shouldBeCalled(); - $secondAdjustment->setLabel('Promotion')->shouldBeCalled(); - $secondAdjustment->setOriginCode('PROMOTION')->shouldBeCalled(); - $secondAdjustment->setAmount(-300)->shouldBeCalled(); - $secondShipment->addAdjustment($secondAdjustment)->shouldBeCalled(); - - $this->execute($order, ['percentage' => 0.5], $promotion)->shouldReturn(true); - } - - function it_does_not_apply_discount_if_order_has_no_shipment( - FactoryInterface $adjustmentFactory, - OrderInterface $order, - PromotionInterface $promotion - ): void { - $order->hasShipments()->willReturn(false); - $order->getShipments()->shouldNotBeCalled(); - $adjustmentFactory->createNew()->shouldNotBeCalled(); - - $this->execute($order, ['percentage' => 0.1], $promotion)->shouldReturn(false); - } - - function it_does_not_apply_discount_if_adjustment_amount_would_be_0( - FactoryInterface $adjustmentFactory, - OrderInterface $order, - PromotionInterface $promotion, - ShipmentInterface $shipment - ): void { - $order->hasShipments()->willReturn(true); - $order->getShipments()->willReturn(new ArrayCollection([$shipment->getWrappedObject()])); - - $shipment->getAdjustmentsTotal(AdjustmentInterface::SHIPPING_ADJUSTMENT)->willReturn(0); - $shipment->getAdjustmentsTotal(AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT)->willReturn(0); - $adjustmentFactory->createNew()->shouldNotBeCalled(); - - $this->execute($order, ['percentage' => 0.5], $promotion)->shouldReturn(false); - } - - function it_throws_exception_if_subject_is_not_an_order( - PromotionInterface $promotion, - PromotionSubjectInterface $subject - ): void { - $this - ->shouldThrow(\InvalidArgumentException::class) - ->during('execute', [$subject, [], $promotion]) - ; - } - - function it_reverts_adjustments( - OrderInterface $order, - AdjustmentInterface $firstAdjustment, - AdjustmentInterface $secondAdjustment, - ShipmentInterface $firstShipment, - ShipmentInterface $secondShipment, - PromotionInterface $promotion - ): void { - $promotion->getCode()->willReturn('PROMOTION'); - - $firstAdjustment->getOriginCode()->willReturn('PROMOTION'); - $secondAdjustment->getOriginCode()->willReturn('OTHER_PROMOTION'); - - $order->hasShipments()->willReturn(true); - $order->getShipments()->willReturn(new ArrayCollection([ - $firstShipment->getWrappedObject(), - $secondShipment->getWrappedObject(), - ])); - $order - ->getAdjustments(AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT) - ->willReturn(new ArrayCollection([$firstAdjustment->getWrappedObject(), $secondAdjustment->getWrappedObject()])) - ; - - $order->removeAdjustment($firstAdjustment)->shouldBeCalled(); - $order->removeAdjustment($secondAdjustment)->shouldNotBeCalled(); - - $firstShipment - ->getAdjustments(AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT) - ->willReturn(new ArrayCollection([$firstAdjustment->getWrappedObject()])) - ; - $firstShipment->removeAdjustment($firstAdjustment)->shouldBeCalled(); - - $secondShipment - ->getAdjustments(AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT) - ->willReturn(new ArrayCollection([$secondAdjustment->getWrappedObject()])) - ; - $secondShipment->removeAdjustment($secondAdjustment)->shouldNotBeCalled(); - - $this->revert($order, [], $promotion); - } - - function it_does_not_revert_adjustments_if_order_has_no_shipment(OrderInterface $order, PromotionInterface $promotion): void - { - $order->hasShipments()->willReturn(false); - $order->getShipments()->shouldNotBeCalled(); - - $this->revert($order, [], $promotion); - } - - function it_throws_an_exception_while_reverting_subject_is_not_an_order( - PromotionInterface $promotion, - PromotionSubjectInterface $subject - ): void { - $this - ->shouldThrow(\InvalidArgumentException::class) - ->during('revert', [$subject, [], $promotion]) - ; - } -} diff --git a/spec/Provider/RemainingTotalProviderSpec.php b/spec/Provider/RemainingTotalProviderSpec.php index 5d2c3959..28aa17cc 100644 --- a/spec/Provider/RemainingTotalProviderSpec.php +++ b/spec/Provider/RemainingTotalProviderSpec.php @@ -5,11 +5,11 @@ namespace spec\Sylius\RefundPlugin\Provider; use PhpSpec\ObjectBehavior; +use Sylius\Component\Core\Model\AdjustmentInterface; use Sylius\Component\Core\Model\OrderItemUnitInterface; +use Sylius\Component\Core\Model\ShipmentInterface; use Sylius\Component\Resource\Repository\RepositoryInterface; -use Sylius\RefundPlugin\Entity\AdjustmentInterface; use Sylius\RefundPlugin\Entity\RefundInterface; -use Sylius\RefundPlugin\Entity\ShipmentInterface; use Sylius\RefundPlugin\Model\RefundType; use Sylius\RefundPlugin\Provider\RemainingTotalProviderInterface; diff --git a/spec/Provider/TaxRateProviderSpec.php b/spec/Provider/TaxRateProviderSpec.php index 20834f06..38479189 100644 --- a/spec/Provider/TaxRateProviderSpec.php +++ b/spec/Provider/TaxRateProviderSpec.php @@ -6,8 +6,8 @@ use Doctrine\Common\Collections\ArrayCollection; use PhpSpec\ObjectBehavior; +use Sylius\Component\Core\Model\AdjustmentInterface; use Sylius\Component\Core\Model\OrderItemUnitInterface; -use Sylius\RefundPlugin\Entity\AdjustmentInterface; use Sylius\RefundPlugin\Exception\MoreThanOneTaxAdjustment; use Sylius\RefundPlugin\Provider\TaxRateProviderInterface; diff --git a/spec/TaxesApplicator/OrderItemUnitsTaxesApplicatorSpec.php b/spec/TaxesApplicator/OrderItemUnitsTaxesApplicatorSpec.php deleted file mode 100644 index 790e38be..00000000 --- a/spec/TaxesApplicator/OrderItemUnitsTaxesApplicatorSpec.php +++ /dev/null @@ -1,208 +0,0 @@ -beConstructedWith($calculator, $adjustmentsFactory, $taxRateResolver); - } - - function it_implements_an_order_shipment_taxes_applicator_interface(): void - { - $this->shouldImplement(OrderTaxesApplicatorInterface::class); - } - - function it_applies_taxes_on_units_based_on_item_total_and_rate( - CalculatorInterface $calculator, - AdjustmentFactoryInterface $adjustmentsFactory, - TaxRateResolverInterface $taxRateResolver, - AdjustmentInterface $taxAdjustment1, - AdjustmentInterface $taxAdjustment2, - Collection $items, - Collection $units, - OrderInterface $order, - OrderItemInterface $orderItem, - OrderItemUnitInterface $unit1, - OrderItemUnitInterface $unit2, - ProductVariantInterface $productVariant, - TaxRateInterface $taxRate, - ZoneInterface $zone - ): void { - $order->getItems()->willReturn($items); - - $items->count()->willReturn(1); - $items->getIterator()->willReturn(new \ArrayIterator([$orderItem->getWrappedObject()])); - - $orderItem->getVariant()->willReturn($productVariant); - $taxRateResolver->resolve($productVariant, ['zone' => $zone])->willReturn($taxRate); - - $taxRate->getLabel()->willReturn('Simple tax (10%)'); - $taxRate->getCode()->willReturn('simple_tax'); - $taxRate->getName()->willReturn('Simple tax'); - $taxRate->getAmount()->willReturn(0.1); - $taxRate->isIncludedInPrice()->willReturn(false); - - $orderItem->getUnits()->willReturn($units); - $units->getIterator()->willReturn(new \ArrayIterator([$unit1->getWrappedObject(), $unit2->getWrappedObject()])); - - $unit1->getTotal()->willReturn(1000); - $calculator->calculate(1000, $taxRate)->willReturn(100); - - $unit2->getTotal()->willReturn(900); - $calculator->calculate(900, $taxRate)->willReturn(90); - - $adjustmentsFactory - ->createWithData(AdjustmentInterface::TAX_ADJUSTMENT, 'Simple tax (10%)', 100, false) - ->willReturn($taxAdjustment1) - ; - $taxAdjustment1 - ->setDetails([ - 'taxRateCode' => 'simple_tax', - 'taxRateName' => 'Simple tax', - 'taxRateAmount' => 0.1, - ]) - ->shouldBeCalled() - ; - $adjustmentsFactory - ->createWithData( - AdjustmentInterface::TAX_ADJUSTMENT, - 'Simple tax (10%)', - 90, - false - ) - ->willReturn($taxAdjustment2) - ; - $taxAdjustment2 - ->setDetails([ - 'taxRateCode' => 'simple_tax', - 'taxRateName' => 'Simple tax', - 'taxRateAmount' => 0.1, - ]) - ->shouldBeCalled() - ; - - $unit1->addAdjustment($taxAdjustment1)->shouldBeCalled(); - $unit2->addAdjustment($taxAdjustment2)->shouldBeCalled(); - - $this->apply($order, $zone); - } - - function it_does_nothing_if_order_item_has_no_units( - CalculatorInterface $calculator, - AdjustmentFactoryInterface $adjustmentsFactory, - TaxRateResolverInterface $taxRateResolver, - OrderInterface $order, - OrderItemInterface $orderItem, - ProductVariantInterface $productVariant, - TaxRateInterface $taxRate, - ZoneInterface $zone - ): void { - $orderItems = new ArrayCollection([$orderItem->getWrappedObject()]); - $order->getItems()->willReturn($orderItems); - - $orderItem->getVariant()->willReturn($productVariant); - $orderItem->getUnits()->willReturn(new ArrayCollection()); - $taxRateResolver->resolve(Argument::cetera())->willReturn($taxRate); - - $calculator->calculate(Argument::cetera())->shouldNotBeCalled(); - $adjustmentsFactory->createWithData(Argument::cetera())->shouldNotBeCalled(); - - $this->apply($order, $zone); - } - - function it_does_nothing_if_tax_rate_cannot_be_resolved( - CalculatorInterface $calculator, - TaxRateResolverInterface $taxRateResolver, - Collection $items, - OrderInterface $order, - OrderItemInterface $orderItem, - ProductVariantInterface $productVariant, - ZoneInterface $zone - ): void { - $order->getItems()->willReturn($items); - - $items->count()->willReturn(1); - $items->getIterator()->willReturn(new \ArrayIterator([$orderItem->getWrappedObject()])); - - $orderItem->getQuantity()->willReturn(1); - - $orderItem->getVariant()->willReturn($productVariant); - $taxRateResolver->resolve($productVariant, ['zone' => $zone])->willReturn(null); - - $orderItem->getUnits()->shouldNotBeCalled(); - $calculator->calculate(Argument::cetera())->shouldNotBeCalled(); - - $this->apply($order, $zone); - } - - function it_does_not_apply_taxes_with_amount_0( - CalculatorInterface $calculator, - AdjustmentFactoryInterface $adjustmentsFactory, - TaxRateResolverInterface $taxRateResolver, - Collection $items, - Collection $units, - OrderInterface $order, - OrderItemInterface $orderItem, - OrderItemUnitInterface $unit1, - OrderItemUnitInterface $unit2, - ProductVariantInterface $productVariant, - TaxRateInterface $taxRate, - ZoneInterface $zone - ): void { - $order->getItems()->willReturn($items); - - $items->count()->willReturn(2); - $items->getIterator()->willReturn(new \ArrayIterator([$orderItem->getWrappedObject()])); - - $orderItem->getQuantity()->willReturn(2); - $orderItem->getVariant()->willReturn($productVariant); - $taxRateResolver->resolve($productVariant, ['zone' => $zone])->willReturn($taxRate); - - $orderItem->getUnits()->willReturn($units); - $units->getIterator()->willReturn(new \ArrayIterator([$unit1->getWrappedObject(), $unit2->getWrappedObject()])); - - $unit1->getTotal()->willReturn(1000); - $calculator->calculate(1000, $taxRate)->willReturn(0.00); - - $unit2->getTotal()->willReturn(900); - $calculator->calculate(900, $taxRate)->willReturn(0.00); - - $adjustmentsFactory->createWithData(AdjustmentInterface::TAX_ADJUSTMENT, Argument::cetera())->shouldNotBeCalled(); - $unit1->addAdjustment(Argument::any())->shouldNotBeCalled(); - $unit2->addAdjustment(Argument::any())->shouldNotBeCalled(); - - $this->apply($order, $zone); - } -} diff --git a/spec/TaxesApplicator/OrderItemsTaxesApplicatorSpec.php b/spec/TaxesApplicator/OrderItemsTaxesApplicatorSpec.php deleted file mode 100644 index 117c0237..00000000 --- a/spec/TaxesApplicator/OrderItemsTaxesApplicatorSpec.php +++ /dev/null @@ -1,202 +0,0 @@ -beConstructedWith($calculator, $adjustmentsFactory, $distributor, $taxRateResolver); - } - - function it_implements_an_order_shipment_taxes_applicator_interface(): void - { - $this->shouldImplement(OrderTaxesApplicatorInterface::class); - } - - function it_applies_taxes_on_units_based_on_item_total_and_rate( - CalculatorInterface $calculator, - AdjustmentFactoryInterface $adjustmentsFactory, - IntegerDistributorInterface $distributor, - TaxRateResolverInterface $taxRateResolver, - AdjustmentInterface $taxAdjustment1, - AdjustmentInterface $taxAdjustment2, - Collection $items, - Collection $units, - OrderInterface $order, - OrderItemInterface $orderItem, - OrderItemUnitInterface $unit1, - OrderItemUnitInterface $unit2, - ProductVariantInterface $productVariant, - TaxRateInterface $taxRate, - ZoneInterface $zone - ): void { - $order->getItems()->willReturn($items); - - $items->count()->willReturn(1); - $items->getIterator()->willReturn(new \ArrayIterator([$orderItem->getWrappedObject()])); - - $orderItem->getQuantity()->willReturn(2); - $orderItem->getVariant()->willReturn($productVariant); - $taxRateResolver->resolve($productVariant, ['zone' => $zone])->willReturn($taxRate); - - $orderItem->getTotal()->willReturn(1000); - $calculator->calculate(1000, $taxRate)->willReturn(100); - - $taxRate->getLabel()->willReturn('Simple tax (10%)'); - $taxRate->getCode()->willReturn('simple_tax'); - $taxRate->getName()->willReturn('Simple tax'); - $taxRate->getAmount()->willReturn(0.1); - $taxRate->isIncludedInPrice()->willReturn(false); - - $orderItem->getUnits()->willReturn($units); - $units->getIterator()->willReturn(new \ArrayIterator([4 => $unit1->getWrappedObject(), 5 => $unit2->getWrappedObject()])); - - $distributor->distribute(100, 2)->willReturn([50, 50]); - - $adjustmentsFactory - ->createWithData( - AdjustmentInterface::TAX_ADJUSTMENT, - 'Simple tax (10%)', - 50, - false - ) - ->willReturn($taxAdjustment1, $taxAdjustment2) - ; - $taxAdjustment1 - ->setDetails([ - 'taxRateCode' => 'simple_tax', - 'taxRateName' => 'Simple tax', - 'taxRateAmount' => 0.1, - ]) - ->shouldBeCalled() - ; - $taxAdjustment2 - ->setDetails([ - 'taxRateCode' => 'simple_tax', - 'taxRateName' => 'Simple tax', - 'taxRateAmount' => 0.1, - ]) - ->shouldBeCalled() - ; - - $unit1->addAdjustment($taxAdjustment1)->shouldBeCalled(); - $unit2->addAdjustment($taxAdjustment2)->shouldBeCalled(); - - $this->apply($order, $zone); - } - - function it_throws_an_invalid_argument_exception_if_order_item_has_0_quantity( - OrderInterface $order, - OrderItemInterface $orderItem, - ZoneInterface $zone - ): void { - $items = new ArrayCollection([$orderItem->getWrappedObject()]); - $order->getItems()->willReturn($items); - - $orderItem->getQuantity()->willReturn(0); - - $this->shouldThrow(\InvalidArgumentException::class)->during('apply', [$order, $zone]); - } - - function it_does_nothing_if_tax_rate_cannot_be_resolved( - TaxRateResolverInterface $taxRateResolver, - Collection $items, - \Iterator $iterator, - OrderInterface $order, - OrderItemInterface $orderItem, - ProductVariantInterface $productVariant, - ZoneInterface $zone - ): void { - $order->getItems()->willReturn($items); - - $items->count()->willReturn(1); - $items->getIterator()->willReturn($iterator); - - $iterator->rewind()->shouldBeCalled(); - $iterator->valid()->willReturn(true, false)->shouldBeCalled(); - $iterator->current()->willReturn($orderItem); - $iterator->next()->shouldBeCalled(); - - $orderItem->getQuantity()->willReturn(5); - $orderItem->getVariant()->willReturn($productVariant); - $taxRateResolver->resolve($productVariant, ['zone' => $zone])->willReturn(null); - - $orderItem->getUnits()->shouldNotBeCalled(); - - $this->apply($order, $zone); - } - - function it_does_not_apply_taxes_with_amount_0( - CalculatorInterface $calculator, - AdjustmentFactoryInterface $adjustmentsFactory, - IntegerDistributorInterface $distributor, - TaxRateResolverInterface $taxRateResolver, - Collection $items, - Collection $units, - OrderInterface $order, - OrderItemInterface $orderItem, - OrderItemUnitInterface $unit1, - OrderItemUnitInterface $unit2, - ProductVariantInterface $productVariant, - TaxRateInterface $taxRate, - ZoneInterface $zone - ): void { - $order->getItems()->willReturn($items); - - $items->count()->willReturn(1); - $items->getIterator()->willReturn(new \ArrayIterator([$orderItem->getWrappedObject()])); - - $orderItem->getQuantity()->willReturn(2); - $orderItem->getVariant()->willReturn($productVariant); - - $taxRateResolver->resolve($productVariant, ['zone' => $zone])->willReturn($taxRate); - - $orderItem->getTotal()->willReturn(1000); - $calculator->calculate(1000, $taxRate)->willReturn(0); - - $taxRate->getLabel()->willReturn('Simple tax (0%)'); - $taxRate->isIncludedInPrice()->willReturn(false); - - $orderItem->getUnits()->willReturn($units); - $units->getIterator()->willReturn(new \ArrayIterator([4 => $unit1->getWrappedObject(), 5 => $unit2->getWrappedObject()])); - - $distributor->distribute(0, 2)->willReturn([0, 0]); - - $adjustmentsFactory->createWithData(Argument::any())->shouldNotBeCalled(); - - $this->apply($order, $zone); - } -} diff --git a/spec/TaxesApplicator/OrderShipmentTaxesApplicatorSpec.php b/spec/TaxesApplicator/OrderShipmentTaxesApplicatorSpec.php deleted file mode 100644 index 6485e682..00000000 --- a/spec/TaxesApplicator/OrderShipmentTaxesApplicatorSpec.php +++ /dev/null @@ -1,390 +0,0 @@ -beConstructedWith($calculator, $adjustmentsFactory, $taxRateResolver); - } - - function it_implements_an_order_shipment_taxes_applicator_interface(): void - { - $this->shouldImplement(OrderTaxesApplicatorInterface::class); - } - - function it_applies_shipment_taxes_on_order_based_on_shipment_adjustments_promotions_and_rate( - CalculatorInterface $calculator, - AdjustmentFactoryInterface $adjustmentsFactory, - TaxRateResolverInterface $taxRateResolver, - AdjustmentInterface $shippingTaxAdjustment, - OrderInterface $order, - ShipmentInterface $shipment, - ShippingMethodInterface $shippingMethod, - TaxRateInterface $taxRate, - ZoneInterface $zone - ): void { - $order->getShippingTotal()->willReturn(1000); - $order->hasShipments()->willReturn(true); - $order->getShipments()->willReturn(new ArrayCollection([$shipment->getWrappedObject()])); - $shipment->getAdjustmentsTotal()->willReturn(1000); - $shipment->getMethod()->willReturn($shippingMethod); - - $shippingMethod->getCode()->willReturn('fedex'); - $shippingMethod->getName()->willReturn('FedEx'); - - $taxRateResolver->resolve($shippingMethod, ['zone' => $zone])->willReturn($taxRate); - $taxRate->getLabel()->willReturn('Simple tax (10%)'); - $taxRate->getCode()->willReturn('simple_tax'); - $taxRate->getName()->willReturn('Simple tax'); - $taxRate->getAmount()->willReturn(0.1); - $taxRate->isIncludedInPrice()->willReturn(false); - - $calculator->calculate(1000, $taxRate)->willReturn(100); - - $adjustmentsFactory - ->createWithData( - AdjustmentInterface::TAX_ADJUSTMENT, - 'Simple tax (10%)', - 100, - false - ) - ->willReturn($shippingTaxAdjustment) - ; - $shippingTaxAdjustment - ->setDetails([ - 'shippingMethodCode' => 'fedex', - 'shippingMethodName' => 'FedEx', - 'taxRateCode' => 'simple_tax', - 'taxRateName' => 'Simple tax', - 'taxRateAmount' => 0.1, - ]) - ->shouldBeCalled() - ; - $shipment->addAdjustment($shippingTaxAdjustment)->shouldBeCalled(); - - $this->apply($order, $zone); - } - - function it_applies_taxes_on_multiple_shipments_based_on_shipment_adjustments_promotions_and_rate( - CalculatorInterface $calculator, - AdjustmentFactoryInterface $adjustmentsFactory, - TaxRateResolverInterface $taxRateResolver, - AdjustmentInterface $firstShippingTaxAdjustment, - AdjustmentInterface $secondShippingTaxAdjustment, - OrderInterface $order, - ShipmentInterface $firstShipment, - ShipmentInterface $secondShipment, - ShippingMethodInterface $shippingMethod, - TaxRateInterface $taxRate, - ZoneInterface $zone - ): void { - $order->getShippingTotal()->willReturn(1000); - $order->hasShipments()->willReturn(true); - $order->getShipments()->willReturn(new ArrayCollection([ - $firstShipment->getWrappedObject(), - $secondShipment->getWrappedObject(), - ])); - $firstShipment->getAdjustmentsTotal()->willReturn(600); - $firstShipment->getMethod()->willReturn($shippingMethod); - $secondShipment->getAdjustmentsTotal()->willReturn(400); - $secondShipment->getMethod()->willReturn($shippingMethod); - - $shippingMethod->getCode()->willReturn('fedex'); - $shippingMethod->getName()->willReturn('FedEx'); - - $taxRateResolver->resolve($shippingMethod, ['zone' => $zone])->willReturn($taxRate); - $taxRate->getLabel()->willReturn('Simple tax (10%)'); - $taxRate->getCode()->willReturn('simple_tax'); - $taxRate->getName()->willReturn('Simple tax'); - $taxRate->getAmount()->willReturn(0.1); - $taxRate->isIncludedInPrice()->willReturn(false); - - $calculator->calculate(600, $taxRate)->willReturn(60); - $adjustmentsFactory - ->createWithData( - AdjustmentInterface::TAX_ADJUSTMENT, - 'Simple tax (10%)', - 60, - false - ) - ->willReturn($firstShippingTaxAdjustment) - ; - $firstShippingTaxAdjustment - ->setDetails([ - 'shippingMethodCode' => 'fedex', - 'shippingMethodName' => 'FedEx', - 'taxRateCode' => 'simple_tax', - 'taxRateName' => 'Simple tax', - 'taxRateAmount' => 0.1, - ]) - ->shouldBeCalled() - ; - $firstShipment->addAdjustment($firstShippingTaxAdjustment)->shouldBeCalled(); - - $calculator->calculate(400, $taxRate)->willReturn(40); - $adjustmentsFactory - ->createWithData( - AdjustmentInterface::TAX_ADJUSTMENT, - 'Simple tax (10%)', - 40, - false, - ) - ->willReturn($secondShippingTaxAdjustment) - ; - $secondShippingTaxAdjustment - ->setDetails([ - 'shippingMethodCode' => 'fedex', - 'shippingMethodName' => 'FedEx', - 'taxRateCode' => 'simple_tax', - 'taxRateName' => 'Simple tax', - 'taxRateAmount' => 0.1, - ]) - ->shouldBeCalled() - ; - $secondShipment->addAdjustment($secondShippingTaxAdjustment)->shouldBeCalled(); - - $this->apply($order, $zone); - } - - function it_applies_taxes_on_multiple_shipments_when_there_is_no_tax_rate_for_one_of_them( - CalculatorInterface $calculator, - AdjustmentFactoryInterface $adjustmentsFactory, - TaxRateResolverInterface $taxRateResolver, - AdjustmentInterface $shippingTaxAdjustment, - OrderInterface $order, - ShipmentInterface $firstShipment, - ShipmentInterface $secondShipment, - ShippingMethodInterface $firstShippingMethod, - ShippingMethodInterface $secondShippingMethod, - TaxRateInterface $taxRate, - ZoneInterface $zone - ): void { - $order->getShippingTotal()->willReturn(1000); - $order->hasShipments()->willReturn(true); - $order->getShipments()->willReturn(new ArrayCollection([ - $firstShipment->getWrappedObject(), - $secondShipment->getWrappedObject(), - ])); - $firstShipment->getAdjustmentsTotal()->willReturn(600); - $firstShipment->getMethod()->willReturn($firstShippingMethod); - $secondShipment->getAdjustmentsTotal()->willReturn(400); - $secondShipment->getMethod()->willReturn($secondShippingMethod); - - $firstShippingMethod->getCode()->willReturn('dhl'); - $firstShippingMethod->getName()->willReturn('DHL'); - - $secondShippingMethod->getCode()->willReturn('fedex'); - $secondShippingMethod->getName()->willReturn('FedEx'); - - $taxRateResolver->resolve($firstShippingMethod, ['zone' => $zone])->willReturn(null); - - $taxRateResolver->resolve($secondShippingMethod, ['zone' => $zone])->willReturn($taxRate); - $taxRate->getLabel()->willReturn('Simple tax (10%)'); - $taxRate->getCode()->willReturn('simple_tax'); - $taxRate->getName()->willReturn('Simple tax'); - $taxRate->getAmount()->willReturn(0.1); - $taxRate->isIncludedInPrice()->willReturn(false); - - $firstShipment->addAdjustment(Argument::any())->shouldNotBeCalled(); - - $calculator->calculate(400, $taxRate)->willReturn(40); - $adjustmentsFactory - ->createWithData( - AdjustmentInterface::TAX_ADJUSTMENT, - 'Simple tax (10%)', - 40, - false, - ) - ->willReturn($shippingTaxAdjustment) - ; - $shippingTaxAdjustment - ->setDetails([ - 'shippingMethodCode' => 'fedex', - 'shippingMethodName' => 'FedEx', - 'taxRateCode' => 'simple_tax', - 'taxRateName' => 'Simple tax', - 'taxRateAmount' => 0.1, - ]) - ->shouldBeCalled() - ; - $secondShipment->addAdjustment($shippingTaxAdjustment)->shouldBeCalled(); - - $this->apply($order, $zone); - } - - function it_applies_taxes_on_multiple_shipments_when_one_of_them_has_0_tax_amount( - CalculatorInterface $calculator, - AdjustmentFactoryInterface $adjustmentsFactory, - TaxRateResolverInterface $taxRateResolver, - AdjustmentInterface $shippingTaxAdjustment, - OrderInterface $order, - ShipmentInterface $firstShipment, - ShipmentInterface $secondShipment, - ShippingMethodInterface $firstShippingMethod, - ShippingMethodInterface $secondShippingMethod, - TaxRateInterface $taxRate, - ZoneInterface $zone - ): void { - $order->getShippingTotal()->willReturn(1000); - $order->hasShipments()->willReturn(true); - $order->getShipments()->willReturn(new ArrayCollection([ - $firstShipment->getWrappedObject(), - $secondShipment->getWrappedObject(), - ])); - $firstShipment->getAdjustmentsTotal()->willReturn(600); - $firstShipment->getMethod()->willReturn($firstShippingMethod); - $secondShipment->getAdjustmentsTotal()->willReturn(400); - $secondShipment->getMethod()->willReturn($secondShippingMethod); - - $firstShippingMethod->getCode()->willReturn('dhl'); - $firstShippingMethod->getName()->willReturn('DHL'); - - $secondShippingMethod->getCode()->willReturn('fedex'); - $secondShippingMethod->getName()->willReturn('FedEx'); - - $taxRateResolver->resolve($firstShippingMethod, ['zone' => $zone])->willReturn($taxRate); - $taxRateResolver->resolve($secondShippingMethod, ['zone' => $zone])->willReturn($taxRate); - $taxRate->getLabel()->willReturn('Simple tax (10%)'); - $taxRate->getCode()->willReturn('simple_tax'); - $taxRate->getName()->willReturn('Simple tax'); - $taxRate->getAmount()->willReturn(0.1); - $taxRate->isIncludedInPrice()->willReturn(false); - - $firstShipment->addAdjustment(Argument::any())->shouldNotBeCalled(); - - $calculator->calculate(600, $taxRate)->willReturn(0); - $adjustmentsFactory - ->createWithData( - AdjustmentInterface::TAX_ADJUSTMENT, - 'Simple tax (10%)', - 0, - false, - ) - ->shouldNotBeCalled() - ; - - $calculator->calculate(400, $taxRate)->willReturn(40); - $adjustmentsFactory - ->createWithData( - AdjustmentInterface::TAX_ADJUSTMENT, - 'Simple tax (10%)', - 40, - false, - ) - ->willReturn($shippingTaxAdjustment) - ; - $shippingTaxAdjustment - ->setDetails([ - 'shippingMethodCode' => 'fedex', - 'shippingMethodName' => 'FedEx', - 'taxRateCode' => 'simple_tax', - 'taxRateName' => 'Simple tax', - 'taxRateAmount' => 0.1, - ]) - ->shouldBeCalled() - ; - $secondShipment->addAdjustment($shippingTaxAdjustment)->shouldBeCalled(); - - $this->apply($order, $zone); - } - - function it_does_nothing_if_the_tax_amount_is_0( - CalculatorInterface $calculator, - AdjustmentFactoryInterface $adjustmentsFactory, - TaxRateResolverInterface $taxRateResolver, - OrderInterface $order, - ShipmentInterface $shipment, - ShippingMethodInterface $shippingMethod, - TaxRateInterface $taxRate, - ZoneInterface $zone - ): void { - $order->getShippingTotal()->willReturn(1000); - $order->hasShipments()->willReturn(true); - $order->getShipments()->willReturn(new ArrayCollection([$shipment->getWrappedObject()])); - $shipment->getMethod()->willReturn($shippingMethod); - $shipment->getAdjustmentsTotal()->willReturn(1000); - - $taxRateResolver->resolve($shippingMethod, ['zone' => $zone])->willReturn($taxRate); - - $calculator->calculate(1000, $taxRate)->willReturn(0.00); - - $adjustmentsFactory->createWithData(Argument::cetera())->shouldNotBeCalled(); - $order->addAdjustment(Argument::any())->shouldNotBeCalled(); - - $this->apply($order, $zone); - } - - function it_throws_an_exception_if_order_has_no_shipment_but_shipment_total_is_greater_than_0( - OrderInterface $order, - ZoneInterface $zone - ): void { - $order->getShippingTotal()->willReturn(10); - $order->hasShipments()->willReturn(false); - - $this->shouldThrow(\LogicException::class)->during('apply', [$order, $zone]); - } - - function it_does_nothing_if_tax_rate_cannot_be_resolved( - CalculatorInterface $calculator, - TaxRateResolverInterface $taxRateResolver, - OrderInterface $order, - ShipmentInterface $shipment, - ShippingMethodInterface $shippingMethod, - ZoneInterface $zone - ): void { - $order->getShippingTotal()->willReturn(100); - $order->hasShipments()->willReturn(true); - $order->getShipments()->willReturn(new ArrayCollection([$shipment->getWrappedObject()])); - $shipment->getMethod()->willReturn($shippingMethod); - - $taxRateResolver->resolve($shippingMethod, ['zone' => $zone])->willReturn(null); - - $calculator->calculate(Argument::any())->shouldNotBeCalled(); - $order->addAdjustment(Argument::any())->shouldNotBeCalled(); - - $this->apply($order, $zone); - } - - function it_does_nothing_if_order_has_0_shipping_total( - TaxRateResolverInterface $taxRateResolver, - OrderInterface $order, - ZoneInterface $zone - ): void { - $order->getShippingTotal()->willReturn(0); - - $taxRateResolver->resolve(Argument::any())->shouldNotBeCalled(); - $order->addAdjustment(Argument::any())->shouldNotBeCalled(); - - $this->apply($order, $zone); - } -} diff --git a/src/Converter/ShipmentLineItemsConverter.php b/src/Converter/ShipmentLineItemsConverter.php index 8ef72ff9..9be71142 100644 --- a/src/Converter/ShipmentLineItemsConverter.php +++ b/src/Converter/ShipmentLineItemsConverter.php @@ -4,12 +4,12 @@ namespace Sylius\RefundPlugin\Converter; +use Sylius\Component\Core\Model\AdjustmentInterface; +use Sylius\Component\Core\Model\ShipmentInterface; use Sylius\Component\Order\Model\AdjustableInterface; use Sylius\Component\Resource\Repository\RepositoryInterface; -use Sylius\RefundPlugin\Entity\AdjustmentInterface; use Sylius\RefundPlugin\Entity\LineItem; use Sylius\RefundPlugin\Entity\LineItemInterface; -use Sylius\RefundPlugin\Entity\ShipmentInterface; use Sylius\RefundPlugin\Exception\MoreThanOneTaxAdjustment; use Sylius\RefundPlugin\Model\ShipmentRefund; use Sylius\RefundPlugin\Provider\TaxRateProviderInterface; diff --git a/src/Entity/AdjustmentInterface.php b/src/Entity/AdjustmentInterface.php deleted file mode 100644 index 46cb5cbe..00000000 --- a/src/Entity/AdjustmentInterface.php +++ /dev/null @@ -1,34 +0,0 @@ -details; - } - - public function setDetails(array $details): void - { - $this->details = $details; - } - - public function getShipment(): ?BaseShipmentInterface - { - return $this->shipment; - } - - public function setShipment(?BaseShipmentInterface $shipment): void - { - if ($this->shipment === $shipment) { - return; - } - - if ($this->shipment !== null) { - $this->shipment->removeAdjustment($this); - } - - $this->shipment = $shipment; - - if ($shipment !== null) { - $this->setAdjustable($this->shipment->getOrder()); - } - } -} diff --git a/src/Entity/ShipmentInterface.php b/src/Entity/ShipmentInterface.php deleted file mode 100644 index 911f7609..00000000 --- a/src/Entity/ShipmentInterface.php +++ /dev/null @@ -1,33 +0,0 @@ - - */ - protected $adjustments; - - /** - * @var int - * @ORM\Column(type="integer", name="adjustments_total") - */ - protected $adjustmentsTotal = 0; - - public function getAdjustments(?string $type = null): Collection - { - if (null === $type) { - return $this->adjustments; - } - - return $this->adjustments->filter(function (AdjustmentInterface $adjustment) use ($type): bool { - return $type === $adjustment->getType(); - }); - } - - public function addAdjustment(BaseAdjustmentInterface $adjustment): void - { - /** @var AdjustmentInterface $adjustment */ - Assert::isInstanceOf($adjustment, AdjustmentInterface::class); - - if ($this->hasAdjustment($adjustment)) { - return; - } - - $this->adjustments->add($adjustment); - $adjustment->setShipment($this); - $this->recalculateAdjustmentsTotal(); - $this->order->recalculateAdjustmentsTotal(); - } - - public function removeAdjustment(BaseAdjustmentInterface $adjustment): void - { - /** @var AdjustmentInterface $adjustment */ - if ($adjustment->isLocked() || !$this->hasAdjustment($adjustment)) { - return; - } - - $this->adjustments->removeElement($adjustment); - $adjustment->setShipment(null); - $this->recalculateAdjustmentsTotal(); - $this->order->recalculateAdjustmentsTotal(); - } - - public function hasAdjustment(BaseAdjustmentInterface $adjustment): bool - { - return $this->adjustments->contains($adjustment); - } - - public function getAdjustmentsTotal(?string $type = null): int - { - $total = 0; - foreach ($this->getAdjustments($type) as $adjustment) { - if (!$adjustment->isNeutral()) { - $total += $adjustment->getAmount(); - } - } - - return $total; - } - - public function removeAdjustments(?string $type = null): void - { - foreach ($this->getAdjustments($type) as $adjustment) { - $this->removeAdjustment($adjustment); - } - } - - public function recalculateAdjustmentsTotal(): void - { - $this->adjustmentsTotal = $this->getAdjustmentsTotal(); - } -} diff --git a/src/Migrations/Version20201130071338.php b/src/Migrations/Version20201130071338.php deleted file mode 100644 index 08391d37..00000000 --- a/src/Migrations/Version20201130071338.php +++ /dev/null @@ -1,57 +0,0 @@ -getTable('sylius_adjustment'); - if ($adjustmentTable->hasColumn('shipment_id')) { - return; - } - - $this->addSql('ALTER TABLE sylius_adjustment ADD shipment_id INT DEFAULT NULL'); - $this->addSql('ALTER TABLE sylius_adjustment ADD CONSTRAINT FK_ACA6E0F27BE036FC FOREIGN KEY (shipment_id) REFERENCES sylius_shipment (id) ON DELETE CASCADE'); - $this->addSql('CREATE INDEX IDX_ACA6E0F27BE036FC ON sylius_adjustment (shipment_id)'); - $this->addSql('ALTER TABLE sylius_shipment ADD adjustments_total INT NOT NULL'); - } - - public function down(Schema $schema): void - { - $adjustmentTable = $schema->getTable('sylius_adjustment'); - if (!$adjustmentTable->hasColumn('shipment_id')) { - return; - } - - $this->addSql('ALTER TABLE sylius_adjustment DROP FOREIGN KEY FK_ACA6E0F27BE036FC'); - $this->addSql('DROP INDEX IDX_ACA6E0F27BE036FC ON sylius_adjustment'); - $this->addSql('ALTER TABLE sylius_adjustment DROP shipment_id'); - $this->addSql('ALTER TABLE sylius_shipment DROP adjustments_total'); - } -} diff --git a/src/Migrations/Version20201204071301.php b/src/Migrations/Version20201204071301.php deleted file mode 100644 index 0eaba303..00000000 --- a/src/Migrations/Version20201204071301.php +++ /dev/null @@ -1,51 +0,0 @@ -getTable('sylius_adjustment'); - if ($adjustmentTable->hasColumn('details')) { - return; - } - - $this->addSql('ALTER TABLE sylius_adjustment ADD details JSON NOT NULL'); - } - - public function down(Schema $schema): void - { - $adjustmentTable = $schema->getTable('sylius_adjustment'); - if (!$adjustmentTable->hasColumn('details')) { - return; - } - - $this->addSql('ALTER TABLE sylius_adjustment DROP details'); - } -} diff --git a/src/Migrations/Version20201208105207.php b/src/Migrations/Version20201208105207.php deleted file mode 100644 index 2bca4db0..00000000 --- a/src/Migrations/Version20201208105207.php +++ /dev/null @@ -1,109 +0,0 @@ -setDefaultAdjustmentData(); - - $adjustments = $this->getShipmentAdjustmentsWithData(); - - foreach ($adjustments as $adjustment) { - if (!isset($this->shippingName[$adjustment['shipment_code']])) { - $this->shippingName[$adjustment['shipment_code']] = $adjustment['label']; - } - - $this->updateAdjustment( - (int) $adjustment['id'], - $adjustment['shipping_id'] ?? 'NULL', - $this->getParsedDetails(['taxRateCode' => $adjustment['tax_rate_code'], 'taxRateName' => $adjustment['tax_rate_name'], 'taxRateAmount' => ($adjustment['tax_rate_amount'] ? (float) $adjustment['tax_rate_amount'] : null), 'shippingMethodCode' => $adjustment['shipment_code'], 'shippingMethodName' => $this->getShippingMethodName($adjustment['shipment_code'])]) - ); - } - } - - public function down(Schema $schema): void - { - $this->setDefaultAdjustmentData(); - } - - private function getShippingMethodName(?string $shippingMethodCode): ?string - { - if ($shippingMethodCode === null) { - return $shippingMethodCode; - } - - return $this->shippingName[$shippingMethodCode]; - } - - private function getParsedDetails(array $details): string - { - /** @var array $parsedDetails */ - $parsedDetails = []; - - foreach ($details as $key => $value) { - if ($value !== null) { - $parsedDetails[$key] = $value; - } - } - - /** @var string $encodedDetails */ - $encodedDetails = json_encode($parsedDetails); - - return $encodedDetails; - } - - private function setDefaultAdjustmentData(): void - { - $this->addSql("UPDATE sylius_adjustment SET shipment_id = null, details = '[]'"); - } - - private function updateAdjustment(int $adjustmentId, string $shipmentId, string $details): void - { - $this->addSql("UPDATE sylius_adjustment SET shipment_id = $shipmentId, details = '" . $details . "' WHERE id = $adjustmentId"); - } - - private function getShipmentAdjustmentsWithData(): array - { - return $this->connection->fetchAllAssociative( - ' - SELECT adjustment.id, adjustment.label, tax_rate.code as tax_rate_code, tax_rate.name as tax_rate_name, tax_rate.amount as tax_rate_amount, adjustment.order_id, shipment.id as shipping_id, shipment.method_id, shipping_method.code AS shipment_code - FROM sylius_adjustment adjustment - LEFT JOIN sylius_shipment shipment ON shipment.order_id = adjustment.order_id - LEFT JOIN sylius_shipping_method shipping_method on shipment.method_id = shipping_method.id - LEFT JOIN sylius_tax_rate tax_rate on adjustment.label LIKE CONCAT(tax_rate.name, \'%\') - WHERE adjustment.type IN ("shipping", "tax") - ORDER BY adjustment.type - ' - ); - } -} diff --git a/src/OrderProcessor/OrderTaxesProcessor.php b/src/OrderProcessor/OrderTaxesProcessor.php deleted file mode 100644 index 1634120c..00000000 --- a/src/OrderProcessor/OrderTaxesProcessor.php +++ /dev/null @@ -1,110 +0,0 @@ -defaultTaxZoneProvider = $defaultTaxZoneProvider; - $this->zoneMatcher = $zoneMatcher; - $this->strategyRegistry = $strategyRegistry; - } - - public function process(BaseOrderInterface $order): void - { - /** @var OrderInterface $order */ - Assert::isInstanceOf($order, OrderInterface::class); - - $this->clearTaxes($order); - if ($order->isEmpty()) { - return; - } - - $zone = $this->getTaxZone($order); - - if (null === $zone) { - return; - } - - /** @var TaxCalculationStrategyInterface $strategy */ - foreach ($this->strategyRegistry->all() as $strategy) { - if ($strategy->supports($order, $zone)) { - $strategy->applyTaxes($order, $zone); - - return; - } - } - - throw new UnsupportedTaxCalculationStrategyException(); - } - - private function getTaxZone(OrderInterface $order): ?ZoneInterface - { - $billingAddress = $order->getBillingAddress(); - $zone = null; - - if (null !== $billingAddress) { - $zone = $this->zoneMatcher->match($billingAddress, Scope::TAX); - } - - return $zone ?: $this->defaultTaxZoneProvider->getZone($order); - } - - private function clearTaxes(OrderInterface $order): void - { - $order->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT); - - foreach ($order->getItems() as $item) { - $item->removeAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT); - } - - /** @var ShipmentInterface $shipment */ - foreach ($order->getShipments() as $shipment) { - $shipment->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT); - } - } -} diff --git a/src/OrderProcessor/ShippingChargesProcessor.php b/src/OrderProcessor/ShippingChargesProcessor.php deleted file mode 100644 index 5b42c885..00000000 --- a/src/OrderProcessor/ShippingChargesProcessor.php +++ /dev/null @@ -1,80 +0,0 @@ -adjustmentFactory = $adjustmentFactory; - $this->shippingChargesCalculator = $shippingChargesCalculator; - } - - public function process(BaseOrderInterface $order): void - { - /** @var OrderInterface $order */ - Assert::isInstanceOf($order, OrderInterface::class); - - // Remove all shipping adjustments, we recalculate everything from scratch. - $order->removeAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT); - - /** @var ShipmentInterface $shipment */ - foreach ($order->getShipments() as $shipment) { - $shipment->removeAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT); - - try { - $shippingCharge = $this->shippingChargesCalculator->calculate($shipment); - $shippingMethod = $shipment->getMethod(); - Assert::notNull($shippingMethod); - - /** @var AdjustmentInterface $adjustment */ - $adjustment = $this->adjustmentFactory->createNew(); - $adjustment->setType(AdjustmentInterface::SHIPPING_ADJUSTMENT); - $adjustment->setAmount($shippingCharge); - $adjustment->setLabel($shippingMethod->getName()); - $adjustment->setDetails([ - 'shippingMethodCode' => $shippingMethod->getCode(), - 'shippingMethodName' => $shippingMethod->getName(), - ]); - - $shipment->addAdjustment($adjustment); - } catch (UndefinedShippingMethodException $exception) { - } - } - } -} diff --git a/src/PromotionAction/ShippingPercentageDiscountPromotionActionCommand.php b/src/PromotionAction/ShippingPercentageDiscountPromotionActionCommand.php deleted file mode 100644 index c916db79..00000000 --- a/src/PromotionAction/ShippingPercentageDiscountPromotionActionCommand.php +++ /dev/null @@ -1,131 +0,0 @@ -adjustmentFactory = $adjustmentFactory; - } - - public function execute(PromotionSubjectInterface $subject, array $configuration, PromotionInterface $promotion): bool - { - if (!$subject instanceof OrderInterface) { - throw new UnexpectedTypeException($subject, OrderInterface::class); - } - - if (!isset($configuration['percentage'])) { - return false; - } - - if (!$subject->hasShipments()) { - return false; - } - - $result = false; - /** @var ShipmentInterface $shipment */ - foreach ($subject->getShipments() as $shipment) { - $maxDiscount = $shipment->getAdjustmentsTotal(AdjustmentInterface::SHIPPING_ADJUSTMENT) + $shipment->getAdjustmentsTotal(AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT); - if ($maxDiscount < 0) { - continue; - } - - $adjustmentAmount = (int) round($shipment->getAdjustmentsTotal(AdjustmentInterface::SHIPPING_ADJUSTMENT) * $configuration['percentage']); - if (0 === $adjustmentAmount) { - continue; - } - - if ($maxDiscount < $adjustmentAmount) { - $adjustmentAmount = $maxDiscount; - } - - $adjustment = $this->createAdjustment($promotion); - $adjustment->setAmount(-$adjustmentAmount); - $shipment->addAdjustment($adjustment); - $result = true; - - } - - return $result; - } - - /** - * @throws UnexpectedTypeException - */ - public function revert(PromotionSubjectInterface $subject, array $configuration, PromotionInterface $promotion): void - { - if (!$subject instanceof OrderInterface) { - throw new UnexpectedTypeException($subject, OrderInterface::class); - } - - if (!$subject->hasShipments()) { - return; - } - - foreach ($subject->getAdjustments(AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT) as $adjustment) { - if ($promotion->getCode() === $adjustment->getOriginCode()) { - $subject->removeAdjustment($adjustment); - } - } - - /** @var ShipmentInterface $shipment */ - foreach ($subject->getShipments() as $shipment) { - $this->removePromotionFromShipment($promotion, $shipment); - } - } - - private function createAdjustment( - PromotionInterface $promotion, - string $type = AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT - ): OrderAdjustmentInterface { - /** @var OrderAdjustmentInterface $adjustment */ - $adjustment = $this->adjustmentFactory->createNew(); - $adjustment->setType($type); - $adjustment->setLabel($promotion->getName()); - $adjustment->setOriginCode($promotion->getCode()); - - return $adjustment; - } - - private function removePromotionFromShipment(PromotionInterface $promotion, ShipmentInterface $shipment): void - { - foreach ($shipment->getAdjustments(AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT) as $adjustment) { - if ($promotion->getCode() === $adjustment->getOriginCode()) { - $shipment->removeAdjustment($adjustment); - } - } - } -} diff --git a/src/Provider/RemainingTotalProvider.php b/src/Provider/RemainingTotalProvider.php index edbae3c4..e643f235 100644 --- a/src/Provider/RemainingTotalProvider.php +++ b/src/Provider/RemainingTotalProvider.php @@ -4,10 +4,10 @@ namespace Sylius\RefundPlugin\Provider; +use Sylius\Component\Core\Model\AdjustmentInterface; use Sylius\Component\Core\Model\OrderItemUnitInterface; use Sylius\Component\Order\Model\AdjustableInterface; use Sylius\Component\Resource\Repository\RepositoryInterface; -use Sylius\RefundPlugin\Entity\AdjustmentInterface; use Sylius\RefundPlugin\Entity\RefundInterface; use Sylius\RefundPlugin\Model\RefundType; use Webmozart\Assert\Assert; diff --git a/src/Provider/TaxRateProvider.php b/src/Provider/TaxRateProvider.php index 107bef30..5b3f4939 100644 --- a/src/Provider/TaxRateProvider.php +++ b/src/Provider/TaxRateProvider.php @@ -5,9 +5,8 @@ namespace Sylius\RefundPlugin\Provider; use Doctrine\Common\Collections\Collection; -use Sylius\Component\Core\Model\OrderItemUnitInterface; +use Sylius\Component\Core\Model\AdjustmentInterface; use Sylius\Component\Order\Model\AdjustableInterface; -use Sylius\RefundPlugin\Entity\AdjustmentInterface; use Sylius\RefundPlugin\Exception\MoreThanOneTaxAdjustment; use Webmozart\Assert\Assert; diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index 00bb3f3f..0de1024e 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -123,42 +123,5 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/TaxesApplicator/OrderItemUnitsTaxesApplicator.php b/src/TaxesApplicator/OrderItemUnitsTaxesApplicator.php deleted file mode 100644 index dc05eb0b..00000000 --- a/src/TaxesApplicator/OrderItemUnitsTaxesApplicator.php +++ /dev/null @@ -1,101 +0,0 @@ -calculator = $calculator; - $this->adjustmentFactory = $adjustmentFactory; - $this->taxRateResolver = $taxRateResolver; - } - - public function apply(OrderInterface $order, ZoneInterface $zone): void - { - foreach ($order->getItems() as $item) { - /** @var ProductVariantInterface|null $variant */ - $variant = $item->getVariant(); - Assert::notNull($variant); - - /** @var TaxRateInterface|null $taxRate */ - $taxRate = $this->taxRateResolver->resolve($variant, ['zone' => $zone]); - if (null === $taxRate) { - continue; - } - - /** @var OrderItemUnitInterface $unit */ - foreach ($item->getUnits() as $unit) { - $taxAmount = $this->calculator->calculate($unit->getTotal(), $taxRate); - if (0.00 === $taxAmount) { - continue; - } - - $this->addAdjustment($unit, (int) $taxAmount, $taxRate); - } - } - } - - private function addAdjustment(OrderItemUnitInterface $unit, int $taxAmount, TaxRateInterface $taxRate): void - { - /** @var string|null $label */ - $label = $taxRate->getLabel(); - Assert::notNull($label); - - /** @var AdjustmentInterface $unitTaxAdjustment */ - $unitTaxAdjustment = $this->adjustmentFactory->createWithData( - AdjustmentInterface::TAX_ADJUSTMENT, - $label, - $taxAmount, - $taxRate->isIncludedInPrice() - ); - $unitTaxAdjustment->setDetails([ - 'taxRateCode' => $taxRate->getCode(), - 'taxRateName' => $taxRate->getName(), - 'taxRateAmount' => $taxRate->getAmount(), - ]); - - $unit->addAdjustment($unitTaxAdjustment); - } -} diff --git a/src/TaxesApplicator/OrderItemsTaxesApplicator.php b/src/TaxesApplicator/OrderItemsTaxesApplicator.php deleted file mode 100644 index 11add5bb..00000000 --- a/src/TaxesApplicator/OrderItemsTaxesApplicator.php +++ /dev/null @@ -1,117 +0,0 @@ -calculator = $calculator; - $this->adjustmentFactory = $adjustmentFactory; - $this->distributor = $distributor; - $this->taxRateResolver = $taxRateResolver; - } - - /** - * @throws \InvalidArgumentException - */ - public function apply(OrderInterface $order, ZoneInterface $zone): void - { - foreach ($order->getItems() as $item) { - $quantity = $item->getQuantity(); - Assert::notSame($quantity, 0, 'Cannot apply tax to order item with 0 quantity.'); - - /** @var ProductVariantInterface|null $variant */ - $variant = $item->getVariant(); - Assert::notNull($variant); - - /** @var TaxRateInterface|null $taxRate */ - $taxRate = $this->taxRateResolver->resolve($variant, ['zone' => $zone]); - if (null === $taxRate) { - continue; - } - - $totalTaxAmount = $this->calculator->calculate($item->getTotal(), $taxRate); - $splitTaxes = $this->distributor->distribute($totalTaxAmount, $quantity); - - $i = 0; - /** @var OrderItemUnitInterface $unit */ - foreach ($item->getUnits() as $unit) { - if (0 === $splitTaxes[$i]) { - continue; - } - - $this->addAdjustment($unit, $splitTaxes[$i], $taxRate); - ++$i; - } - } - } - - private function addAdjustment(OrderItemUnitInterface $unit, int $taxAmount, TaxRateInterface $taxRate): void - { - /** @var string|null $label */ - $label = $taxRate->getLabel(); - Assert::notNull($label); - - /** @var AdjustmentInterface $unitTaxAdjustment */ - $unitTaxAdjustment = $this->adjustmentFactory->createWithData( - AdjustmentInterface::TAX_ADJUSTMENT, - $label, - $taxAmount, - $taxRate->isIncludedInPrice() - ); - $unitTaxAdjustment->setDetails([ - 'taxRateCode' => $taxRate->getCode(), - 'taxRateName' => $taxRate->getName(), - 'taxRateAmount' => $taxRate->getAmount(), - ]); - - $unit->addAdjustment($unitTaxAdjustment); - } -} diff --git a/src/TaxesApplicator/OrderShipmentTaxesApplicator.php b/src/TaxesApplicator/OrderShipmentTaxesApplicator.php deleted file mode 100644 index fa85ba15..00000000 --- a/src/TaxesApplicator/OrderShipmentTaxesApplicator.php +++ /dev/null @@ -1,124 +0,0 @@ -calculator = $calculator; - $this->adjustmentFactory = $adjustmentFactory; - $this->taxRateResolver = $taxRateResolver; - } - - public function apply(OrderInterface $order, ZoneInterface $zone): void - { - if (0 === $order->getShippingTotal()) { - return; - } - - if (!$order->hasShipments()) { - throw new \LogicException('Order should have at least one shipment.'); - } - - /** @var ShipmentInterface $shipment */ - foreach ($order->getShipments() as $shipment) { - $shippingMethod = $this->getShippingMethod($shipment); - - /** @var TaxRateInterface|null $taxRate */ - $taxRate = $this->taxRateResolver->resolve($shippingMethod, ['zone' => $zone]); - if (null === $taxRate) { - continue; - } - - $taxAmount = $this->calculator->calculate($shipment->getAdjustmentsTotal(), $taxRate); - if (0.00 === $taxAmount) { - continue; - } - - $this->addAdjustment($shipment, (int) $taxAmount, $taxRate, $shippingMethod); - } - } - - private function addAdjustment( - ShipmentInterface $shipment, - int $taxAmount, - TaxRateInterface $taxRate, - ShippingMethodInterface $shippingMethod - ): void { - /** @var string|null $label */ - $label = $taxRate->getLabel(); - Assert::notNull($label); - - /** @var AdjustmentInterface $adjustment */ - $adjustment = $this->adjustmentFactory->createWithData( - AdjustmentInterface::TAX_ADJUSTMENT, - $label, - $taxAmount, - $taxRate->isIncludedInPrice() - ); - $adjustment->setDetails([ - 'shippingMethodCode' => $shippingMethod->getCode(), - 'shippingMethodName' => $shippingMethod->getName(), - 'taxRateCode' => $taxRate->getCode(), - 'taxRateName' => $taxRate->getName(), - 'taxRateAmount' => $taxRate->getAmount(), - ]); - - $shipment->addAdjustment($adjustment); - } - - /** - * @throws \LogicException - */ - private function getShippingMethod(ShipmentInterface $shipment): ShippingMethodInterface - { - $method = $shipment->getMethod(); - - /** @var ShippingMethodInterface $method */ - Assert::isInstanceOf($method, ShippingMethodInterface::class); - - return $method; - } -} diff --git a/tests/Application/Kernel.php b/tests/Application/Kernel.php index 6038b297..b178ec11 100644 --- a/tests/Application/Kernel.php +++ b/tests/Application/Kernel.php @@ -41,15 +41,15 @@ public function getLogDir(): string public function registerBundles(): iterable { - foreach ($this->getConfigurationDirectories() as $confDir) { - yield from $this->registerBundlesFromFile($confDir . '/bundles.php'); + foreach ($this->getBundleListFiles() as $file) { + yield from $this->registerBundlesFromFile($file); } } protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void { - foreach ($this->getConfigurationDirectories() as $confDir) { - $container->addResource(new FileResource($confDir . '/bundles.php')); + foreach ($this->getBundleListFiles() as $file) { + $container->addResource(new FileResource($file)); } $container->setParameter('container.dumper.inline_class_loader', true); @@ -111,9 +111,29 @@ private function registerBundlesFromFile(string $bundlesFile): iterable /** * @return string[] */ - private function getConfigurationDirectories(): iterable + private function getBundleListFiles(): array { - yield $this->getProjectDir() . '/config'; - yield $this->getProjectDir() . '/config/sylius/' . SyliusKernel::MAJOR_VERSION . '.' . SyliusKernel::MINOR_VERSION; + return array_filter( + array_map( + static function (string $directory): string { + return $directory . '/bundles.php'; + }, + $this->getConfigurationDirectories() + ), + 'file_exists' + ); + } + + /** + * @return string[] + */ + private function getConfigurationDirectories(): array + { + $directories = [ + $this->getProjectDir() . '/config', + $this->getProjectDir() . '/config/sylius/' . SyliusKernel::MAJOR_VERSION . '.' . SyliusKernel::MINOR_VERSION, + ]; + + return array_filter($directories, 'file_exists'); } } diff --git a/tests/Application/config/bundles.php b/tests/Application/config/bundles.php index 9d9790cc..0e442acc 100644 --- a/tests/Application/config/bundles.php +++ b/tests/Application/config/bundles.php @@ -56,4 +56,6 @@ Sylius\Bundle\ApiBundle\SyliusApiBundle::class => ['all' => true], Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class => ['all' => true], SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true], + BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true], + SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true], ]; diff --git a/tests/Application/config/packages/_sylius.yaml b/tests/Application/config/packages/_sylius.yaml index aa0c8387..79f5ce6c 100644 --- a/tests/Application/config/packages/_sylius.yaml +++ b/tests/Application/config/packages/_sylius.yaml @@ -14,15 +14,3 @@ parameters: sylius_shop: product_grid: include_all_descendants: true - -sylius_order: - resources: - adjustment: - classes: - model: Tests\Sylius\RefundPlugin\Application\Entity\Adjustment - -sylius_shipping: - resources: - shipment: - classes: - model: Tests\Sylius\RefundPlugin\Application\Entity\Shipment diff --git a/tests/Application/config/sylius/1.9/packages/dev/jms_serializer.yaml b/tests/Application/config/packages/dev/jms_serializer.yaml similarity index 100% rename from tests/Application/config/sylius/1.9/packages/dev/jms_serializer.yaml rename to tests/Application/config/packages/dev/jms_serializer.yaml diff --git a/tests/Application/config/packages/doctrine.yaml b/tests/Application/config/packages/doctrine.yaml index 16257cdf..f51ba5a2 100644 --- a/tests/Application/config/packages/doctrine.yaml +++ b/tests/Application/config/packages/doctrine.yaml @@ -12,9 +12,3 @@ doctrine: charset: UTF8 url: '%env(resolve:DATABASE_URL)%' - orm: - mappings: - App: - type: annotation - dir: '%kernel.project_dir%/src/Entity' - prefix: Tests\Sylius\RefundPlugin\Application diff --git a/tests/Application/config/sylius/1.9/packages/jms_serializer.yaml b/tests/Application/config/packages/jms_serializer.yaml similarity index 100% rename from tests/Application/config/sylius/1.9/packages/jms_serializer.yaml rename to tests/Application/config/packages/jms_serializer.yaml diff --git a/tests/Application/config/sylius/1.9/packages/prod/jms_serializer.yaml b/tests/Application/config/packages/prod/jms_serializer.yaml similarity index 100% rename from tests/Application/config/sylius/1.9/packages/prod/jms_serializer.yaml rename to tests/Application/config/packages/prod/jms_serializer.yaml diff --git a/tests/Application/config/sylius/1.8/bundles.php b/tests/Application/config/sylius/1.8/bundles.php deleted file mode 100644 index 74ee2bc0..00000000 --- a/tests/Application/config/sylius/1.8/bundles.php +++ /dev/null @@ -1,6 +0,0 @@ - ['all' => true], - WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle::class => ['all' => true], -]; diff --git a/tests/Application/config/sylius/1.8/packages/dev/jms_serializer.yaml b/tests/Application/config/sylius/1.8/packages/dev/jms_serializer.yaml deleted file mode 100644 index 353e4602..00000000 --- a/tests/Application/config/sylius/1.8/packages/dev/jms_serializer.yaml +++ /dev/null @@ -1,7 +0,0 @@ -jms_serializer: - visitors: - json: - options: - - JSON_PRETTY_PRINT - - JSON_UNESCAPED_SLASHES - - JSON_PRESERVE_ZERO_FRACTION diff --git a/tests/Application/config/sylius/1.8/packages/framework.yaml b/tests/Application/config/sylius/1.8/packages/framework.yaml deleted file mode 100644 index 62f82d35..00000000 --- a/tests/Application/config/sylius/1.8/packages/framework.yaml +++ /dev/null @@ -1,2 +0,0 @@ -framework: - templating: { engines: ["twig"] } diff --git a/tests/Application/config/sylius/1.8/packages/jms_serializer.yaml b/tests/Application/config/sylius/1.8/packages/jms_serializer.yaml deleted file mode 100644 index 64dd8d10..00000000 --- a/tests/Application/config/sylius/1.8/packages/jms_serializer.yaml +++ /dev/null @@ -1,4 +0,0 @@ -jms_serializer: - visitors: - xml: - format_output: '%kernel.debug%' diff --git a/tests/Application/config/sylius/1.8/packages/prod/jms_serializer.yaml b/tests/Application/config/sylius/1.8/packages/prod/jms_serializer.yaml deleted file mode 100644 index bc97faf1..00000000 --- a/tests/Application/config/sylius/1.8/packages/prod/jms_serializer.yaml +++ /dev/null @@ -1,6 +0,0 @@ -jms_serializer: - visitors: - json: - options: - - JSON_UNESCAPED_SLASHES - - JSON_PRESERVE_ZERO_FRACTION diff --git a/tests/Application/config/sylius/1.8/routes/dev/twig.yaml b/tests/Application/config/sylius/1.8/routes/dev/twig.yaml deleted file mode 100644 index f4ee8396..00000000 --- a/tests/Application/config/sylius/1.8/routes/dev/twig.yaml +++ /dev/null @@ -1,3 +0,0 @@ -_errors: - resource: '@TwigBundle/Resources/config/routing/errors.xml' - prefix: /_error diff --git a/tests/Application/config/sylius/1.9/bundles.php b/tests/Application/config/sylius/1.9/bundles.php deleted file mode 100644 index bd33f4ae..00000000 --- a/tests/Application/config/sylius/1.9/bundles.php +++ /dev/null @@ -1,6 +0,0 @@ - ['all' => true], - SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true], -]; diff --git a/tests/Application/src/Entity/Adjustment.php b/tests/Application/src/Entity/Adjustment.php deleted file mode 100644 index 417623b5..00000000 --- a/tests/Application/src/Entity/Adjustment.php +++ /dev/null @@ -1,28 +0,0 @@ - $this->adjustments */ - $this->adjustments = new ArrayCollection(); - } -} diff --git a/tests/Behat/Context/Setup/RefundingContext.php b/tests/Behat/Context/Setup/RefundingContext.php index a8d72b63..4085fe12 100644 --- a/tests/Behat/Context/Setup/RefundingContext.php +++ b/tests/Behat/Context/Setup/RefundingContext.php @@ -9,9 +9,9 @@ use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\Model\OrderItemUnitInterface; use Sylius\Component\Core\Model\PaymentMethodInterface; +use Sylius\Component\Core\Model\ShipmentInterface; use Sylius\Component\Core\Repository\OrderRepositoryInterface; use Sylius\RefundPlugin\Command\RefundUnits; -use Sylius\RefundPlugin\Entity\ShipmentInterface; use Sylius\RefundPlugin\Model\OrderItemUnitRefund; use Sylius\RefundPlugin\Model\ShipmentRefund; use Symfony\Component\Messenger\MessageBusInterface;