Repository navigation
Expand test coverage and fix overnight schedules - #20
Merged
Merged
Conversation
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
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 becauseCarbonPeriod::create(start, end)withend < startsilently 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 inSLA::calculateclips 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)
on('Saturday')), weekend-only schedules, multi-period days viaandFrom,Weekly::addTimePeriods/clearTimePeriods, timezone storage,effectiveFromnot yet reached, mid-duration schedule switching viafromSchedulesaddHolidays()array form, holidays on non-covered days,SLAPause::toDayPeriod/SLAHoliday::toPeriodbreaches()accessor returns only breached breaches, exact-boundary threshold does not breach, no breaches defined →hasABreach()falseAll 48 tests pass; PHPStan level 8 and Pint clean.