Server IP : 66.29.132.124 / Your IP : 3.147.68.18 Web Server : LiteSpeed System : Linux business141.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : wavevlvu ( 1524) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/wavevlvu/book24.ng/vendor/bavix/laravel-wallet/tests/ |
Upload File : |
<?php namespace Bavix\Wallet\Test; use Bavix\Wallet\Interfaces\Rateable; use Bavix\Wallet\Services\ExchangeService; use Bavix\Wallet\Test\Factories\UserMultiFactory; use Bavix\Wallet\Test\Models\UserMulti; use Illuminate\Support\Str; class RateTest extends TestCase { /** * @return void */ public function testRate(): void { /** * @var UserMulti $user */ $user = UserMultiFactory::new()->create(); $usd = $user->createWallet(['name' => 'Dollar USA', 'slug' => 'my-usd']); self::assertEquals($usd->slug, 'my-usd'); self::assertEquals($usd->currency, 'USD'); self::assertEquals($usd->holder_id, $user->id); self::assertInstanceOf($usd->holder_type, $user); $rub = $user->createWallet(['name' => 'RUB']); self::assertEquals($rub->slug, 'rub'); self::assertEquals($rub->currency, 'RUB'); self::assertEquals($rub->holder_id, $user->id); self::assertInstanceOf($rub->holder_type, $user); $superWallet = $user->createWallet(['name' => 'Super Wallet']); self::assertEquals($superWallet->slug, Str::slug('Super Wallet')); self::assertEquals($superWallet->currency, Str::upper(Str::slug('Super Wallet'))); self::assertEquals($superWallet->holder_id, $user->id); self::assertInstanceOf($superWallet->holder_type, $user); $rate = app(Rateable::class) ->withAmount(1000) ->withCurrency($usd) ->convertTo($rub); self::assertEquals($rate, 67610.); } /** * @return void */ public function testExchange(): void { /** * @var UserMulti $user */ $user = UserMultiFactory::new()->create(); $usd = $user->createWallet(['name' => 'USD']); self::assertEquals($usd->slug, 'usd'); self::assertEquals($usd->currency, 'USD'); self::assertEquals($usd->holder_id, $user->id); self::assertInstanceOf($usd->holder_type, $user); $rub = $user->createWallet(['name' => 'RUR', 'slug' => 'my-rub']); self::assertEquals($rub->slug, 'my-rub'); self::assertEquals($rub->currency, 'RUB'); self::assertEquals($rub->holder_id, $user->id); self::assertInstanceOf($rub->holder_type, $user); $rate = app(ExchangeService::class) ->rate($usd, $rub); self::assertEquals($rate, 67.61); $rate = app(ExchangeService::class) ->rate($rub, $usd); self::assertEquals($rate, 1 / 67.61); } }