I need help in creating a unit test case for Laravel. It's an API end point accepting a json as the POST payload (NOT POST form) and basically just creating an entry in the database based on that json object. The API works fine but I'm having trouble in creating the unit test.
The controller code contains
$request = Request::instance();
$content = $request->getContent();
$inputRequest = json_decode($content);
I don't know how to pass the payload into the unit test code (extending Illuminate\Foundation\Testing\TestCase
)
Anyone able to help?
Thanks heaps
when using call() method provided by laravel in a unit test.
the sixth parameter $content(String) can be used to pass in the post payload in test case class:
$this->call($method, $uri, $parameters, $files, $server, jsonencode($yourdata), $changeHistory);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With