Testing Laravel route that listens for a webhook

耗尽温柔 提交于 2019-12-10 15:47:44

问题


Seems like I am missing something here, but I am struggling to implement a test for Laravel that integrates a SendOwl webhook.

Here is the doc I am using: https://help.sendowl.com/help/using-web-hooks

Note I have already added the route to exclude in VerifyCSRFToken

Using ngrok (setting the webhook to go to the ngrok url for local dev) I have confirmed that the controller code is working correctly manually, and the webhook works.

What I am stuck on is how to actually implement a test that can automate this. This for example, does not work if you try to assert status, it will be 500.

$response = $this->call('post', '/listenhere', ['json'=>json_decode($json, true)]);

回答1:


The call method was rolled out with Laravel4.2. It is no longer used to simulate HTTP requests within your tests.

Since v5.2, Laravel provides a json helper for testing JSON APIs and their responses.

For example, you can now:

$response = $this->post('POST', '/listenhere', json_decode($json, true));
$response->assertStatus(200);
$response->assertJson(['created' => true]);


来源:https://stackoverflow.com/questions/47463547/testing-laravel-route-that-listens-for-a-webhook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!