mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
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:
parent
82adf1933f
commit
2ca64739db
3 changed files with 41 additions and 24 deletions
|
@ -412,10 +412,8 @@ class PurchaseUnitTest extends TestCase
|
|||
foreach ($data as $testKey => $test) {
|
||||
$items = [];
|
||||
foreach ($test['items'] as $key => $item) {
|
||||
$unitAmount = Mockery::mock(Money::class);
|
||||
$unitAmount->shouldReceive('value')->andReturn($item['value']);
|
||||
$tax = Mockery::mock(Money::class);
|
||||
$tax->shouldReceive('value')->andReturn($item['tax']);
|
||||
$unitAmount = new Money($item['value'], 'EUR');
|
||||
$tax = new Money($item['tax'], 'EUR');
|
||||
$items[$key] = Mockery::mock(
|
||||
Item::class,
|
||||
[
|
||||
|
@ -436,15 +434,14 @@ class PurchaseUnitTest extends TestCase
|
|||
return null;
|
||||
}
|
||||
|
||||
$money = Mockery::mock(Money::class);
|
||||
$money->shouldReceive('value')->andReturn($value);
|
||||
$money = new Money($value, 'EUR');
|
||||
return $money;
|
||||
});
|
||||
}
|
||||
}
|
||||
$amount = Mockery::mock(Amount::class);
|
||||
$amount->shouldReceive('to_array')->andReturn(['value' => number_format( $test['amount'], 2, '.', '' ), 'breakdown' => []]);
|
||||
$amount->shouldReceive('value')->andReturn($test['amount']);
|
||||
$amount->shouldReceive('value_str')->andReturn(number_format( $test['amount'], 2, '.', '' ));
|
||||
$amount->shouldReceive('currency_code')->andReturn('EUR');
|
||||
$amount->shouldReceive('breakdown')->andReturn($breakdown);
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue