Skip to content

Commit f891119

Browse files
committed
add support Model::preventSilentlyDiscardingAttributes()
1 parent 289519f commit f891119

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed

src/Models/Transaction.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class Transaction extends Model
4949
'amount',
5050
'confirmed',
5151
'meta',
52+
'created_at',
53+
'updated_at',
5254
];
5355

5456
/**

src/Models/Transfer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class Transfer extends Model
5656
'to_id',
5757
'uuid',
5858
'fee',
59+
'created_at',
60+
'updated_at',
5961
];
6062

6163
/**

src/Models/Wallet.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class Wallet extends Model implements Customer, WalletFloat, Confirmable, Exchan
6464
'meta',
6565
'balance',
6666
'decimal_places',
67+
'created_at',
68+
'updated_at',
6769
];
6870

6971
/**
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bavix\Wallet\Test\Units\Domain;
6+
7+
use Bavix\Wallet\Internal\Service\ClockServiceInterface;
8+
use Bavix\Wallet\Test\Infra\Factories\BuyerFactory;
9+
use Bavix\Wallet\Test\Infra\Factories\UserFactory;
10+
use Bavix\Wallet\Test\Infra\Factories\UserMultiFactory;
11+
use Bavix\Wallet\Test\Infra\Models\Buyer;
12+
use Bavix\Wallet\Test\Infra\Models\User;
13+
use Bavix\Wallet\Test\Infra\Models\UserMulti;
14+
use Bavix\Wallet\Test\Infra\Services\ClockFakeService;
15+
use Bavix\Wallet\Test\Infra\TestCase;
16+
use Illuminate\Database\Eloquent\Model;
17+
18+
/**
19+
* @internal
20+
*/
21+
final class SilentlyDiscardingTest extends TestCase
22+
{
23+
protected function setUp(): void
24+
{
25+
parent::setUp();
26+
Model::preventSilentlyDiscardingAttributes();
27+
}
28+
29+
public function testDepositSilentlyDiscarding(): void
30+
{
31+
/** @var Buyer $buyer */
32+
$buyer = BuyerFactory::new()->create();
33+
self::assertFalse($buyer->relationLoaded('wallet'));
34+
$buyer->deposit(1);
35+
36+
self::assertTrue($buyer->relationLoaded('wallet'));
37+
self::assertTrue($buyer->wallet->exists);
38+
self::assertSame(1, $buyer->balanceInt);
39+
}
40+
41+
public function testTransferSilentlyDiscarding(): void
42+
{
43+
/**
44+
* @var User $first
45+
* @var User $second
46+
*/
47+
[$first, $second] = UserFactory::times(2)->create();
48+
self::assertNotSame($first->getKey(), $second->getKey());
49+
50+
self::assertNotNull($first->deposit(1000));
51+
self::assertSame(1000, $first->balanceInt);
52+
53+
self::assertNotNull($first->transfer($second, 500));
54+
self::assertSame(500, $first->balanceInt);
55+
self::assertSame(500, $second->balanceInt);
56+
}
57+
58+
public function testMultiWalletSilentlyDiscarding(): void
59+
{
60+
$this->app->bind(ClockServiceInterface::class, ClockFakeService::class);
61+
62+
/** @var UserMulti $user */
63+
$user = UserMultiFactory::new()->create();
64+
$dateTime = app(ClockServiceInterface::class)->now();
65+
66+
$wallet = $user->createWallet([
67+
'name' => 'hello',
68+
'created_at' => $dateTime->getTimestamp(),
69+
'updated_at' => $dateTime->getTimestamp(),
70+
]);
71+
72+
self::assertCount(1, $user->wallets);
73+
self::assertSame($dateTime->getTimestamp(), $wallet->created_at->getTimestamp());
74+
self::assertSame($dateTime->getTimestamp(), $wallet->updated_at->getTimestamp());
75+
}
76+
}

0 commit comments

Comments
 (0)