From ef19fdeb436322a389db9f76a4d37aa0f3b194c0 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Wed, 28 Sep 2022 20:37:35 +0300 Subject: [PATCH 1/2] add support Model::preventSilentlyDiscardingAttributes() --- src/Models/Transaction.php | 2 + src/Models/Transfer.php | 2 + src/Models/Wallet.php | 2 + tests/Units/Domain/SilentlyDiscardingTest.php | 76 +++++++++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 tests/Units/Domain/SilentlyDiscardingTest.php diff --git a/src/Models/Transaction.php b/src/Models/Transaction.php index 26206238c..ce22b0685 100644 --- a/src/Models/Transaction.php +++ b/src/Models/Transaction.php @@ -49,6 +49,8 @@ class Transaction extends Model 'amount', 'confirmed', 'meta', + 'created_at', + 'updated_at', ]; /** diff --git a/src/Models/Transfer.php b/src/Models/Transfer.php index dc1a341fa..721696d46 100644 --- a/src/Models/Transfer.php +++ b/src/Models/Transfer.php @@ -56,6 +56,8 @@ class Transfer extends Model 'to_id', 'uuid', 'fee', + 'created_at', + 'updated_at', ]; /** diff --git a/src/Models/Wallet.php b/src/Models/Wallet.php index 06c5ced7d..f2745a0e8 100644 --- a/src/Models/Wallet.php +++ b/src/Models/Wallet.php @@ -64,6 +64,8 @@ class Wallet extends Model implements Customer, WalletFloat, Confirmable, Exchan 'meta', 'balance', 'decimal_places', + 'created_at', + 'updated_at', ]; /** diff --git a/tests/Units/Domain/SilentlyDiscardingTest.php b/tests/Units/Domain/SilentlyDiscardingTest.php new file mode 100644 index 000000000..13cb927b9 --- /dev/null +++ b/tests/Units/Domain/SilentlyDiscardingTest.php @@ -0,0 +1,76 @@ +create(); + self::assertFalse($buyer->relationLoaded('wallet')); + $buyer->deposit(1); + + self::assertTrue($buyer->relationLoaded('wallet')); + self::assertTrue($buyer->wallet->exists); + self::assertSame(1, $buyer->balanceInt); + } + + public function testTransferSilentlyDiscarding(): void + { + /** + * @var User $first + * @var User $second + */ + [$first, $second] = UserFactory::times(2)->create(); + self::assertNotSame($first->getKey(), $second->getKey()); + + self::assertNotNull($first->deposit(1000)); + self::assertSame(1000, $first->balanceInt); + + self::assertNotNull($first->transfer($second, 500)); + self::assertSame(500, $first->balanceInt); + self::assertSame(500, $second->balanceInt); + } + + public function testMultiWalletSilentlyDiscarding(): void + { + $this->app->bind(ClockServiceInterface::class, ClockFakeService::class); + + /** @var UserMulti $user */ + $user = UserMultiFactory::new()->create(); + $dateTime = app(ClockServiceInterface::class)->now(); + + $wallet = $user->createWallet([ + 'name' => 'hello', + 'created_at' => $dateTime->getTimestamp(), + 'updated_at' => $dateTime->getTimestamp(), + ]); + + self::assertCount(1, $user->wallets); + self::assertSame($dateTime->getTimestamp(), $wallet->created_at->getTimestamp()); + self::assertSame($dateTime->getTimestamp(), $wallet->updated_at->getTimestamp()); + } +} From 8e6dad70be8b98e8b1c33bf27710cbf0c893f9cd Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Wed, 28 Sep 2022 20:42:39 +0300 Subject: [PATCH 2/2] add tearDown --- tests/Units/Domain/SilentlyDiscardingTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/Units/Domain/SilentlyDiscardingTest.php b/tests/Units/Domain/SilentlyDiscardingTest.php index 13cb927b9..f17578c91 100644 --- a/tests/Units/Domain/SilentlyDiscardingTest.php +++ b/tests/Units/Domain/SilentlyDiscardingTest.php @@ -26,6 +26,12 @@ protected function setUp(): void Model::preventSilentlyDiscardingAttributes(); } + protected function tearDown(): void + { + parent::tearDown(); + Model::preventSilentlyDiscardingAttributes(false); + } + public function testDepositSilentlyDiscarding(): void { /** @var Buyer $buyer */