Skip to content

Commit a61f52e

Browse files
committed
fixed automatic wallet creation when calling float balance
1 parent 56a7765 commit a61f52e

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/Traits/HasWalletFloat.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public function forceTransferFloat(
148148
public function getBalanceFloatAttribute(): string
149149
{
150150
$math = app(MathServiceInterface::class);
151-
$wallet = app(CastServiceInterface::class)->getWallet($this);
151+
$wallet = app(CastServiceInterface::class)->getWallet($this, false);
152152
$decimalPlacesValue = $wallet->decimal_places;
153153
$decimalPlaces = $math->powTen($decimalPlacesValue);
154154

tests/Units/Domain/BalanceTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,25 @@
1919
*/
2020
final class BalanceTest extends TestCase
2121
{
22+
public function testBalanceWalletNotExists()
23+
{
24+
/** @var Buyer $buyer */
25+
$buyer = BuyerFactory::new()->create();
26+
self::assertFalse($buyer->relationLoaded('wallet'));
27+
28+
self::assertSame(0, (int) $buyer->wallet->balance);
29+
self::assertFalse($buyer->wallet->exists);
30+
31+
self::assertSame(0, $buyer->wallet->balanceInt);
32+
self::assertFalse($buyer->wallet->exists);
33+
34+
self::assertSame(0., (float)$buyer->wallet->balanceFloat);
35+
self::assertFalse($buyer->wallet->exists);
36+
37+
self::assertSame(0., $buyer->wallet->balanceFloatNum);
38+
self::assertFalse($buyer->wallet->exists);
39+
}
40+
2241
public function testDepositWalletExists(): void
2342
{
2443
/** @var Buyer $buyer */

0 commit comments

Comments
 (0)