Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeception API testing: stuck at passing json payload to REST service

I found this cool tool called codeception for testing in PHP. I am liking it a lot. I started writing API test cases. But I am stuck at POSTING json payload to a REST service. How can I perform this?

I have a REST end point called /order, which accepts a JSON payload. The service is build on Laravel4, so I accept the payload in Laravel4 using Input::json()->all().

I have tried something like this

$filename = __DIR__.'/createOrder.json';
$I->haveHttpHeader('Content-Type', 'application/json');
**$I->sendPOST('order', null, array($filename));**  
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();

But it gives me 500 internal server error, as my service accepts json payload and not in the form of file.

Anyone has worked on something like this before?

Thanks in advance.

like image 896
Sameer Avatar asked Sep 05 '25 03:09

Sameer


1 Answers

I know this is an old question but for others who stumble on this, try:

$I->haveHttpHeader('Content-Type','application/json');

it definitely should work.

like image 76
tomvo Avatar answered Sep 08 '25 00:09

tomvo