Level 23
$this->getJson() and $this->postJson()?
Are you using Laravel? We need a little more info about what you're using. :)
I currently have this testable piece of code to submit a json filled data via post. I let my controller do its thing and respond back.
$responseKey = 'abcdabcd6b1649f681a408f1beebabcd';
$sendJson = $this->createSaleResponse($responseKey);
$sendHeaders = [ 'CONTENT_TYPE' => 'application/json' ];
$response = $this->call(
'POST',
'ext-purchase-api/api/roku/notifications',
[],
[],
[],
$sendHeaders,
$sendJson
);
$this->assertEquals(200, $response->status());
$receiveData = $response->getContent();
$this->assertEquals($responseKey, $receiveData);
$response->assertHeader('ApiKey', $secret);
I am used to the restful API of $this->get and $this->post - is there a better way to format this code?
Note the solution was inspired by: https://stackoverflow.com/questions/46289156/lumen-5-5-unit-test-post-json
Please or to participate in this conversation.