Skip to content

Commit 860466b

Browse files
committed
Ability to dynamically create a wallet
1 parent a546e8f commit 860466b

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/Services/WalletService.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ public function create(Model $model, array $data): Wallet
2929
{
3030
$wallet = $this->walletRepository->create(array_merge(
3131
config('wallet.wallet.creating', []),
32-
$data,
3332
[
3433
'uuid' => $this->uuidFactoryService->uuid4(),
34+
],
35+
$data,
36+
[
3537
'holder_type' => $model->getMorphClass(),
3638
'holder_id' => $model->getKey(),
3739
]

tests/Units/Service/WalletTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
use Bavix\Wallet\Internal\Service\UuidFactoryServiceInterface;
1010
use Bavix\Wallet\Services\WalletServiceInterface;
1111
use Bavix\Wallet\Test\Infra\Factories\BuyerFactory;
12+
use Bavix\Wallet\Test\Infra\Factories\UserMultiFactory;
1213
use Bavix\Wallet\Test\Infra\Models\Buyer;
14+
use Bavix\Wallet\Test\Infra\Models\UserMulti;
1315
use Bavix\Wallet\Test\Infra\TestCase;
1416

1517
/**
@@ -59,6 +61,27 @@ public function testGetById(): void
5961
app(WalletServiceInterface::class)->getById(-1);
6062
}
6163

64+
public function testCreateWalletWithUuid(): void
65+
{
66+
/** @var UserMulti $user */
67+
$user = UserMultiFactory::new()->create();
68+
69+
$uuidFactoryService = app(UuidFactoryServiceInterface::class);
70+
71+
/** @var string[] $uuids */
72+
$uuids = array_map(static fn () => $uuidFactoryService->uuid4(), range(1, 10));
73+
74+
foreach ($uuids as $uuid) {
75+
$user->createWallet([
76+
'uuid' => $uuid,
77+
'name' => md5($uuid),
78+
]);
79+
}
80+
81+
self::assertSame(10, $user->wallets()->count());
82+
self::assertSame(10, $user->wallets()->whereIn('uuid', $uuids)->count());
83+
}
84+
6285
public function testGetByUuid(): void
6386
{
6487
$this->expectException(ModelNotFoundException::class);

0 commit comments

Comments
 (0)