Skip to content

Commit 1ecdf11

Browse files
keatliang2005rez1dent3
authored andcommitted
Transaction float accessor fix test
1 parent 1a332e3 commit 1ecdf11

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bavix\Wallet\Test\Units\Domain;
6+
7+
use Bavix\Wallet\Test\Infra\Factories\UserMultiFactory;
8+
use Bavix\Wallet\Test\Infra\Models\UserMulti;
9+
use Bavix\Wallet\Test\Infra\TestCase;
10+
11+
/**
12+
* @internal
13+
*/
14+
final class TransactionAmountFloatAccessorTest extends TestCase
15+
{
16+
/**
17+
* @see https://github.com/bavix/laravel-wallet/pull/533
18+
*/
19+
public function testTransactionAmountFloatAccessor(): void
20+
{
21+
/** @var UserMulti $user */
22+
$user = UserMultiFactory::new()->create();
23+
24+
// two decimal
25+
$twoDecimalWallet = $user->createWallet([
26+
'name' => '2 Floating point',
27+
'slug' => '2-floating-point',
28+
'decimal_places' => 2,
29+
]);
30+
31+
$amountTwoDecimal = 1.11;
32+
$twoDecimalTransaction = $twoDecimalWallet->depositFloat($amountTwoDecimal);
33+
34+
self::assertNotNull($twoDecimalTransaction);
35+
self::assertSame($amountTwoDecimal, (float) $twoDecimalTransaction->amountFloat, 'amount float is same decimal places');
36+
37+
// four decimal
38+
$fourDecimalWallet = $user->createWallet([
39+
'name' => '4 Floating point',
40+
'slug' => '4-floating-point',
41+
'decimal_places' => 4,
42+
]);
43+
44+
$amountFourDecimal = 1.1111;
45+
$fourDecimalTransaction = $fourDecimalWallet->depositFloat($amountFourDecimal);
46+
47+
self::assertNotNull($fourDecimalTransaction);
48+
self::assertSame($amountFourDecimal, (float) $fourDecimalTransaction->amountFloat, 'amount float is same decimal places');
49+
}
50+
}

0 commit comments

Comments
 (0)