Fix ApiContext header step matching (quoted regex + JSON shortcut)#59
Closed
zakhar-huzenko wants to merge 2 commits into
Closed
Fix ApiContext header step matching (quoted regex + JSON shortcut)#59zakhar-huzenko wants to merge 2 commits into
zakhar-huzenko wants to merge 2 commits into
Conversation
…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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Turnip placeholders (
:headerName,:value) only match unquoted tokens built from[\w.,]+(no-, no/). That breaks real headers such asContent-Typeand MIME values such asapplication/json, which led consumers to work around the context with reflection.Changes
Content-Typeandapplication/jsonmatch reliably.Given the request JSON content type is usedsetsContent-Type: application/jsonso POST/PUT/PATCH JSON-encoding iniSendRequestToRouteis obvious without a separate hack context.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.ApiContextStepPatternTestasserts the regex matches quotedContent-Type/application/jsonand rejects the old unquoted form; unit test for the new JSON content-type step. Step-pattern test usespreg_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 withcomposer update --prefer-lowest.