Skip to content

Add RuleConventionsTest to enforce rule registration conventions#992

Open
mglaman wants to merge 4 commits into
mainfrom
claude/add-phpunit-drupal-rule-dv3Tp
Open

Add RuleConventionsTest to enforce rule registration conventions#992
mglaman wants to merge 4 commits into
mainfrom
claude/add-phpunit-drupal-rule-dv3Tp

Conversation

@mglaman
Copy link
Copy Markdown
Owner

@mglaman mglaman commented May 19, 2026

Adds tests/src/RuleConventionsTest.php which parses rules.neon,
extension.neon, and bleedingEdge.neon and asserts that every rule is
toggleable: registered via conditionalTags with a boolean default under
parameters.drupal.rules, opt-in rules enabled in bleedingEdge.neon, and
no new rules added directly under rules:. Graduated rules (default
true) are tracked via an explicit allowlist.

Fixes the pre-existing convention violation surfaced by the test:
pluginManagerInspectionRule was opt-in (false default) but missing from
bleedingEdge.neon.

Adds AGENTS.md documenting the conventions for contributors and agents,
and nette/neon as a dev dependency for parsing the neon files.

Closes #971

https://claude.ai/code/session_01AAChSrMEaL4S6st2ET2JRF

claude added 4 commits May 19, 2026 13:23
Adds tests/src/RuleConventionsTest.php which parses rules.neon,
extension.neon, and bleedingEdge.neon and asserts that every rule is
toggleable: registered via conditionalTags with a boolean default under
parameters.drupal.rules, opt-in rules enabled in bleedingEdge.neon, and
no new rules added directly under rules:. Graduated rules (default
true) are tracked via an explicit allowlist.

Fixes the pre-existing convention violation surfaced by the test:
pluginManagerInspectionRule was opt-in (false default) but missing from
bleedingEdge.neon.

Adds AGENTS.md documenting the conventions for contributors and agents,
and nette/neon as a dev dependency for parsing the neon files.

Closes #971

https://claude.ai/code/session_01AAChSrMEaL4S6st2ET2JRF
The rule is too unreliable to enable for bleeding-edge users. Instead of
adding it to bleedingEdge.neon, record the deliberate exception in
RuleConventionsTest::OPT_IN_RULES_EXCLUDED_FROM_BLEEDING_EDGE so the
conventions test stays green and the exclusion is explicit and
documented. Reverts the earlier bleedingEdge.neon addition and documents
the exception mechanism in AGENTS.md.

https://claude.ai/code/session_01AAChSrMEaL4S6st2ET2JRF
Drop the separate AGENTS.md and document the toggleable-rule conventions
in the existing CLAUDE.md instead. Update RuleConventionsTest failure
messages to point at CLAUDE.md.

https://claude.ai/code/session_01AAChSrMEaL4S6st2ET2JRF
Access the preg_match capture group only inside the `=== 1` branch so
PHPStan can prove the offset exists, instead of relying on an assertSame
that does not narrow the matches array.

https://claude.ai/code/session_01AAChSrMEaL4S6st2ET2JRF
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an automated PHPUnit guardrail to enforce this repository’s PHPStan rule registration conventions (toggleable rules via conditionalTags + parameters.drupal.rules, and a frozen legacy rules: list), and documents the conventions for contributors.

Changes:

  • Add RuleConventionsTest that parses rules.neon, extension.neon, and bleedingEdge.neon to enforce rule toggleability conventions.
  • Add nette/neon (dev) dependency to decode NEON config in tests.
  • Document rule registration conventions in CLAUDE.md.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tests/src/RuleConventionsTest.php New PHPUnit test enforcing rule registration/toggleability conventions across NEON configs.
composer.json Adds nette/neon to require-dev for NEON parsing in tests.
CLAUDE.md Documents the rule registration conventions and graduation workflow.
Comments suppressed due to low confidence (2)

tests/src/RuleConventionsTest.php:115

  • The test name testConditionalRulesHaveFalseDefaultInExtensionNeon is misleading because the body explicitly allows (and asserts) true defaults for parameters listed in GRADUATED_RULES. Rename the test to reflect the actual convention being enforced (e.g., “conditional rules have a boolean default; non-graduated default false”).
    public function testConditionalRulesHaveFalseDefaultInExtensionNeon(): void
    {
        $defaults = $this->extensionRuleDefaults();

        foreach ($this->conditionalRuleParameters() as $parameter) {

tests/src/RuleConventionsTest.php:167

  • The comment says graduated rules “must not be listed in bleedingEdge.neon”, but the test currently just continues when the default isn’t false and never asserts absence in $bleedingEdge. Add an assertion that graduated (default true) rule parameters are not present in bleedingEdge.neon so the convention is actually enforced.
        foreach ($this->conditionalRuleParameters() as $parameter) {
            if (!array_key_exists($parameter, $defaults) || $defaults[$parameter] !== false) {
                // Graduated rules (default `true`) are already on by default and
                // must not be listed in bleedingEdge.neon.
                continue;

Comment on lines +82 to +86
private const OPT_IN_RULES_EXCLUDED_FROM_BLEEDING_EDGE = [
// PluginManagerInspectionRule is currently too unreliable to enable by
// default for bleeding-edge users.
'pluginManagerInspectionRule',
];
Comment thread CLAUDE.md
Comment on lines +34 to +38
## Rule Registration Conventions

Every rule must be **toggleable**. Never add a new rule directly under `rules:`
in `rules.neon` — that section is frozen for legacy rules and
`tests/src/RuleConventionsTest.php` fails if it grows.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add PHPUnit test to enforce rule registration conventions

3 participants