base commit
This commit is contained in:
54
tests/Unit/Services/LeaveDaysCalculatorTest.php
Normal file
54
tests/Unit/Services/LeaveDaysCalculatorTest.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Services\Leave\LeaveDaysCalculator;
|
||||
use Carbon\Carbon;
|
||||
|
||||
beforeEach(function (): void {
|
||||
$this->calculator = new LeaveDaysCalculator;
|
||||
});
|
||||
|
||||
it('calculates inclusive calendar days between two dates', function (): void {
|
||||
config(['hr.leave_calculation' => 'calendar']);
|
||||
|
||||
$days = $this->calculator->between(
|
||||
Carbon::parse('2025-01-06'),
|
||||
Carbon::parse('2025-01-12'),
|
||||
);
|
||||
|
||||
expect($days)->toBe(7);
|
||||
});
|
||||
|
||||
it('calculates business days excluding weekends', function (): void {
|
||||
config(['hr.leave_calculation' => 'business']);
|
||||
|
||||
$days = $this->calculator->between(
|
||||
Carbon::parse('2025-01-06'),
|
||||
Carbon::parse('2025-01-12'),
|
||||
);
|
||||
|
||||
expect($days)->toBe(5);
|
||||
});
|
||||
|
||||
it('returns zero when the end date is before the start date', function (): void {
|
||||
config(['hr.leave_calculation' => 'calendar']);
|
||||
|
||||
$days = $this->calculator->between(
|
||||
Carbon::parse('2025-01-10'),
|
||||
Carbon::parse('2025-01-06'),
|
||||
);
|
||||
|
||||
expect($days)->toBe(0);
|
||||
});
|
||||
|
||||
it('counts a single day when start and end are the same', function (): void {
|
||||
config(['hr.leave_calculation' => 'calendar']);
|
||||
|
||||
$days = $this->calculator->between(
|
||||
Carbon::parse('2025-01-06'),
|
||||
Carbon::parse('2025-01-06'),
|
||||
);
|
||||
|
||||
expect($days)->toBe(1);
|
||||
});
|
||||
Reference in New Issue
Block a user