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 show warnings in PHPUnit?
- How to generate a coverage report with PHPUnit?
- How to check if a JSON contains a value in PHPUnit?
- How to stop PHPUnit on failure?
- How to skip a PHPUnit test?
- How to mock a method with different arguments in PHPUnit?
- What are PHPUnit required extensions
- How to install PHPUnit with a PHAR file?
- How to run tests in parallel with PHPUnit?
- How to order tests with PHPUnit?
See more codes...