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 56a7765 commit a61f52e
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 @@ -148,7 +148,7 @@ public function forceTransferFloat(
public function getBalanceFloatAttribute(): string
{
$math = app(MathServiceInterface::class);

Check warning on line 150 in src/Traits/HasWalletFloat.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined function

Undefined function 'app'
$wallet = app(CastServiceInterface::class)->getWallet($this);
$wallet = app(CastServiceInterface::class)->getWallet($this, false);

Check warning on line 151 in src/Traits/HasWalletFloat.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined function

Undefined function 'app'
$decimalPlacesValue = $wallet->decimal_places;
$decimalPlaces = $math->powTen($decimalPlacesValue);

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()
{
/** @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 a61f52e

Please sign in to comment.