Skip to content

Fix ApiContext header step matching (quoted regex + JSON shortcut)#59

Closed
zakhar-huzenko wants to merge 2 commits into
developfrom
cursor/fix-api-context-header-steps-0cec
Closed

Fix ApiContext header step matching (quoted regex + JSON shortcut)#59
zakhar-huzenko wants to merge 2 commits into
developfrom
cursor/fix-api-context-header-steps-0cec

Conversation

@zakhar-huzenko
Copy link
Copy Markdown
Contributor

@zakhar-huzenko zakhar-huzenko commented May 11, 2026

Summary

Turnip placeholders (:headerName, :value) only match unquoted tokens built from [\w.,]+ (no -, no /). That breaks real headers such as Content-Type and MIME values such as application/json, which led consumers to work around the context with reflection.

Changes

  • Request header steps now use explicit regex patterns that require double-quoted header names and values, so Content-Type and application/json match reliably.
  • Multiline request header step uses the same quoted header name rule.
  • Given the request JSON content type is used sets Content-Type: application/json so POST/PUT/PATCH JSON-encoding in iSendRequestToRoute is obvious without a separate hack context.
  • Response header (Then / And) steps updated to the same quoted form for consistency.
  • docs/steps.md: documents the quoting requirement, the JSON shortcut, JSON body encoding for write methods, and a short breaking-change note for unquoted header steps.
  • Tests: ApiContextStepPatternTest asserts the regex matches quoted Content-Type / application/json and rejects the old unquoted form; unit test for the new JSON content-type step. Step-pattern test uses preg_match + default policy constructors so Behat 3.6 (composer --prefer-lowest) passes CI.

Verification

composer run dev-checks (composer validate, PHPStan max, PHPCS, PHPUnit) passes on this branch. PHPUnit also passes with composer update --prefer-lowest.

Open in Web Open in Cursor 

…e step

Use regex step patterns so Content-Type and application/json bind correctly
instead of Turnip tokens that omit hyphens and slashes. Add a dedicated
Given the request JSON content type is used step and document JSON body
encoding on POST/PUT/PATCH. Align response header assertions with the same
quoting rules.

Co-authored-by: Zakhar <zahar.guzenko@gmail.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.12%. Comparing base (0c06f56) to head (ecb08dc).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@              Coverage Diff              @@
##             develop      #59      +/-   ##
=============================================
+ Coverage      98.10%   98.12%   +0.01%     
- Complexity        75       76       +1     
=============================================
  Files              6        6              
  Lines            264      266       +2     
=============================================
+ Hits             259      261       +2     
  Misses             5        5              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Use default Regex/Turnip policy constructors and preg_match instead of
SimpleStepMethodNameSuggester and PatternTransformer::matchPattern, which
exist only in newer Behat releases.

Co-authored-by: Zakhar <zahar.guzenko@gmail.com>
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