From 9660faf2f93501ed905a8f26d272b3f02d336e1c Mon Sep 17 00:00:00 2001 From: lukinovec Date: Mon, 13 Apr 2026 14:10:05 +0200 Subject: [PATCH] Ensure Slack throws cURL exception in test --- .../LogTenancyBootstrapperTest.php | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/tests/Bootstrappers/LogTenancyBootstrapperTest.php b/tests/Bootstrappers/LogTenancyBootstrapperTest.php index 469fed6f..e83b2710 100644 --- a/tests/Bootstrappers/LogTenancyBootstrapperTest.php +++ b/tests/Bootstrappers/LogTenancyBootstrapperTest.php @@ -350,6 +350,22 @@ test('slack channel uses correct webhook urls', function () { 'logging.channels.slack.level' => 'debug', // Set level to debug to keep the tests simple, since the default level here is 'critical' ]); + $assertWebhook = function (string $expectedWebhook, string $message): void { + $thrown = false; + + // Because the Slack channel uses cURL to send messages, we cannot use Http::fake() here. + // Instead, we catch the exception and check the error message which contains the actual webhook URL + // (logging always throws "Curl error (code 6): Could not resolve host: {webhook_url}"). + try { + Log::channel('slack')->info($message); + } catch (Exception $e) { + $thrown = true; + expect($e->getMessage())->toContain($expectedWebhook); + } + + expect($thrown)->toBeTrue(); + }; + $tenant1 = Tenant::create(['id' => 'tenant1', 'slackUrl' => 'tenant1-webhook']); $tenant2 = Tenant::create(['id' => 'tenant2', 'slackUrl' => 'tenant2-webhook']); @@ -358,27 +374,13 @@ test('slack channel uses correct webhook urls', function () { ]; // Test central context - should attempt to use central webhook - // Because the Slack channel uses cURL to send messages, we cannot use Http::fake() here. - // Instead, we catch the exception and check the error message which contains the actual webhook URL. - try { - Log::channel('slack')->info('central'); - } catch (Exception $e) { - expect($e->getMessage())->toContain('central-webhook'); - } + $assertWebhook('central-webhook', 'central'); // Slack channel should attempt to use the tenant-specific webhooks - tenancy()->runForMultiple([$tenant1, $tenant2], function (Tenant $tenant) { - try { - Log::channel('slack')->info($tenant->id); - } catch (Exception $e) { - expect($e->getMessage())->toContain($tenant->slackUrl); - } + tenancy()->runForMultiple([$tenant1, $tenant2], function (Tenant $tenant) use ($assertWebhook) { + $assertWebhook($tenant->slackUrl, $tenant->id); }); // Central context, central webhook should be used again - try { - Log::channel('slack')->info('central'); - } catch (Exception $e) { - expect($e->getMessage())->toContain('central-webhook'); - } + $assertWebhook('central-webhook', 'central'); });