From 13d7945e298f32c32cfde38ad9b33611a0b2a339 Mon Sep 17 00:00:00 2001 From: GuntherDebrauwer <22586858+GuntherDebrauwer@users.noreply.github.com> Date: Thu, 30 Apr 2020 16:25:07 +0200 Subject: [PATCH 1/2] Use default webhook response as fallback --- src/WebhookConfig.php | 7 ++++--- tests/WebhookConfigTest.php | 9 +++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/WebhookConfig.php b/src/WebhookConfig.php index 80c5309..0de7571 100644 --- a/src/WebhookConfig.php +++ b/src/WebhookConfig.php @@ -3,9 +3,10 @@ namespace Spatie\WebhookClient; 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; +use Spatie\WebhookClient\SignatureValidator\SignatureValidator; 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() { From f45929cf9ede3aeca924d9227943b57b4bfc8a3a Mon Sep 17 00:00:00 2001 From: GuntherDebrauwer <22586858+GuntherDebrauwer@users.noreply.github.com> Date: Thu, 30 Apr 2020 16:26:21 +0200 Subject: [PATCH 2/2] Fix StyleCI issue --- src/WebhookConfig.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WebhookConfig.php b/src/WebhookConfig.php index 0de7571..dc4add6 100644 --- a/src/WebhookConfig.php +++ b/src/WebhookConfig.php @@ -3,10 +3,10 @@ namespace Spatie\WebhookClient; 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; -use Spatie\WebhookClient\SignatureValidator\SignatureValidator; class WebhookConfig {