diff --git a/src/WebhookConfig.php b/src/WebhookConfig.php index 80c5309..dc4add6 100644 --- a/src/WebhookConfig.php +++ b/src/WebhookConfig.php @@ -5,6 +5,7 @@ use Spatie\WebhookClient\Exceptions\InvalidConfig; use Spatie\WebhookClient\SignatureValidator\SignatureValidator; use Spatie\WebhookClient\WebhookProfile\WebhookProfile; +use Spatie\WebhookClient\WebhookResponse\DefaultRespondsTo; use Spatie\WebhookClient\WebhookResponse\RespondsToWebhook; class WebhookConfig @@ -43,11 +44,11 @@ public function __construct(array $properties) } $this->webhookProfile = app($properties['webhook_profile']); - $webhookResponseClass = $properties['webhook_response'] ?? RespondsToWebhook::class; + $webhookResponseClass = $properties['webhook_response'] ?? DefaultRespondsTo::class; if (! is_subclass_of($webhookResponseClass, RespondsToWebhook::class)) { throw InvalidConfig::invalidWebhookResponse($webhookResponseClass); } - $this->webhookResponse = app($properties['webhook_response']); + $this->webhookResponse = app($webhookResponseClass); $this->webhookModel = $properties['webhook_model']; diff --git a/tests/WebhookConfigTest.php b/tests/WebhookConfigTest.php index fb1f4b8..18cb235 100644 --- a/tests/WebhookConfigTest.php +++ b/tests/WebhookConfigTest.php @@ -61,6 +61,15 @@ public function it_validates_the_webhook_response() new WebhookConfig($config); } + /** @test */ + public function it_uses_the_default_webhook_response_if_none_provided() + { + $config = $this->getValidConfig(); + $config['webhook_response'] = null; + + $this->assertInstanceOf(DefaultRespondsTo::class, (new WebhookConfig($config))->webhookResponse); + } + /** @test */ public function it_validates_the_process_webhook_job() {