Files
monica/tests/Helper/MoneyHelperTest.php
T
2018-01-21 22:54:28 -05:00

56 lines
1.4 KiB
PHP

<?php
namespace Tests\Helper;
use App\User;
use App\Currency;
use Tests\TestCase;
use App\Helpers\MoneyHelper;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class MoneyHelperTest extends TestCase
{
use DatabaseTransactions;
public function testFormatReturnsAmountWithCurrencySymbol()
{
$currency = new Currency();
$currency->symbol = '€';
$this->assertEquals('€500', MoneyHelper::format(500, $currency));
}
public function testFormatUsesCurrencySettingIfDefined()
{
$currency = Currency::where('iso', 'GBP')->first();
$user = factory(User::class)->create([
'currency_id' => $currency->id,
]);
$this->actingAs($user);
$this->assertEquals('£75', MoneyHelper::format(75));
}
public function testFormatReturnsAmountWithoutSymbolIfCurrencyIsUndefined()
{
$this->assertEquals('500', MoneyHelper::format(500));
}
public function testFormatReturnsZeroIfAmountIsNull()
{
$this->assertEquals('0', MoneyHelper::format(null));
}
public function test_it_covers_brazilian_currency()
{
$currency = Currency::where('iso', 'BRL')->first();
$user = factory(User::class)->create([
'currency_id' => $currency->id,
]);
$this->actingAs($user);
$this->assertEquals('R$12.345,67', MoneyHelper::format(12345.67));
}
}