Skip to content

Commit 7cbe208

Browse files
author
Babichev Maxim
committed
fix
1 parent 6aa2cff commit 7cbe208

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/Services/WalletService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function getBalance(Wallet $object): int
6767
$wallet->exists or $wallet->save();
6868
$proxy = app(ProxyService::class);
6969
if (!$proxy->has($wallet->getKey())) {
70-
$proxy->set($wallet->getKey(), (int)($wallet->attributes['balance'] ?? 0));
70+
$proxy->set($wallet->getKey(), (int)$wallet->getOriginal('balance', 0));
7171
}
7272

7373
return $proxy[$wallet->getKey()];

tests/BalanceTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
namespace Bavix\Wallet\Test;
44

55
use Bavix\Wallet\Services\CommonService;
6+
use Bavix\Wallet\Services\ProxyService;
67
use Bavix\Wallet\Test\Models\Buyer;
78
use function app;
9+
use Illuminate\Support\Facades\DB;
810

911
class BalanceTest extends TestCase
1012
{
@@ -45,4 +47,30 @@ public function testSimple(): void
4547
$this->assertEquals($wallet->balance, 1001);
4648
}
4749

50+
/**
51+
* @return void
52+
* @see https://github.com/bavix/laravel-wallet/issues/49
53+
*/
54+
public function testForceUpdate(): void
55+
{
56+
/**
57+
* @var Buyer $buyer
58+
*/
59+
$buyer = factory(Buyer::class)->create();
60+
$wallet = $buyer->wallet;
61+
62+
$this->assertEquals($wallet->balance, 0);
63+
64+
$wallet->deposit(1000);
65+
$this->assertEquals($wallet->balance, 1000);
66+
67+
$buyer->wallet->update(['balance' => 10]);
68+
app(ProxyService::class)->fresh();
69+
70+
$this->assertEquals($wallet->balance, 10);
71+
$wallet->refreshBalance();
72+
73+
$this->assertEquals($wallet->balance, 1000);
74+
}
75+
4876
}

0 commit comments

Comments
 (0)