PHP code example of sdobreff / json-response-test
1. Go to this page and download the library: Download sdobreff/json-response-test 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/ */
sdobreff / json-response-test example snippets
declare(strict_types=1);
class LocationTest extends BaseApiTest {
public function testGetLocation() {
$addHead = [
'headers' => [
'Authorization' => 'Bearer some-key',
],
];
$response = $this->request(
'/api/v1/search',
'POST',
[
'q' => 'sp',
'filters' => '{}',
],
$addHead
);
$this->assertResponse( $response, 'location/tst.json' );
}
}
declare(strict_types=1);
use JsonResponseTest\APITest\JsonApiTest;
class BaseApiTest extends JsonApiTest {
public function setUp() {
$dir = __DIR__ . '/responses/';
parent::setResponseDir( $dir );
parent::setClient();
parent::setBaseUrl( 'https://local-test.com' );
}
}
{
"users":[
{
"firstName": "Norbert",
"lastName": "Orzechowicz",
"created": "2014-01-01",
"roles":["ROLE_USER", "ROLE_DEVELOPER"],
"attributes": {
"isAdmin": false,
"dateOfBirth": null,
"hasEmailVerified": true
},
"avatar": {
"url": "http://avatar-image.com/avatar.png"
}
},
{
"firstName": "Michał",
"lastName": "Dąbrowski",
"created": "2014-01-01",
"roles":["ROLE_USER", "ROLE_DEVELOPER", "ROLE_ADMIN"],
"attributes": {
"isAdmin": true,
"dateOfBirth": null,
"hasEmailVerified": true
},
"avatar": null
}
]
}