Skip to content

Expand test coverage and fix overnight schedules - #20

Merged
sifex merged 1 commit into
mainfrom
chore/expand-test-coverage
Aug 15, 2026
Merged

sifex merged 1 commit into
mainfrom
chore/expand-test-coverage

Conversation

@sifex

@sifex sifex commented Aug 15, 2026

Copy link
Copy Markdown
Owner

Summary

Adds 28 new tests covering previously untested behaviour, lifting coverage from 96.3% to 98.4%. In the process, the new tests exposed a real bug: midnight-crossing (overnight) schedules silently produced zero SLA time.

Stacked on #16 (chore/maintenance-update) — retargets to main once #16 merges.

Bug found & fixed: overnight schedules return 0

A schedule like from('22:00:00')->to('02:00:00') — common for 24/7 support — returned 0 seconds because CarbonPeriod::create(start, end) with end < start silently yields an empty period.

Fix in src/Agenda/Weekly.php: overnight periods are now kept as a single period spanning midnight, which the existing per-day overlap logic in SLA::calculate clips exactly (verified: 22:00→02:00 across a window totals 4h, no boundary seconds lost).

As a consequence, a 24/7 schedule expressed as equal from/to times (09:00 → 09:00) now correctly covers a full day instead of 0.

New tests (tests/SLAEdgeCasesTest.php)

  • Schedules: single-day-name strings (on('Saturday')), weekend-only schedules, multi-period days via andFrom, Weekly::addTimePeriods / clearTimePeriods, timezone storage, effectiveFrom not yet reached, mid-duration schedule switching via fromSchedules
  • Boundaries: subject starting after the schedule ends, starting/ending exactly on schedule edges, multi-week weekday durations
  • Overnight: across midnight, night-only windows, full window, multi-day, weekday-only overnight schedules, 24/7 equal-times schedules
  • Pauses/holidays: pause outside the window, pause covering the whole window, multi-day pauses, addHolidays() array form, holidays on non-covered days, SLAPause::toDayPeriod / SLAHoliday::toPeriod
  • Breaches: breaches() accessor returns only breached breaches, exact-boundary threshold does not breach, no breaches defined → hasABreach() false

All 48 tests pass; PHPStan level 8 and Pint clean.

Adds 28 new tests (tests/SLAEdgeCasesTest.php) covering previously
untested behaviour: single-day string schedules, weekend-only
schedules, multi-period schedules via andFrom, the Weekly agenda
addTimePeriods/clearTimePeriods API, schedule effectiveFrom switches
mid-duration, boundary conditions (start/end exactly at schedule
edges), multi-week durations, overnight schedules, pause and holiday
edge cases (outside window, full-window, multi-day, arrays, weekend
holidays), the breaches() accessor, breach boundary semantics, and
SLAPause/SLAHoliday day periods.

Coverage: 96.3% -> 98.4%.

The new overnight-schedule tests exposed a real bug: midnight-crossing
schedules (e.g. 22:00 -> 02:00) silently produced zero SLA time
because CarbonPeriod::create(start, end) with end < start yields an
empty period. Weekly::toPeriods now keeps overnight periods as a
single period spanning midnight, which the per-day overlap logic in
SLA::calculate clips exactly. A 24/7 schedule (equal from/to times) is
now also covered.
sifex added a commit that referenced this pull request Aug 15, 2026
- Remove the stale disclaimer that sla-timer is inefficient over
  periods longer than a month (fixed in #21: a year with daily
  holidays now calculates in ~30ms, 10-year spans in ~90ms) and
  replace it with a short Performance section
- Document overnight (midnight-crossing) schedules and 24/7 coverage
  via equal from/to times in the schedule-building guide (newly
  working behaviour from #20)
@sifex
sifex merged commit 19b5231 into main Aug 15, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant