diff --git a/src/Models/Wallet.php b/src/Models/Wallet.php index f2745a0e8..a510d59db 100644 --- a/src/Models/Wallet.php +++ b/src/Models/Wallet.php @@ -156,6 +156,6 @@ public function getCurrencyAttribute(): string protected function initializeMorphOneWallet(): void { - $this->uuid = app(UuidFactoryServiceInterface::class)->uuid4(); + $this->uuid ??= app(UuidFactoryServiceInterface::class)->uuid4(); } } diff --git a/tests/Units/Domain/EagerLoadingTest.php b/tests/Units/Domain/EagerLoadingTest.php index 083164b8d..2e2db49d3 100644 --- a/tests/Units/Domain/EagerLoadingTest.php +++ b/tests/Units/Domain/EagerLoadingTest.php @@ -22,11 +22,14 @@ final class EagerLoadingTest extends TestCase { public function testUuidDuplicate(): void { + $expected = []; + /** @var Buyer[]|Collection $buyerTimes */ $buyerTimes = BuyerFactory::times(10)->create(); foreach ($buyerTimes as $buyerTime) { self::assertTrue($buyerTime->wallet->relationLoaded('holder')); $buyerTime->deposit(100); + $expected[] = $buyerTime->wallet->uuid; } /** @var Buyer[] $buyers */ @@ -47,6 +50,7 @@ public function testUuidDuplicate(): void self::assertCount(10, array_unique($uuids)); self::assertCount(1, array_unique($balances)); + self::assertEquals($expected, $uuids); } public function testTransferTransactions(): void