Skip to content

Read Behat step definitions from PHP attributes - #686

Merged
swissspidy merged 1 commit into
mainfrom
claude/sweet-hawking-po05uc
Dec 1, 2026
Merged

swissspidy merged 1 commit into
mainfrom
claude/sweet-hawking-po05uc

Conversation

@swissspidy

@swissspidy swissspidy commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

wp-cli/wp-cli-tests v5.6.0 (wp-cli/wp-cli-tests#428) moved the Behat step definitions from @Given/@When/@Then docblock annotations to PHP attributes (#[Given( '...' )]). gen-behat-docs only parsed the annotations, so it found no steps and deleted every page under references/behat-steps/, as seen in #685.

This also reads Behat\Step\Given|When|Then attributes via reflection and feeds them into the same behat_step / parameters structure the docblock parser produces. Docblock parsing is kept as a fallback for older versions.

Tested against wp-cli-tests main: all 49 public step definitions resolve, and step names match the previous format (e.g. Given /^an? (empty|non-existent) ([^\s]+) directory$/).


Generated by Claude Code

Summary by CodeRabbit

  • New Features
    • API documentation now includes step names and patterns declared through supported PHP attributes, making those details available in the handbook representation.
    • Existing step names and parameter entries are preserved when attribute information is processed.

wp-cli-tests v5.6.0 declares step definitions with attributes such as
#[Given( 'an empty directory' )] instead of @given docblock annotations.
The generator only parsed the annotations, so it found no steps and
removed all Behat steps pages. Read the attributes as well, keeping
the docblock parsing as a fallback for older versions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UWTd5qhPpccgCgUjqYTBZP
@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The handbook generator now reads supported Behat PHP attributes and adds step names and patterns to parsed PHPDoc before building the API representation. Existing step names and parameter entries remain unchanged.

Changes: Behat Attribute Parsing

Layer / File(s) Summary
Read Behat attributes
bin/Handbook_Command.php
get_simple_representation() passes the reflection object and parsed PHPDoc to a new parser. The parser reads Given, When, and Then attributes with non-empty string patterns, then adds missing step names and split patterns without replacing existing entries.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

  • wp-cli/handbook#685: This PR restores Behat step pages that were removed after the generator failed to read PHP attributes.

Suggested reviewers: ekamran, ernilambar, schlessera

Merge Risk: Minimal · up to 8d2ab

This change lets the handbook generator read Behat step definitions from PHP attributes, so the behat-steps pages are no longer emptied when wp-cli-tests uses attributes. Docblock definitions keep working as before. No concrete merge risk was found.

Security architecture risk: Minimal · up to 8d2ab

The change restores Behat documentation on newer versions of the test package while retaining support for older annotations. It changes which metadata can name generated pages, but the reviewed change does not give callers new access or expand where the generator can write.

Security review details

Security Blast Radius

  • inferred — The source-supported reach of the new input is the generated Behat and internal API reference content and page names. Both use the existing slug normalizer, which removes characters outside letters, digits, and hyphens before a name is used in a filename.

Trust Boundaries and Controls

  • observed — Both collectors require the existing public-documentation marker before representation construction. The new parser matches the final segment of the attribute name rather than its namespace, so an unrelated attribute named Given, When, or Then on an already selected declaration can also be treated as step metadata.

Resilience and Maintainability Implications

  • observed — Metadata collection completes before either generator clears its output directory. Interruption after cleanup can still leave partial generated output; the PR changes the metadata, not the existing delete-then-write sequence or its recovery behavior.

Hardening Proposals

  • proposed — Consider matching fully qualified Behat attribute names and limiting enrichment to the Behat collector so unrelated attributes cannot rename internal API pages.
Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Read Behat step definitions from PHP attributes" matches the main change. The PR adds parsing of PHP Given, When, and Then attributes in bin/Handbook_Command.php, so step definitions can be…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Read Behat step definitions from PHP attributes" matches the main change. The PR adds parsing of PHP Given, When, and Then attributes in bin/Handbook_Command.php, so step definitions can be read from attributes as well as docblocks. The title is specific and does not use vague terms.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

PHPStan (2.3.5)

Invalid configuration:
Unexpected item 'parameters › strictRules'.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b5c5478e-8d0b-4d99-acc7-f09274da31f1
Commits

Reviewing files that changed from the base of the PR and between aa563e1 and 8d2ab7b.

Files selected for processing: 1

  • bin/Handbook_Command.php

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@swissspidy
swissspidy marked this pull request as ready for review December 1, 2026 16:00
@swissspidy
swissspidy requested a review from a team as a code owner December 1, 2026 16:00
Copilot AI balanced review requested due to automatic review settings December 1, 2026 16:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request. Check if the Files changed in this pull request are included in default exclusions.

@swissspidy
swissspidy merged commit 9f03520 into main Dec 1, 2026
8 checks passed
@swissspidy
swissspidy deleted the claude/sweet-hawking-po05uc branch December 1, 2026 16:04
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.

2 participants