Refactor money value formatting

Do not duplicate code and send string value for JPY
This commit is contained in:
Alex P 2022-07-07 12:34:21 +03:00
parent 67cdf9be8e
commit 82adf1933f
5 changed files with 84 additions and 18 deletions

View file

@ -22,9 +22,7 @@ class AmountTest extends TestCase
public function testBreakdownIsNull()
{
$money = Mockery::mock(Money::class);
$money->shouldReceive('currency_code')->andReturn('currencyCode');
$money->shouldReceive('value')->andReturn(1.10);
$money = new Money(1.10, 'currencyCode');
$testee = new Amount($money);
$this->assertNull($testee->breakdown());
@ -38,9 +36,7 @@ class AmountTest extends TestCase
public function testBreakdown()
{
$money = Mockery::mock(Money::class);
$money->shouldReceive('currency_code')->andReturn('currencyCode');
$money->shouldReceive('value')->andReturn(1.10);
$money = new Money(1.10, 'currencyCode');
$breakdown = Mockery::mock(AmountBreakdown::class);
$breakdown->shouldReceive('to_array')->andReturn([1]);
$testee = new Amount($money, $breakdown);

View file

@ -334,6 +334,25 @@ class PurchaseUnitTest extends TestCase
],
]),
];
yield 'no decimals currency' => [
[
'currency' => 'JPY',
'items' => [
['price' => 18.0, 'quantity' => 2],
],
'shipping' => ['total' => 5.0],
'billing' => ['city' => 'city2'],
],
self::adaptAmountFormat([
'value' => 66,
'breakdown' => [
'item_total' => 36,
'tax_total' => 25, // 24.60
'shipping' => 5,
],
], 'JPY'),
];
}
public function cartData() {