Skip to content

Commit e66a166

Browse files
committed
Update tests to handle multiple neutral tax rates and adjust calculations accordingly.
1 parent cf58c66 commit e66a166

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

features/managing_invoices/seeing_invoice_with_taxes_included_in_price.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Feature: Seeing included in price taxes on an invoice
2626
When I view the summary of the invoice for order "#00000666"
2727
Then it should have 2 "PHP T-Shirt" items with unit net price "48.78", discounted unit net price "48.78", net value "97.56", tax total "22.44" and total "120.00" in "USD" currency
2828
And it should have 2 "Symfony Mug" items with unit net price "36.36", discounted unit net price "36.36", net value "72.72", tax total "7.28" and total "80.00" in "USD" currency
29-
And it should have 1 "Symfony Mug" items with unit net price "36.37", discounted unit net price "36.37", net value "36.37", tax total "3.63" and total "40.00" in "USD" currency
29+
And it should have 1 "Symfony Mug" items with unit net price "36.36", discounted unit net price "36.37", net value "36.37", tax total "3.63" and total "40.00" in "USD" currency
3030
And it should have a tax item "23%" with amount "22.44" in "USD" currency
3131
And it should have a tax item "10%" with amount "10.91" in "USD" currency
3232
And its net total should be "216.65" in "USD" currency

features/managing_invoices/seeing_invoice_with_taxes_included_in_price_and_promotions_applied.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ Feature: Seeing included in price taxes and promotions applied on an invoice
2222

2323
Scenario: Seeing proper taxes and promotions on an invoice
2424
When I view the summary of the invoice for order "#00000666"
25-
Then it should have 2 "PHP T-Shirt" items with unit net price "50.65", discounted unit net price "40.65", net value "81.30", tax total "18.70" and total "100.00" in "USD" currency
25+
Then it should have 2 "PHP T-Shirt" items with unit net price "48.78", discounted unit net price "40.65", net value "81.30", tax total "18.70" and total "100.00" in "USD" currency
2626
And it should have a tax item "23%" with amount "18.70" in "USD" currency
2727
And its total should be "110.00" in "USD" currency

src/Provider/UnitNetPriceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ public function getUnitNetPrice(OrderItemUnitInterface $orderItemUnit): int
4242

4343
$taxDivisor = 1.0 + $taxRate;
4444

45-
return (int) round($unitPrice / $taxDivisor, 0, PHP_ROUND_HALF_UP);
45+
return (int) round($unitPrice / $taxDivisor, 0, \PHP_ROUND_HALF_UP);
4646
}
4747
}

tests/Unit/Provider/UnitNetPriceProviderTest.php

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,19 @@ public function it_provides_net_price_for_unit_with_taxes_included_in_price(): v
4646
$taxAdjustment = $this->createMock(AdjustmentInterface::class);
4747

4848
$unit->method('getOrderItem')->willReturn($orderItem);
49-
$orderItem->method('getUnitPrice')->willReturn(1000);
49+
$orderItem->method('getUnitPrice')->willReturn(1200);
5050

5151
$unit
5252
->method('getAdjustments')
5353
->with(AdjustmentInterface::TAX_ADJUSTMENT)
5454
->willReturn(new ArrayCollection([$taxAdjustment]));
5555

5656
$taxAdjustment->method('isNeutral')->willReturn(true);
57-
$taxAdjustment->method('getAmount')->willReturn(200);
57+
$taxAdjustment->method('getDetails')->willReturn(['taxRateAmount' => 0.20]);
5858

5959
$result = $this->provider->getUnitNetPrice($unit);
6060

61-
self::assertSame(800, $result);
61+
self::assertSame(1000, $result);
6262
}
6363

6464
#[Test]
@@ -77,10 +77,36 @@ public function it_provides_net_price_for_unit_with_taxes_excluded_of_price(): v
7777
->willReturn(new ArrayCollection([$taxAdjustment]));
7878

7979
$taxAdjustment->method('isNeutral')->willReturn(false);
80-
$taxAdjustment->method('getAmount')->willReturn(200);
8180

8281
$result = $this->provider->getUnitNetPrice($unit);
8382

8483
self::assertSame(1000, $result);
8584
}
85+
86+
#[Test]
87+
public function it_supports_multiple_neutral_tax_rates_by_summing_them(): void
88+
{
89+
$unit = $this->createMock(OrderItemUnitInterface::class);
90+
$orderItem = $this->createMock(OrderItemInterface::class);
91+
$taxAdj1 = $this->createMock(AdjustmentInterface::class);
92+
$taxAdj2 = $this->createMock(AdjustmentInterface::class);
93+
94+
$unit->method('getOrderItem')->willReturn($orderItem);
95+
$orderItem->method('getUnitPrice')->willReturn(1000);
96+
97+
$unit
98+
->method('getAdjustments')
99+
->with(AdjustmentInterface::TAX_ADJUSTMENT)
100+
->willReturn(new ArrayCollection([$taxAdj1, $taxAdj2]));
101+
102+
$taxAdj1->method('isNeutral')->willReturn(true);
103+
$taxAdj1->method('getDetails')->willReturn(['taxRateAmount' => 0.05]);
104+
105+
$taxAdj2->method('isNeutral')->willReturn(true);
106+
$taxAdj2->method('getDetails')->willReturn(['taxRateAmount' => 0.025]);
107+
108+
$result = $this->provider->getUnitNetPrice($unit);
109+
110+
self::assertSame(930, $result);
111+
}
86112
}

0 commit comments

Comments
 (0)