Skip to content

Commit

Permalink
fix(Price): GetValue
Browse files Browse the repository at this point in the history
  • Loading branch information
4513 committed May 4, 2024
1 parent 5a6f5fa commit 4c0e581
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./vendor/autoload.php" colors="true" enforceTimeLimit="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd" cacheDirectory=".phpunit.cache" requireCoverageMetadata="true">
<testsuites>
<testsuite name="Core Tests">
<directory suffix=".php">./tests/Core/</directory>
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<coverage/>
Expand Down
4 changes: 2 additions & 2 deletions src/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public function __clone(): void
* VAT: string,
* time: string|null,
* details: array{
* unit: \MiBo\Prices\Units\Price\Currency,
* unit: array<mixed>,
* VAT: \MiBo\VAT\VAT,
* prices: array<\MiBo\Prices\Contracts\PriceInterface>
* }
Expand All @@ -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(),
],
Expand Down
57 changes: 57 additions & 0 deletions tests/Issues/Issue005Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace MiBo\Prices\Tests\Issues;

use MiBo\Prices\Price;
use MiBo\Prices\Tests\VATResolver;
use MiBo\Prices\Units\Price\Currency;
use PHPUnit\Framework\TestCase;

/**
* Class Issue005Test
*
* @package MiBo\Prices\Tests\Issues
*
* @author Michal Boris <[email protected]>
*
* @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());
}
}

0 comments on commit 4c0e581

Please sign in to comment.