| 
 | 1 | +<?php  | 
 | 2 | + | 
 | 3 | +namespace Bavix\Wallet\Test;  | 
 | 4 | + | 
 | 5 | +use Bavix\Wallet\Test\Models\Buyer;  | 
 | 6 | +use Bavix\Wallet\Test\Models\User;  | 
 | 7 | + | 
 | 8 | +class CastsTest extends TestCase  | 
 | 9 | +{  | 
 | 10 | + | 
 | 11 | +    /**  | 
 | 12 | +     * @return void  | 
 | 13 | +     */  | 
 | 14 | +    public function testModelWallet(): void  | 
 | 15 | +    {  | 
 | 16 | +        /**  | 
 | 17 | +         * @var Buyer $buyer  | 
 | 18 | +         */  | 
 | 19 | +        $buyer = factory(Buyer::class)->create();  | 
 | 20 | +        $this->assertEquals($buyer->balance, 0);  | 
 | 21 | + | 
 | 22 | +        $this->assertIsInt($buyer->wallet->getKey());  | 
 | 23 | +        $this->assertEquals($buyer->wallet->getCasts()['id'], 'int');  | 
 | 24 | + | 
 | 25 | +        config(['wallet.wallet.casts.id' => 'string']);  | 
 | 26 | +        $this->assertIsString($buyer->wallet->getKey());  | 
 | 27 | +        $this->assertEquals($buyer->wallet->getCasts()['id'], 'string');  | 
 | 28 | +    }  | 
 | 29 | + | 
 | 30 | +    /**  | 
 | 31 | +     * @return void  | 
 | 32 | +     */  | 
 | 33 | +    public function testModelTransfer(): void  | 
 | 34 | +    {  | 
 | 35 | +        /**  | 
 | 36 | +         * @var Buyer $buyer  | 
 | 37 | +         * @var User $user  | 
 | 38 | +         */  | 
 | 39 | +        $buyer = factory(Buyer::class)->create();  | 
 | 40 | +        $user = factory(User::class)->create();  | 
 | 41 | +        $this->assertEquals($buyer->balance, 0);  | 
 | 42 | +        $this->assertEquals($user->balance, 0);  | 
 | 43 | + | 
 | 44 | +        $deposit = $user->deposit(1000);  | 
 | 45 | +        $this->assertEquals($user->balance, $deposit->amount);  | 
 | 46 | + | 
 | 47 | +        $transfer = $user->transfer($buyer, 700);  | 
 | 48 | + | 
 | 49 | +        $this->assertIsInt($transfer->getKey());  | 
 | 50 | +        $this->assertEquals($transfer->getCasts()['id'], 'int');  | 
 | 51 | + | 
 | 52 | +        config(['wallet.transfer.casts.id' => 'string']);  | 
 | 53 | +        $this->assertIsString($transfer->getKey());  | 
 | 54 | +        $this->assertEquals($transfer->getCasts()['id'], 'string');  | 
 | 55 | +    }  | 
 | 56 | + | 
 | 57 | +    /**  | 
 | 58 | +     * @return void  | 
 | 59 | +     */  | 
 | 60 | +    public function testModelTransaction(): void  | 
 | 61 | +    {  | 
 | 62 | +        /**  | 
 | 63 | +         * @var Buyer $buyer  | 
 | 64 | +         */  | 
 | 65 | +        $buyer = factory(Buyer::class)->create();  | 
 | 66 | +        $this->assertEquals($buyer->balance, 0);  | 
 | 67 | +        $deposit = $buyer->deposit(1);  | 
 | 68 | + | 
 | 69 | +        $this->assertIsInt($deposit->getKey());  | 
 | 70 | +        $this->assertEquals($deposit->getCasts()['id'], 'int');  | 
 | 71 | + | 
 | 72 | +        config(['wallet.transaction.casts.id' => 'string']);  | 
 | 73 | +        $this->assertIsString($deposit->getKey());  | 
 | 74 | +        $this->assertEquals($deposit->getCasts()['id'], 'string');  | 
 | 75 | +    }  | 
 | 76 | + | 
 | 77 | +}  | 
0 commit comments