From 4c0e5818b60805da0eb3f22bfc4939ba9dd7f5c1 Mon Sep 17 00:00:00 2001 From: MiBo Date: Sat, 4 May 2024 18:49:15 +0200 Subject: [PATCH] fix(Price): GetValue --- phpunit.xml.dist | 2 +- src/Price.php | 4 +-- tests/Issues/Issue005Test.php | 57 +++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 tests/Issues/Issue005Test.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c91ce27..6321add 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,7 +2,7 @@ - ./tests/Core/ + ./tests diff --git a/src/Price.php b/src/Price.php index d79f698..d5bd0d5 100644 --- a/src/Price.php +++ b/src/Price.php @@ -315,7 +315,7 @@ public function __clone(): void * VAT: string, * time: string|null, * details: array{ - * unit: \MiBo\Prices\Units\Price\Currency, + * unit: array, * VAT: \MiBo\VAT\VAT, * prices: array<\MiBo\Prices\Contracts\PriceInterface> * } @@ -331,7 +331,7 @@ public function __debugInfo(): array 'VAT' => $this->getVAT()->getRate()->name, 'time' => $this->getDateTime()->format(DateTime::ATOM), 'details' => [ - 'unit' => $this->getUnit(), + 'unit' => $this->getUnit()->__debugInfo(), 'VAT' => $this->getVAT(), 'prices' => $this->getNestedPrices(), ], diff --git a/tests/Issues/Issue005Test.php b/tests/Issues/Issue005Test.php new file mode 100644 index 0000000..39ae159 --- /dev/null +++ b/tests/Issues/Issue005Test.php @@ -0,0 +1,57 @@ + + * + * @since 2.0.1 + * + * @no-named-arguments Parameter names are not covered by the backward compatibility promise. + */ +final class Issue005Test extends TestCase +{ + /** + * @small + * + * @coversNothing + * + * @return void + */ + public function test(): void + { + $price = new Price(100, Currency::get('EUR'), VATResolver::retrieveByCategory('1', 'SVK')); + + self::assertEquals(100, $price->getValue()); + self::assertEquals(100, $price->getValue()); + + $newPrice = new Price(100, Currency::get('EUR'), VATResolver::retrieveByCategory('1', 'SVK')); + + self::assertEquals(100, $newPrice->getValue()); + self::assertEquals(100, $newPrice->getValue()); + + $combined = $price->add($newPrice); + + self::assertEquals(200, $combined->getValue()); + self::assertEquals(200, $combined->getValue()); + self::assertEquals(200, $price->getValue()); + + $differentVat = new Price(100, Currency::get('EUR'), VATResolver::retrieveByCategory('2', 'SVK')); + + $price->add($differentVat); + + self::assertEquals(300, $price->getValue()); + self::assertEquals(360, $price->getValueWithVAT()); + } +}