Skip to content

Commit 6ed76b0

Browse files
authored
Add a unique token to route names (#210)
* Adds unique key to route name * Test mulitple routes for a configuration are unique
1 parent ca27d95 commit 6ed76b0

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/WebhookClientServiceProvider.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public function packageBooted()
2727
throw InvalidMethod::make($method);
2828
}
2929

30-
return Route::{$method}($url, '\Spatie\WebhookClient\Http\Controllers\WebhookController')->name("webhook-client-{$name}");
30+
return Route::{$method}($url, '\Spatie\WebhookClient\Http\Controllers\WebhookController')
31+
->name("webhook-client-{$name}." . Str::random(8));
3132
});
3233

3334
$this->app->scoped(WebhookConfigRepository::class, function () {
@@ -43,7 +44,9 @@ public function packageBooted()
4344
$this->app->bind(WebhookConfig::class, function () {
4445
$routeName = Route::currentRouteName() ?? '';
4546

46-
$configName = Str::after($routeName, 'webhook-client-');
47+
$routeNameSuffix = Str::after($routeName, 'webhook-client-');
48+
49+
$configName = Str::before($routeNameSuffix, '.');
4750

4851
$webhookConfig = app(WebhookConfigRepository::class)->getConfig($configName);
4952

tests/WebhookControllerTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,21 @@ public function it_can_store_none_of_the_headers()
204204
$this->assertEquals(0, count(WebhookCall::first()->headers));
205205
}
206206

207+
/** @test */
208+
public function multiple_routes_can_share_configuration()
209+
{
210+
Route::webhooks('incoming-webhooks-additional');
211+
212+
$this->refreshWebhookConfigRepository();
213+
214+
$routeNames = collect(Route::getRoutes())
215+
->map(fn ($route) => $route->getName());
216+
217+
$uniqueRouteNames = $routeNames->unique();
218+
219+
$this->assertEquals($routeNames->count(), $uniqueRouteNames->count());
220+
}
221+
207222
protected function determineSignature(array $payload): string
208223
{
209224
$secret = config('webhook-client.configs.0.signing_secret');

0 commit comments

Comments
 (0)