From ebf17b9df6625cd340b9b0740019843ba15f8cb5 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Tue, 10 Sep 2024 19:55:34 +0300 Subject: [PATCH 1/3] fixed automatic wallet creation when calling float balance --- src/Traits/HasWalletFloat.php | 2 +- tests/Units/Domain/BalanceTest.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Traits/HasWalletFloat.php b/src/Traits/HasWalletFloat.php index adb8decf8..a624363d8 100644 --- a/src/Traits/HasWalletFloat.php +++ b/src/Traits/HasWalletFloat.php @@ -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 */ diff --git a/tests/Units/Domain/BalanceTest.php b/tests/Units/Domain/BalanceTest.php index a202e39d8..92796a6af 100644 --- a/tests/Units/Domain/BalanceTest.php +++ b/tests/Units/Domain/BalanceTest.php @@ -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 */ From e5bf1091b4dfe8ff3eda9bace3218304f01a7c04 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Tue, 10 Sep 2024 20:16:29 +0300 Subject: [PATCH 2/3] fix --- tests/Units/Domain/BalanceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Units/Domain/BalanceTest.php b/tests/Units/Domain/BalanceTest.php index 92796a6af..9e37b081a 100644 --- a/tests/Units/Domain/BalanceTest.php +++ b/tests/Units/Domain/BalanceTest.php @@ -19,7 +19,7 @@ */ final class BalanceTest extends TestCase { - public function testBalanceWalletNotExists() + public function testBalanceWalletNotExists(): void { /** @var Buyer $buyer */ $buyer = BuyerFactory::new()->create(); From 186171541081d40846c80556ca30206d49b0f43b Mon Sep 17 00:00:00 2001 From: Github bot Date: Tue, 10 Sep 2024 17:20:22 +0000 Subject: [PATCH 3/3] autofix --- tests/Units/Domain/BalanceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Units/Domain/BalanceTest.php b/tests/Units/Domain/BalanceTest.php index 9e37b081a..383123f4c 100644 --- a/tests/Units/Domain/BalanceTest.php +++ b/tests/Units/Domain/BalanceTest.php @@ -31,7 +31,7 @@ public function testBalanceWalletNotExists(): void self::assertSame(0, $buyer->wallet->balanceInt); self::assertFalse($buyer->wallet->exists); - self::assertSame(0., (float)$buyer->wallet->balanceFloat); + self::assertSame(0., (float) $buyer->wallet->balanceFloat); self::assertFalse($buyer->wallet->exists); self::assertSame(0., $buyer->wallet->balanceFloatNum);