Files
portal-api/tests/Unit/BillingPricingTest.php
T
2026-09-27 11:42:40 +07:00

63 lines
1.9 KiB
PHP

<?php
namespace Tests\Unit;
use App\Enums\Product\ProductBillingCycle;
use App\Helpers\OrderHelper;
use App\Models\DomainPricing;
use PHPUnit\Framework\TestCase;
class BillingPricingTest extends TestCase
{
public function test_cycle_to_months_covers_every_enum_case(): void
{
$expected = [
'onetime' => 1,
'monthly' => 1,
'quarterly' => 3,
'semi_annually' => 6,
'annually' => 12,
'biennially' => 24,
'triennially' => 36,
];
foreach (ProductBillingCycle::cases() as $case) {
$this->assertSame($expected[$case->value], OrderHelper::cycleToMonths($case->value));
}
}
public function test_cycle_to_months_throws_on_unknown_value(): void
{
$this->expectException(\InvalidArgumentException::class);
OrderHelper::cycleToMonths('semiannually');
}
public function test_cycle_to_months_throws_on_null(): void
{
$this->expectException(\InvalidArgumentException::class);
OrderHelper::cycleToMonths(null);
}
/** @dataProvider domainPriceProvider */
public function test_domain_price_formula(int $setupFee, int $firstYear, int $renewal, int $years, int $expected): void
{
$pricing = new DomainPricing([
'setup_fee' => (string) $setupFee,
'first_year' => $firstYear,
'recurring_fee' => (string) $renewal,
]);
$this->assertSame($expected, $pricing->orderPrice($years));
}
public static function domainPriceProvider(): array
{
return [
'years=1, no setup fee' => [0, 200000, 350000, 1, 200000],
'years=1, with setup fee' => [50000, 200000, 350000, 1, 250000],
'years=3, no setup fee' => [0, 200000, 350000, 3, 900000],
'years=3, with setup fee' => [50000, 200000, 350000, 3, 950000],
];
}
}