phpunitHow to use PHPUnit json assert?
PHPUnit json assert is a method used to compare two JSON strings. It can be used to check if two JSON strings are equal or not.
Example code
$json1 = '{"name":"John","age":30,"city":"New York"}';
$json2 = '{"name":"John","age":30,"city":"New York"}';
$this->assertJsonStringEqualsJsonString($json1, $json2);
Output example
OK
Code explanation
$json1
and$json2
: two JSON strings to be comparedassertJsonStringEqualsJsonString()
: the method used to compare two JSON strings
Helpful links
More of Phpunit
- How to skip a PHPUnit test?
- How to run tests in parallel with PHPUnit?
- How to use hooks in PHPUnit?
- What are PHPUnit required extensions
- How to use the PHPUnit Framework TestCase?
- How to run PHPUnit in quiet mode?
- How to show warnings in PHPUnit?
- How to load fixtures with PHPUnit?
- How to use a listener with PHPUnit?
- How to stop PHPUnit on failure?
See more codes...