Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Models/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class Transaction extends Model
'amount',
'confirmed',
'meta',
'created_at',
'updated_at',
];

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Models/Transfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class Transfer extends Model
'to_id',
'uuid',
'fee',
'created_at',
'updated_at',
];

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Models/Wallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class Wallet extends Model implements Customer, WalletFloat, Confirmable, Exchan
'meta',
'balance',
'decimal_places',
'created_at',
'updated_at',
];

/**
Expand Down
82 changes: 82 additions & 0 deletions tests/Units/Domain/SilentlyDiscardingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

declare(strict_types=1);

namespace Bavix\Wallet\Test\Units\Domain;

use Bavix\Wallet\Internal\Service\ClockServiceInterface;
use Bavix\Wallet\Test\Infra\Factories\BuyerFactory;
use Bavix\Wallet\Test\Infra\Factories\UserFactory;
use Bavix\Wallet\Test\Infra\Factories\UserMultiFactory;
use Bavix\Wallet\Test\Infra\Models\Buyer;
use Bavix\Wallet\Test\Infra\Models\User;
use Bavix\Wallet\Test\Infra\Models\UserMulti;
use Bavix\Wallet\Test\Infra\Services\ClockFakeService;
use Bavix\Wallet\Test\Infra\TestCase;
use Illuminate\Database\Eloquent\Model;

/**
* @internal
*/
final class SilentlyDiscardingTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
Model::preventSilentlyDiscardingAttributes();
}

protected function tearDown(): void
{
parent::tearDown();
Model::preventSilentlyDiscardingAttributes(false);
}

public function testDepositSilentlyDiscarding(): void
{
/** @var Buyer $buyer */
$buyer = BuyerFactory::new()->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());
}
}