Skip to content

Commit 22b2f45

Browse files
committed
fix initializeMorphOneWallet
2 parents eed73be + ab1ee58 commit 22b2f45

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

changelog.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## 10.1.4 - 2024-03-09
4+
5+
### What's Changed
6+
7+
* [10.x] fix initializeMorphOneWallet by [@rez1dent3](https://github.com/rez1dent3) in https://github.com/bavix/laravel-wallet/pull/905
8+
9+
**Full Changelog**: https://github.com/bavix/laravel-wallet/compare/10.1.3...10.1.4
10+
311
## 10.1.3 - 2024-02-01
412

513
### What's Changed
@@ -2182,11 +2190,17 @@ Added a patch from version 4.2.1 #150
21822190
### Added
21832191

21842192
- written README.
2193+
21852194
- Project configuration file created.
2195+
21862196
- Migration 2018_11_06_222923_create_transactions_table.
2197+
21872198
- Migration 2018_11_07_192923_create_transfers_table.
2199+
21882200
- `HasWallet` trait and `Wallet` interface.
2201+
21892202
- methods:
2203+
21902204
- private checkAmount(int $amount): void
21912205
- public forceWithdraw(int $amount, ?array $meta = null, bool $confirmed = true): Transaction
21922206
- public deposit(int $amount, ?array $meta = null, bool $confirmed = true): Transaction
@@ -2200,14 +2214,17 @@ Added a patch from version 4.2.1 #150
22002214
- public resetBalance(): void
22012215

22022216
- relations:
2217+
22032218
- public transactions(): MorphMany
22042219
- public transfers(): MorphMany
22052220

22062221
- magic property
2222+
22072223
- public getBalanceAttribute(): int
22082224

22092225

22102226
- `CanBePaid` trait and `Product`, `Costomer` interface's
2227+
22112228
- methods:
22122229
- public pay(Product $product): Transfer
22132230
- public safePay(Product $product): ?Transfer
@@ -2216,7 +2233,9 @@ Added a patch from version 4.2.1 #150
22162233

22172234

22182235
- Exceptions: AmountInvalid, BalanceIsEmpty.
2236+
22192237
- Models: Transfer, Transaction.
2238+
22202239

22212240
## What's Changed
22222241

src/Models/Wallet.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ public function getCurrencyAttribute(): string
159159
return $this->meta['currency'] ?? Str::upper($this->slug);
160160
}
161161

162+
protected function initializeMorphOneWallet(): void
163+
{
164+
$this->uuid ??= app(UuidFactoryServiceInterface::class)->uuid4();
165+
}
166+
162167
/**
163168
* returns all the receiving transfers to this wallet.
164169
*
@@ -168,9 +173,4 @@ public function receivedTransfers(): HasMany
168173
{
169174
return $this->hasMany(config('wallet.transfer.model', Transfer::class), 'to_id');
170175
}
171-
172-
protected function initializeMorphOneWallet(): void
173-
{
174-
$this->uuid = app(UuidFactoryServiceInterface::class)->uuid4();
175-
}
176176
}

tests/Units/Domain/EagerLoadingTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@ final class EagerLoadingTest extends TestCase
2222
{
2323
public function testUuidDuplicate(): void
2424
{
25+
$expected = [];
26+
2527
/** @var Collection<int, Buyer> $buyerTimes */
2628
$buyerTimes = BuyerFactory::times(10)->create();
2729
foreach ($buyerTimes as $buyerTime) {
2830
self::assertTrue($buyerTime->wallet->relationLoaded('holder'));
2931
$buyerTime->deposit(100);
32+
$expected[] = $buyerTime->wallet->uuid;
3033
}
3134

3235
/** @var Collection<int, Buyer> $buyers */
@@ -47,6 +50,7 @@ public function testUuidDuplicate(): void
4750

4851
self::assertCount(10, array_unique($uuids));
4952
self::assertCount(1, array_unique($balances));
53+
self::assertEquals($expected, $uuids);
5054
}
5155

5256
public function testTransferTransactions(): void

0 commit comments

Comments
 (0)