diff --git a/src/Models/Wallet.php b/src/Models/Wallet.php index 814513c7e..51f32a853 100644 --- a/src/Models/Wallet.php +++ b/src/Models/Wallet.php @@ -161,7 +161,7 @@ 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 3df738a08..bc1094e53 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 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 Collection $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