Skip to content

fix(test): use willReturnCallback and unique service keys in SchedulerWorkerTest (closes #668) - #771

Merged
s2x merged 2 commits into
masterfrom
refactor/issue-668-schedulerworkertest-willreturn-datetimei
Aug 22, 2026
Merged

fix(test): use willReturnCallback and unique service keys in SchedulerWorkerTest (closes #668)#771
s2x merged 2 commits into
masterfrom
refactor/issue-668-schedulerworkertest-willreturn-datetimei

Conversation

@s2x

@s2x s2x commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

Description

Closes #668

Fixes two latent test fragilities in tests/Worker/SchedulerWorkerTest.php:

  1. willReturn(new DateTimeImmutable('+1 second')) evaluates once — the relative string is parsed at stub-configuration time, returning the same fixed absolute date on every call. Replaced with willReturnCallback(fn(\DateTimeImmutable $now): \DateTimeImmutable => $now->modify('+1 second')), matching the pattern documented in FAQ-022.

  2. Shared test_service key causes cross-test deduplication — both testScheduleCallbackPassesArgsToDelay and testScheduleCallbackUsesFirstClassCallable used the same service key, so the static $tickCallbacks dedup in scheduleCallback() reused the first test's closure/args for the second test. Replaced with unique per-test keys (args_test_service, callable_test_service), matching the convention already used by the newer tests.

Changes

  • tests/Worker/SchedulerWorkerTest.php: 2 stub replacements + 2 service key renames + arrow function return types

Changelog

Added entry under [Unreleased] → Fixed in CHANGELOG.md.

Proof of Work

docs/proof_of_work/0668-schedulerworkertest-datetime-dedup/ — 1 review round

Code Review

  • Passed subagent code review
  • Every finding answered (1 HIGH finding fixed: missing arrow function return types broke RectorConfigTest)

Piotr Hałas added 2 commits August 22, 2026 03:10
…rWorkerTest (closes #668)

- Replace willReturn(new DateTimeImmutable('+1 second')) with
  willReturnCallback(fn(\DateTimeImmutable $now): \DateTimeImmutable =>
  $now->modify('+1 second')) in two test methods, fixing the
  evaluates-once-at-stub-time trap (FAQ-022)
- Replace shared 'test_service' key with unique per-test keys
  ('args_test_service', 'callable_test_service') to prevent
  static $tickCallbacks cross-test deduplication
- Add explicit return type to arrow functions (AddArrowFunctionReturnTypeRector)
@s2x s2x self-assigned this Aug 22, 2026
@s2x
s2x merged commit 05a48a8 into master Aug 22, 2026
14 checks passed
@s2x
s2x deleted the refactor/issue-668-schedulerworkertest-willreturn-datetimei branch August 22, 2026 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant