Skip to content

Commit

Permalink
Merge pull request #992 from bavix/990-how-to-disable-auto-create-wal…
Browse files Browse the repository at this point in the history
…let-behavior

[11.x] fixed automatic wallet creation when calling float balance
  • Loading branch information
rez1dent3 authored Sep 10, 2024
2 parents a88e98c + 1861715 commit fe4029b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Traits/HasWalletFloat.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public function forceTransferFloat(
public function getBalanceFloatAttribute(): string
{
// Get the wallet.
$wallet = app(CastServiceInterface::class)->getWallet($this);
$wallet = app(CastServiceInterface::class)->getWallet($this, false);

// Get the wallet balance.
/** @var non-empty-string $balance */
Expand Down
19 changes: 19 additions & 0 deletions tests/Units/Domain/BalanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@
*/
final class BalanceTest extends TestCase
{
public function testBalanceWalletNotExists(): void
{
/** @var Buyer $buyer */
$buyer = BuyerFactory::new()->create();
self::assertFalse($buyer->relationLoaded('wallet'));

self::assertSame(0, (int) $buyer->wallet->balance);
self::assertFalse($buyer->wallet->exists);

self::assertSame(0, $buyer->wallet->balanceInt);
self::assertFalse($buyer->wallet->exists);

self::assertSame(0., (float) $buyer->wallet->balanceFloat);
self::assertFalse($buyer->wallet->exists);

self::assertSame(0., $buyer->wallet->balanceFloatNum);
self::assertFalse($buyer->wallet->exists);
}

public function testDepositWalletExists(): void
{
/** @var Buyer $buyer */
Expand Down

0 comments on commit fe4029b

Please sign in to comment.