Use BigDecimal for Pricedetail price field.

This commit is contained in:
Jan Böhmer 2020-05-20 22:02:07 +02:00
parent db4d7dc5fc
commit b1db89e3b4
8 changed files with 116 additions and 49 deletions

View file

@ -59,6 +59,6 @@ class CurrencyTest extends TestCase
$this->assertNull($currency->getInverseExchangeRate());
$currency->setExchangeRate(BigDecimal::of('1.45643'));
$this->assertSame(BigDecimal::of('0.68661'), $currency->getInverseExchangeRate());
$this->assertSame((string) BigDecimal::of('0.68661'), (string) $currency->getInverseExchangeRate());
}
}

View file

@ -45,6 +45,7 @@ namespace App\Tests\Entity\PriceSystem;
use App\Entity\Parts\Part;
use App\Entity\PriceInformations\Orderdetail;
use App\Entity\PriceInformations\Pricedetail;
use Brick\Math\BigDecimal;
use PHPUnit\Framework\TestCase;
class PricedetailTest extends TestCase
@ -52,17 +53,17 @@ class PricedetailTest extends TestCase
public function testGetPricePerUnit(): void
{
$pricedetail = new Pricedetail();
$pricedetail->setPrice('100.234');
$pricedetail->setPrice(BigDecimal::of('100.234'));
$this->assertSame('100.23400', $pricedetail->getPricePerUnit());
$this->assertSame('100.23400', (string) $pricedetail->getPricePerUnit());
$pricedetail->setPriceRelatedQuantity(2.3);
$this->assertSame('43.58000', $pricedetail->getPricePerUnit());
$this->assertSame('139.45600', $pricedetail->getPricePerUnit('3.2'));
$this->assertSame('43.58000', (string) $pricedetail->getPricePerUnit());
$this->assertSame('139.45600', (string) $pricedetail->getPricePerUnit('3.2'));
$pricedetail->setPrice('10000000.2345'); //Ten million
$pricedetail->setPrice(BigDecimal::of('10000000.2345')); //Ten million
$pricedetail->setPriceRelatedQuantity(1.234e9); //100 billion
$this->assertSame('0.00810', $pricedetail->getPricePerUnit());
$this->assertSame('0.00810', (string) $pricedetail->getPricePerUnit());
}
public function testGetPriceRelatedQuantity(): void