Skip to content

Model WP-Cron events in the lifecycle idempotency check - #168

Merged
schlessera merged 1 commit into
mainfrom
test/159-model-wp-cron-in-lifecycle-effects
Oct 23, 2026
Merged

schlessera merged 1 commit into
mainfrom
test/159-model-wp-cron-in-lifecycle-effects

Conversation

@schlessera

Copy link
Copy Markdown
Member

Closes #159

What changed

The lifecycle idempotency check in CompositionRootContract now models WP-Cron. LifecycleEffects stubs wp_schedule_event(), wp_schedule_single_event(), wp_next_scheduled(), wp_unschedule_event() and wp_clear_scheduled_hook() and records events per hook, keyed by timestamp and md5( serialize( $args ) ) as WordPress does. An activate() that schedules at a new time or with new arguments on every call is now reported as changes the cron events of "<hook>" again. Four fixtures cover it (two reported, a wp_next_scheduled()-guarded step and an identical double schedule passing), and docs/architecture-rules.md lists cron events among the recorded effects and describes the model.

Why this shape

The model follows the issue: one entry per hook in the snapshot, so the existing effect comparison and message format work unchanged. serialize() is needed to key arguments exactly as WordPress does, so that line carries a named, reasoned phpcs:ignore for the one WPCS sniff. The ten-minute single-event window, the schedule filters and $wp_error stay out of scope as the issue says.

Proof

The new tests failed before the change (Call to undefined function ...wp_schedule_event(); the contract assertions for the two broken fixtures failed): Tests: 37, Assertions: 80, Errors: 6, Failures: 2 in LifecycleEffectsTest and CompositionRootContractTest. After the change, in php:8.3-cli:

composer test   # OK (598 tests, 3457 assertions)
composer lint   # phpcs, phpstan, psalm clean; phpstan-rules suite 132 tests pass

In the Docker image's default 128 MB memory limit the phpstan-rules suite runs out of memory at the end of the run, on this branch and independent of this change; with memory_limit=-1 it passes.

Checklist

  • composer test and composer lint pass locally, and CI is green on the current head.
  • Every acceptance criterion from the issue is met, or the gap is named below.
  • Nothing a generated plugin relies on changed, or the issue carries breaking and a ruling.
  • Docs and inline comments reflect the change, or nothing documented moved.

Anything left open

Nothing.

@schlessera schlessera added type: test Coverage or test harness work with no behaviour change. area: tests tests/php: unit and integration suites, fixtures. labels Oct 23, 2026
@schlessera
schlessera merged commit 86697de into main Oct 23, 2026
5 checks passed
schlessera added a commit to mwpd/content-freshness that referenced this pull request Oct 23, 2026
Ported from mwpd/basic-scaffold@86697de (mwpd/basic-scaffold#168).

It replaces the plugin's own cron model in the check.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: tests tests/php: unit and integration suites, fixtures. type: test Coverage or test harness work with no behaviour change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tests: the lifecycle idempotency check does not model WP-Cron events

1 participant