53 lines
1.4 KiB
PHP
53 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
|
|
{
|
|
$invoice = [
|
|
'invoice_number' => 'INV-001',
|
|
'invoice_date' => date('Y-m-d'),
|
|
'subtotal' => 100,
|
|
'discount_total' => 0,
|
|
'grand_total' => 116
|
|
];
|
|
$lines = [
|
|
['line_number' => 1, 'quantity' => 1, 'unit_price' => 100, 'tax_rate' => 0.16, 'tax_amount' => 16, 'line_total' => 116]
|
|
];
|
|
|
|
$result = $this->service->validate($invoice, $lines);
|
|
$this->assertTrue($result['is_valid']);
|
|
}
|
|
|
|
public function test_it_detects_mismatching_totals(): void
|
|
{
|
|
$invoice = [
|
|
'invoice_number' => 'INV-002',
|
|
'invoice_date' => date('Y-m-d'),
|
|
'subtotal' => 100,
|
|
'discount_total' => 0,
|
|
'grand_total' => 110 // Mismatch
|
|
];
|
|
$lines = [
|
|
['line_number' => 1, 'quantity' => 1, 'unit_price' => 100, 'tax_rate' => 0.16, 'tax_amount' => 16, 'line_total' => 116]
|
|
];
|
|
|
|
$result = $this->service->validate($invoice, $lines);
|
|
$this->assertFalse($result['is_valid']);
|
|
}
|
|
}
|