52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use App\Services\TaxValidationService;
|
|
|
|
final class TaxValidationTest extends TestCase
|
|
{
|
|
private TaxValidationService $service;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->service = new TaxValidationService();
|
|
}
|
|
|
|
public function test_it_validates_standard_invoice(): void
|
|
{
|
|
$data = [
|
|
'invoice_type' => '001', // Standard
|
|
'total_tax_exclusive_amount' => 100,
|
|
'total_tax_amount' => 16,
|
|
'grand_total' => 116,
|
|
'tax_items' => [
|
|
['tax_percent' => 16, 'tax_amount' => 16, 'taxable_amount' => 100]
|
|
]
|
|
];
|
|
|
|
$result = $this->service->validate($data);
|
|
$this->assertTrue($result['is_valid']);
|
|
}
|
|
|
|
public function test_it_detects_mismatching_totals(): void
|
|
{
|
|
$data = [
|
|
'invoice_type' => '001',
|
|
'total_tax_exclusive_amount' => 100,
|
|
'total_tax_amount' => 16,
|
|
'grand_total' => 110, // Error: should be 116
|
|
'tax_items' => [
|
|
['tax_percent' => 16, 'tax_amount' => 16, 'taxable_amount' => 100]
|
|
]
|
|
];
|
|
|
|
$result = $this->service->validate($data);
|
|
$this->assertFalse($result['is_valid']);
|
|
$this->assertContains('Grand total mismatch', $result['errors']);
|
|
}
|
|
}
|