Skip to content

Commit

Permalink
Merge pull request #17 from localhousee/main
Browse files Browse the repository at this point in the history
feat: format newline on `message` function
  • Loading branch information
freekmurze authored Nov 7, 2022
2 parents 22e74ae + e06b25e commit 2ea5720
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/DiscordAlert.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public function message(string $text): void
{
$webhookUrl = Config::getWebhookUrl($this->webhookUrlName);

$text = $this->parseNewline($text);

$jobArguments = [
'text' => $text,
'webhookUrl' => $webhookUrl,
Expand All @@ -26,4 +28,9 @@ public function message(string $text): void

dispatch($job);
}

private function parseNewline(string $text): string
{
return str_replace('\n', PHP_EOL, $text);
}
}
10 changes: 10 additions & 0 deletions tests/DiscordAlertsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,13 @@

DiscordAlert::message('test-data');
})->throws(JobClassDoesNotExist::class);

it('will convert a newline string (\n) into a PHP_EOL constant', function() {
config()->set('discord-alerts.webhook_urls.default', 'https://test-domain.com');

DiscordAlert::message('test \n data');

Bus::assertDispatched(function (SendToDiscordChannelJob $job) {
return $job->text === "test " . PHP_EOL . " data";
});
});

0 comments on commit 2ea5720

Please sign in to comment.