问题
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