Use str value when checking mismatch

Otherwise the check may fail depending on the rounding used when creating the Money objects
This commit is contained in:
Alex P 2022-07-07 12:36:14 +03:00
parent 82adf1933f
commit 2ca64739db
3 changed files with 41 additions and 24 deletions

View file

@ -68,8 +68,6 @@ class PurchaseUnitTest extends TestCase
$pu = $this->puFactory->from_wc_order($wcOrder);
$puData = $pu->to_array();
self::assertTrue(isset($puData['amount']['breakdown']));
self::assertEquals($expectedAmount, $puData['amount']);
}
@ -83,8 +81,6 @@ class PurchaseUnitTest extends TestCase
$pu = $this->puFactory->from_wc_cart($this->cart);
$puData = $pu->to_array();
self::assertTrue(isset($puData['amount']['breakdown']));
self::assertEquals($expectedAmount, $puData['amount']);
}
@ -353,6 +349,18 @@ class PurchaseUnitTest extends TestCase
],
], 'JPY'),
];
yield [
[
'items' => [
['price' => 5.345, 'quantity' => 2],
],
'billing' => ['city' => 'city0'],
],
self::adaptAmountFormat([
'value' => 10.69,
]),
];
}
public function cartData() {
@ -409,6 +417,18 @@ class PurchaseUnitTest extends TestCase
],
], get_woocommerce_currency()),
];
yield [
[
'products' => [
['price' => 5.345, 'quantity' => 2],
],
'billing' => ['city' => 'city0'],
],
self::adaptAmountFormat([
'value' => 10.69,
], get_woocommerce_currency()),
];
}
private static function adaptAmountFormat(array $data, string $currency = null): array {