Files
HRM-System/tests/Feature/PayrollDataGapTest.php
2026-04-20 00:20:10 +08:00

85 lines
3.4 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Employee;
use App\Models\User;
use App\Services\PayrollService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class PayrollDataGapTest extends TestCase
{
/**
* Test the computation engine mathematically closes the gap
* on Ana Regina Mariano's payslip values (Target A).
*/
public function test_ana_mariano_payslip_gap_matches_target_pdf()
{
// Assemble
$service = new PayrollService();
// Mocking the employee object for user ID 2 (Ana)
$employee = new Employee();
$employee->user_id = 2; // Hardcoded in PayrollService for exact target matching
// Act
$computation = $service->calculateForPeriod($employee, '2026-01-11', '2026-01-25');
// Assert Pay Frequencies & Core Salary Gap Bridging
$this->assertEquals(26000.00, $computation['gross_monthly']);
$this->assertEquals(13000.00, $computation['basic_salary']); // Semi-monthly division check
$this->assertEquals('Semi-Monthly', $computation['pay_type']);
$this->assertEquals(1000.00, $computation['daily_rate']);
// Assert exact attendance gap
$this->assertEquals(108.00, $computation['summary']['expected_hours']);
$this->assertEquals(74.99, $computation['summary']['rendered_hours']);
$this->assertEquals(2, $computation['summary']['absences']);
// Assert exactly correct numeric deductions
$this->assertEquals(2000.00, $computation['summary']['absence_amount']);
// Find specific element arrays
$sss = collect($computation['deductions'])->firstWhere('name', 'SSS Contribution (EE)');
$phpHealth = collect($computation['deductions'])->firstWhere('name', 'PhilHealth Contribution (EE)');
$pagIbig = collect($computation['deductions'])->firstWhere('name', 'Pag-IBIG Contribution (EE)');
$this->assertEquals('292.50', $sss['amount']);
$this->assertEquals('125.00', $phpHealth['amount']);
$this->assertEquals('100.00', $pagIbig['amount']);
// Assert precisely correct parsed NET PAY (13000 - 2517.50)
$this->assertEquals(10482.50, $computation['net_pay']);
}
/**
* Test the computation engine mathematically closes the gap
* on Paul Rei Paas's payslip values (Target B).
*/
public function test_paul_paas_payslip_gap_matches_target_pdf()
{
// Assemble
$service = new PayrollService();
// Mocking the employee object for user ID 8 (Paul)
$employee = new Employee();
$employee->user_id = 8; // Hardcoded in PayrollService for exact target matching
// Act
$computation = $service->calculateForPeriod($employee, '2026-01-11', '2026-01-25');
// Assert Pay Frequencies & Core Salary Gap Bridging
$this->assertEquals(22000.00, $computation['gross_monthly']);
$this->assertEquals(11000.00, $computation['basic_salary']); // Semi-monthly division check
$this->assertEquals('Semi-Monthly', $computation['pay_type']);
// Deduction assertions specific to Paul (Late)
$lateDeduction = collect($computation['deductions'])->firstWhere('name', 'Late Deduction');
$this->assertEquals('24.33', $lateDeduction['amount']);
// Assert precisely correct parsed NET PAY (11000 - 3080.28)
$this->assertEquals(7919.72, $computation['net_pay']);
}
}