test: add regression tests for scalar value casting with asRoot - #831
Merged
Conversation
Route and query parameters coming from an HTTP request are strings, and the mapper enables scalar value casting for them. The existing `asRoot` test cases only use native values (`42` instead of `'42'`), so that path is never exercised with the string values a framework actually provides. These tests cover mapping all query parameters to a shaped array and to an object, both with a string value mapped to an `int`.
Member
|
Thank you! |
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.
Route and query parameters from an HTTP request are always strings, and the mapper enables scalar value casting for them, as documented:
The existing
asRoottest cases pass native values ('anotherQueryParameter' => 42); that path is never exercised with the strings a real framework provides. This adds two cases: one mapping all query parameters to a shaped array, one to an object alongside a#[FromRoute]parameter.This is not a bug report:
masteralready behaves correctly. The bug existed on2.5.1and was fixed incidentally by 578bd58 (chore: refactor HTTP request mapping), a commit not yet in any release. These tests pin the fix down.Reproduction on
2.5.1:These tests guard the fix. Reverting the change in
HttpRequestNodeBuilder(excluding theasRootkey fromallowScalarValueCastingForChildren()) makes both fail withValue '42' is not a valid integer; the other 56 cases in the file pass.Happy to adjust naming or placement if you prefer them elsewhere.