PHP code example of ezitisitis / phpunit-json-assert
1. Go to this page and download the library: Download ezitisitis/phpunit-json-assert library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ezitisitis / phpunit-json-assert example snippets
use Helmich\JsonAssert\JsonAssertions;
use PHPUnit\Framework\TestCase;
class MyTestCase extends TestCase
{
use JsonAssertions;
public function testJsonDocumentIsValid()
{
$jsonDocument = [
'id' => 1000,
'username' => 'mhelmich',
'given_name' => 'Martin',
'family_name' => 'Helmich',
'age' => 27,
'hobbies' => [
"Heavy Metal",
"Science Fiction",
"Open Source Software"
]
];
$this->assertJsonValueEquals($jsonDocument, '$.username', 'mhelmich');
$this->assertJsonValueEquals($jsonDocument, '$.hobbies[*]', 'Open Source Software');
}
}