Currently, I'm using assertJsonStructure in order to validate the structure, but it doesn't check the exact JSON structure, for example:
[
{"id":1, "name": "Bueno Aires", "slug": "buenos-aires"},
{"id":2, "name": "Neuquén", "slug": "neuquen"},
{"id":3, "name": "Córdoba", "slug": "cordoba"}
]
Test results are:
assertJsonStructure([['id', 'name', 'slug']]);: true
assertJsonStructure([['id', 'name']]);: true
Test results expected:
assertJsonStructure([['id', 'name', 'slug']]);: true
assertJsonStructure([['id', 'name']]);: false
Is there some way to validate that?
If you want to assert exactly the same json, checkout this package that add snapshot methods to PHPUnit: https://github.com/spatie/phpunit-snapshot-assertions
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community