Skip to content

Commit 2ba47a8

Browse files
committed
Fixed creating a wallet with default slug. # 57 @kak2z7702
1 parent 53fffc0 commit 2ba47a8

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

changelog.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [3.0.3] - 2019-07-06
10+
### Fixed
11+
- Fixed creating a wallet with default slug. # 57 @kak2z7702
12+
913
## [3.0.2] - 2019-06-18
1014
### Added
1115
- Add support laravel 5.9
@@ -305,7 +309,8 @@ The operation is now executed in the transaction and updates the new `refund` fi
305309
- Exceptions: AmountInvalid, BalanceIsEmpty.
306310
- Models: Transfer, Transaction.
307311

308-
[Unreleased]: https://github.com/bavix/laravel-wallet/compare/3.0.2...HEAD
312+
[Unreleased]: https://github.com/bavix/laravel-wallet/compare/3.0.3...HEAD
313+
[3.0.3]: https://github.com/bavix/laravel-wallet/compare/3.0.2...3.0.3
309314
[3.0.2]: https://github.com/bavix/laravel-wallet/compare/3.0.1...3.0.2
310315
[3.0.1]: https://github.com/bavix/laravel-wallet/compare/3.0.0...3.0.1
311316
[3.0.0]: https://github.com/bavix/laravel-wallet/compare/2.4.1...3.0.0

src/Traits/HasWallets.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,17 @@ public function wallets(): MorphMany
8383
*/
8484
public function createWallet(array $data): WalletModel
8585
{
86-
/**
87-
* Create a default wallet
88-
*/
89-
$this->getBalanceAttribute();
90-
9186
/**
9287
* @var WalletModel $wallet
9388
*/
9489
$wallet = $this->wallets()->create($data);
9590
$this->_wallets[$wallet->slug] = $wallet;
9691

92+
/**
93+
* Create a default wallet
94+
*/
95+
$this->getBalanceAttribute();
96+
9797
return $wallet;
9898
}
9999

tests/MultiWalletTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,25 @@
1414
class MultiWalletTest extends TestCase
1515
{
1616

17+
/**
18+
* @return void
19+
*/
20+
public function testCreateDefault(): void
21+
{
22+
$slug = config('wallet.wallet.default.slug', 'default');
23+
24+
/**
25+
* @var UserMulti $user
26+
*/
27+
$user = factory(UserMulti::class)->create();
28+
$this->assertNull($user->getWallet($slug));
29+
30+
$wallet = $user->createWallet(['name' => 'Simple', 'slug' => $slug]);
31+
$this->assertNotNull($wallet);
32+
$this->assertNotNull($user->wallet);
33+
$this->assertEquals($user->wallet->id, $wallet->id);
34+
}
35+
1736
/**
1837
* @return void
1938
*/

0 commit comments

Comments
 (0)