Add TickingClock: auto-advancing clock for sequential test scenarios #2

Open
opened 2026-07-26 19:13:19 +02:00 by claudeCode · 0 comments
Member

Problem

Tests that verify time-ordered behavior (e.g. event sequences, TTL expiry after N operations) must call FrozenClock::set() manually between each step. This couples test logic to specific timestamps and makes the intent less clear.

Proposed API

$clock = new TickingClock(
    new \DateTimeImmutable('2026-01-01 00:00:00'),
    new \DateInterval('PT1S')  // tick interval
);

$clock->now(); // 2026-01-01 00:00:00
$clock->now(); // 2026-01-01 00:00:01
$clock->now(); // 2026-01-01 00:00:02

Each now() call advances the internal time by the configured interval before returning. The first call returns the initial time without advancing.

Benefits

  • Tests that care about ordering, not absolute times, become self-documenting
  • No manual set() bookkeeping
  • Implements ClockInterface — drop-in replacement for FrozenClock where appropriate

Acceptance criteria

  • TickingClock(DateTimeImmutable $start, DateInterval $tick): void
  • First now() returns $start, each subsequent call adds $tick
  • Implements ClockInterface
  • Test coverage including multi-step sequences
## Problem Tests that verify time-ordered behavior (e.g. event sequences, TTL expiry after N operations) must call `FrozenClock::set()` manually between each step. This couples test logic to specific timestamps and makes the intent less clear. ## Proposed API ```php $clock = new TickingClock( new \DateTimeImmutable('2026-01-01 00:00:00'), new \DateInterval('PT1S') // tick interval ); $clock->now(); // 2026-01-01 00:00:00 $clock->now(); // 2026-01-01 00:00:01 $clock->now(); // 2026-01-01 00:00:02 ``` Each `now()` call advances the internal time by the configured interval before returning. The first call returns the initial time without advancing. ## Benefits - Tests that care about ordering, not absolute times, become self-documenting - No manual `set()` bookkeeping - Implements `ClockInterface` — drop-in replacement for `FrozenClock` where appropriate ## Acceptance criteria - `TickingClock(DateTimeImmutable $start, DateInterval $tick): void` - First `now()` returns `$start`, each subsequent call adds `$tick` - Implements `ClockInterface` - Test coverage including multi-step sequences
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: tez/tez-utils-clock#2