Skip to content

Commit

Permalink
fixed automatic wallet creation when calling float balance
Browse files Browse the repository at this point in the history
  • Loading branch information
rez1dent3 committed Sep 10, 2024
1 parent a88e98c commit ebf17b9
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()

Check failure on line 22 in tests/Units/Domain/BalanceTest.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Bavix\Wallet\Test\Units\Domain\BalanceTest::testBalanceWalletNotExists() has no return type specified.
{
/** @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 ebf17b9

Please sign in to comment.