Skip to content

Commit 2cf1567

Browse files
committed
add unit-test
1 parent 932c5bd commit 2cf1567

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

rector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Rector\Core\Configuration\Option;
66
use Rector\Laravel\Set\LaravelSetList;
77
use Rector\Php74\Rector\Property\TypedPropertyRector;
8+
use Rector\PHPUnit\Set\PHPUnitSetList;
89
use Rector\Set\ValueObject\SetList;
910
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
1011

@@ -17,6 +18,7 @@
1718
]);
1819

1920
// Define what rule sets will be applied
21+
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_91);
2022
$containerConfigurator->import(LaravelSetList::LARAVEL_60);
2123
$containerConfigurator->import(SetList::DEAD_CODE);
2224
$containerConfigurator->import(SetList::PHP_74);

tests/Units/Domain/MultiWalletTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
use Bavix\Wallet\Exceptions\AmountInvalid;
88
use Bavix\Wallet\Exceptions\BalanceIsEmpty;
9+
use Bavix\Wallet\Exceptions\InsufficientFunds;
910
use Bavix\Wallet\Internal\Exceptions\ExceptionInterface;
1011
use Bavix\Wallet\Internal\Exceptions\ModelNotFoundException;
12+
use Bavix\Wallet\Internal\Service\DatabaseServiceInterface;
1113
use Bavix\Wallet\Internal\Service\UuidFactoryServiceInterface;
1214
use Bavix\Wallet\Models\Transaction;
1315
use Bavix\Wallet\Models\Transfer;
@@ -17,6 +19,7 @@
1719
use Bavix\Wallet\Test\Infra\Models\Item;
1820
use Bavix\Wallet\Test\Infra\Models\UserCashier;
1921
use Bavix\Wallet\Test\Infra\Models\UserMulti;
22+
use Bavix\Wallet\Test\Infra\PackageModels\Wallet;
2023
use Bavix\Wallet\Test\Infra\TestCase;
2124
use function compact;
2225
use Illuminate\Database\QueryException;
@@ -522,4 +525,44 @@ public function testDecimalPlaces(): void
522525
$user->deposit(1_000_000_000);
523526
self::assertSame(1000., (float) $wallet->balanceFloat);
524527
}
528+
529+
public function testMultiWalletTransactionState(): void
530+
{
531+
/** @var UserMulti $user */
532+
$user = UserMultiFactory::new()->create();
533+
534+
/** @var Wallet[] $wallets */
535+
$wallets = [];
536+
foreach (range(1, 10) as $item) {
537+
$wallets[] = $user->createWallet(['name' => 'index'.$item]);
538+
}
539+
540+
self::assertCount(10, $wallets);
541+
542+
$funds = null;
543+
544+
try {
545+
app(DatabaseServiceInterface::class)->transaction(function () use ($wallets) {
546+
foreach ($wallets as $key => $wallet) {
547+
$wallet->deposit(1000 + $key); // 1000 + [0...9]
548+
$wallet->withdraw(100);
549+
$wallet->deposit(50);
550+
551+
self::assertSame(950 + $key, $wallet->balanceInt);
552+
}
553+
554+
$wallet = reset($wallets);
555+
self::assertIsObject($wallet);
556+
557+
$wallet->withdraw(1000); // failed
558+
});
559+
} catch (InsufficientFunds $funds) {
560+
self::assertSame(ExceptionInterface::INSUFFICIENT_FUNDS, $funds->getCode());
561+
}
562+
563+
self::assertNotNull($funds);
564+
foreach ($wallets as $wallet) {
565+
self::assertSame(0, $wallet->balanceInt);
566+
}
567+
}
525568
}

0 commit comments

Comments
 (0)