-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[JsonPath] Add JsonPathAssertionsTrait
and related constraints
#60105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 7.3
Are you sure you want to change the base?
[JsonPath] Add JsonPathAssertionsTrait
and related constraints
#60105
Conversation
4325a17
to
59965aa
Compare
src/Symfony/Component/JsonPath/Tests/Test/JsonPathAssertionsTraitTest.php
Outdated
Show resolved
Hide resolved
59965aa
to
86cd504
Compare
src/Symfony/Component/JsonPath/Test/JsonPathAssertionsTrait.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/JsonPath/Tests/Test/JsonPathAssertionsTraitTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/JsonPath/Test/JsonPathAssertionsTrait.php
Outdated
Show resolved
Hide resolved
86cd504
to
5afe345
Compare
@stof All your comments are addressed, I pushed a new version with "standalone" constraints as done in BrowserKit. |
JsonPathAssertionsTrait
JsonPathAssertionsTrait
and related constraints
JsonPathAssertionsTrait
and related constraintsJsonPathAssertionsTrait
and related constraints
JsonPathAssertionsTrait
and related constraintsJsonPathAssertionsTrait
and related constraints
… (alexandre-daubois) This PR was merged into the 7.3 branch. Discussion ---------- [JsonPath] Add two utils methods to `JsonPath` builder | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | - | License | MIT Small DX improvements that goes with #60105 and #60083. This PR adds two new methods, `first()` and `last()`, added to JsonPath builder. This voluntary reminds methods from the DomCrawler component. The goal is not to add every possible method, but I think `first()` and `last()` are common enough to be added. I also propose to rename `anyIndex()` to `all()`. ```php $path = new JsonPath(); // Get the first user of the collection $path = $path->key('users')->first(); ``` ```php $path = new JsonPath(); // Get the last user of the collection $path = $path->key('users')->last(); ``` ```php $path = new JsonPath(); // Get all users of the collection $path = $path->key('users')->all(); ``` Commits ------- 3bc3559 [JsonPath][DX] Add utils methods to `JsonPath` builder
JsonPathAssertionsTrait
and related constraintsJsonPathAssertionsTrait
and related constraints
src/Symfony/Component/JsonPath/Test/JsonPathAssertionsTrait.php
Outdated
Show resolved
Hide resolved
5afe345
to
bbe4a62
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API Platform has a useful assertJsonContains
method that matches an array subset.
You can add assertJsonPathSubset
src/Symfony/Component/JsonPath/Test/JsonPathAssertionsTrait.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/JsonPath/Test/JsonPathAssertionsTrait.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/JsonPath/Test/JsonPathAssertionsTrait.php
Outdated
Show resolved
Hide resolved
bbe4a62
to
f03afed
Compare
@GromNaN indeed, good idea of feature! I'll have a look at it a bit later when I have a some time to dig the subject on why Sebastian deprecated the feature in PHPUnit first 🙂 Thanks for the review! |
Let's leverage JsonPath in test cases. I propose to add a new trait to ease testing JSON strings against JsonPath: