Skip to content

Commit

Permalink
Use default webhook response as fallback (#60)
Browse files Browse the repository at this point in the history
* Use default webhook response as fallback

* Fix StyleCI issue

Co-authored-by: GuntherDebrauwer <[email protected]>
  • Loading branch information
gdebrauwer and gdebrauwer authored Apr 30, 2020
1 parent d21404f commit 8cf08be
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/WebhookConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'];

Expand Down
9 changes: 9 additions & 0 deletions tests/WebhookConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit 8cf08be

Please sign in to comment.