From 7cbe208b4f14f359861fdbf70a1ba79c6df3cd18 Mon Sep 17 00:00:00 2001 From: Babichev Maxim Date: Mon, 17 Jun 2019 13:43:34 +0300 Subject: [PATCH 1/4] fix --- src/Services/WalletService.php | 2 +- tests/BalanceTest.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Services/WalletService.php b/src/Services/WalletService.php index 96348b254..723986deb 100644 --- a/src/Services/WalletService.php +++ b/src/Services/WalletService.php @@ -67,7 +67,7 @@ public function getBalance(Wallet $object): int $wallet->exists or $wallet->save(); $proxy = app(ProxyService::class); if (!$proxy->has($wallet->getKey())) { - $proxy->set($wallet->getKey(), (int)($wallet->attributes['balance'] ?? 0)); + $proxy->set($wallet->getKey(), (int)$wallet->getOriginal('balance', 0)); } return $proxy[$wallet->getKey()]; diff --git a/tests/BalanceTest.php b/tests/BalanceTest.php index 0ce2a0e4d..d23c7c94e 100644 --- a/tests/BalanceTest.php +++ b/tests/BalanceTest.php @@ -3,8 +3,10 @@ namespace Bavix\Wallet\Test; use Bavix\Wallet\Services\CommonService; +use Bavix\Wallet\Services\ProxyService; use Bavix\Wallet\Test\Models\Buyer; use function app; +use Illuminate\Support\Facades\DB; class BalanceTest extends TestCase { @@ -45,4 +47,30 @@ public function testSimple(): void $this->assertEquals($wallet->balance, 1001); } + /** + * @return void + * @see https://github.com/bavix/laravel-wallet/issues/49 + */ + public function testForceUpdate(): void + { + /** + * @var Buyer $buyer + */ + $buyer = factory(Buyer::class)->create(); + $wallet = $buyer->wallet; + + $this->assertEquals($wallet->balance, 0); + + $wallet->deposit(1000); + $this->assertEquals($wallet->balance, 1000); + + $buyer->wallet->update(['balance' => 10]); + app(ProxyService::class)->fresh(); + + $this->assertEquals($wallet->balance, 10); + $wallet->refreshBalance(); + + $this->assertEquals($wallet->balance, 1000); + } + } From 937b584d0ffe829aed922ac8f650d22053b701d9 Mon Sep 17 00:00:00 2001 From: Babichev Maxim Date: Mon, 17 Jun 2019 13:49:14 +0300 Subject: [PATCH 2/4] fix unit-test --- tests/BalanceTest.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/BalanceTest.php b/tests/BalanceTest.php index d23c7c94e..cd1d72516 100644 --- a/tests/BalanceTest.php +++ b/tests/BalanceTest.php @@ -2,6 +2,7 @@ namespace Bavix\Wallet\Test; +use Bavix\Wallet\Models\Wallet; use Bavix\Wallet\Services\CommonService; use Bavix\Wallet\Services\ProxyService; use Bavix\Wallet\Test\Models\Buyer; @@ -64,12 +65,15 @@ public function testForceUpdate(): void $wallet->deposit(1000); $this->assertEquals($wallet->balance, 1000); - $buyer->wallet->update(['balance' => 10]); + Wallet::whereKey($buyer->wallet->getKey()) + ->update(['balance' => 10]); + app(ProxyService::class)->fresh(); + $wallet->refresh(); $this->assertEquals($wallet->balance, 10); - $wallet->refreshBalance(); + $wallet->refreshBalance(); $this->assertEquals($wallet->balance, 1000); } From b347120f4a4adf5416d3f30aa4f3f429a09ebdb1 Mon Sep 17 00:00:00 2001 From: Babichev Maxim Date: Mon, 17 Jun 2019 13:51:13 +0300 Subject: [PATCH 3/4] update phpDoc --- tests/BalanceTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/BalanceTest.php b/tests/BalanceTest.php index cd1d72516..7ca8127de 100644 --- a/tests/BalanceTest.php +++ b/tests/BalanceTest.php @@ -7,13 +7,13 @@ use Bavix\Wallet\Services\ProxyService; use Bavix\Wallet\Test\Models\Buyer; use function app; -use Illuminate\Support\Facades\DB; class BalanceTest extends TestCase { /** * @return void + * @throws */ public function testSimple(): void { @@ -72,7 +72,7 @@ public function testForceUpdate(): void $wallet->refresh(); $this->assertEquals($wallet->balance, 10); - + $wallet->refreshBalance(); $this->assertEquals($wallet->balance, 1000); } From af13c4937e4d9e6f04c64800e2ef16eeab223491 Mon Sep 17 00:00:00 2001 From: Babichev Maxim Date: Mon, 17 Jun 2019 13:54:13 +0300 Subject: [PATCH 4/4] add changelog --- changelog.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 4d7022d40..b54970c1a 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [3.0.1] - 2019-06-17 +### Fixed +- The shortened syntax for getting the balance did not work. + ## [3.0.0] - 2019-05-25 ### Added - Add service `CommonService` @@ -294,7 +298,8 @@ The operation is now executed in the transaction and updates the new `refund` fi - Exceptions: AmountInvalid, BalanceIsEmpty. - Models: Transfer, Transaction. -[Unreleased]: https://github.com/bavix/laravel-wallet/compare/3.0.0...HEAD +[Unreleased]: https://github.com/bavix/laravel-wallet/compare/3.0.1...HEAD +[3.0.1]: https://github.com/bavix/laravel-wallet/compare/3.0.0...3.0.1 [3.0.0]: https://github.com/bavix/laravel-wallet/compare/2.4.1...3.0.0 [2.4.1]: https://github.com/bavix/laravel-wallet/compare/2.4.0...2.4.1 [2.4.0]: https://github.com/bavix/laravel-wallet/compare/2.3.2...2.4.0