Skip to content

Commit

Permalink
Merge pull request #50 from bavix/deposit
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
rez1dent3 authored Jun 17, 2019
2 parents 6aa2cff + af13c49 commit 5474e87
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
7 changes: 6 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Services/WalletService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()];
Expand Down
32 changes: 32 additions & 0 deletions tests/BalanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

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;
use function app;

Expand All @@ -11,6 +13,7 @@ class BalanceTest extends TestCase

/**
* @return void
* @throws
*/
public function testSimple(): void
{
Expand Down Expand Up @@ -45,4 +48,33 @@ 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);

Wallet::whereKey($buyer->wallet->getKey())
->update(['balance' => 10]);

app(ProxyService::class)->fresh();

$wallet->refresh();
$this->assertEquals($wallet->balance, 10);

$wallet->refreshBalance();
$this->assertEquals($wallet->balance, 1000);
}

}

0 comments on commit 5474e87

Please sign in to comment.