Skip to content

Check declared service IDs against the plugin's service prefix - #165

Merged
schlessera merged 2 commits into
mainfrom
test/162-service-id-prefix
Oct 23, 2026
Merged

schlessera merged 2 commits into
mainfrom
test/162-service-id-prefix

Conversation

@schlessera

Copy link
Copy Markdown
Member

Closes #162

What changed

The composition-root contract now checks every key of a root's get_service_classes() against that root's own SERVICE_PREFIX, read by reflection like HOOK_PREFIX already is. An unprefixed ID, or any ID under an empty prefix, fails as architecture.serviceIdsPrefixed with the ID, the root and the configured prefix, and says how to fix it. The principle-13 row in docs/architecture-rules.md now names the rule, and "prefixes of service identifiers" leaves the manual-review column. IDs added by runtime filters stay outside the check and are listed that way in the docs.

Why this shape

The check inspects only the recorded declaration keys, so it neither resolves callables nor builds services. It lives in CompositionRootContract rather than a PHPStan rule because the IDs are array keys built from a constant, which the contract already reads declaratively. Existing fixture roots got a SERVICE_PREFIX and prefixed IDs instead of the check being loosened.

Proof

New tests were written first. Before the change, 3 of the 4 new tests failed because invalid IDs produced no diagnostic. They cover an unprefixed ID with the full diagnostic asserted, a fixture root with a different prefix that passes with its own IDs and fails with sample-plugin IDs, and an empty prefix.

composer test   # PHP 8.3: OK (579 tests, 3392 assertions)
composer lint   # PHP 8.3: phpcs, phpstan, psalm, PHPStan rule tests all pass

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. Generated roots that declare unprefixed IDs will now fail this check and must correct them.

@schlessera schlessera added type: test Coverage or test harness work with no behaviour change. area: tests tests/php: unit and integration suites, fixtures. area: tooling composer.json, PHPCS, PHPStan, Psalm and Rector configuration. labels Oct 23, 2026
@schlessera
schlessera merged commit 1241979 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@1241979 (mwpd/basic-scaffold#165).

The plugin's own cron fixtures go too: the scaffold's cron model, ported further on, brings its own.
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. area: tooling composer.json, PHPCS, PHPStan, Psalm and Rector configuration. 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: enforce the plugin prefix on declared service identifiers

1 participant