Testing Webhooks
Testing webhooks
RelayKit includes helpers for feature tests and unit tests.
Fake incoming requests
use RelayKit\Testing\WebhookRequest;
$response = WebhookRequest::fake('payments')
->event('payment_succeeded')
->payload(['customer_id' => 'cus_123'])
->post();
$response->assertAccepted();
Assert a handler was called
RelayKit::fake();
WebhookRequest::fake('payments')
->event('payment_succeeded')
->post();
RelayKit::assertHandled('payments.payment_succeeded');
Test signature failures
WebhookRequest::fake('payments')
->invalidSignature()
->post()
->assertForbidden();
Keep tests focused
Most tests should check one of three things:
- The provider extracts the correct event name
- The signature verifier accepts or rejects a request
- The handler updates your application correctly