Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly Implode Nested(Array) Notification Routes To Fix Array To String Conversion Exception #778

Merged
merged 3 commits into from
Nov 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Watchers/NotificationWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ private function formatNotifiable($notifiable)
if ($notifiable instanceof Model) {
return FormatModel::given($notifiable);
} elseif ($notifiable instanceof AnonymousNotifiable) {
return 'Anonymous:'.implode(',', $notifiable->routes);
$routes = array_map(function ($route) {
return is_array($route) ? implode(',', $route) : $route;
}, $notifiable->routes);

return 'Anonymous:'.implode(',', $routes);
}

return get_class($notifiable);
Expand Down
18 changes: 14 additions & 4 deletions tests/Watchers/NotificationWatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,26 @@ protected function getEnvironmentSetUp($app)

public function test_notification_watcher_registers_entry()
{
Notification::route('mail', 'telescope@laravel.com')
->notify(new BoomerangNotification);
$this->performNotificationAssertions('mail', 'telescope@laravel.com');
}

public function test_notification_watcher_registers_array_routes()
{
$this->performNotificationAssertions('mail', ['telescope@laravel.com', 'nestedroute@laravel.com']);
}

private function performNotificationAssertions($channel, $route)
{
Notification::route($channel, $route)
->notify(new BoomerangNotification);

$entry = $this->loadTelescopeEntries()->first();

$this->assertSame(EntryType::NOTIFICATION, $entry->type);
$this->assertSame(BoomerangNotification::class, $entry->content['notification']);
$this->assertSame(false, $entry->content['queued']);
$this->assertStringContainsString('telescope@laravel.com', $entry->content['notifiable']);
$this->assertSame('mail', $entry->content['channel']);
$this->assertStringContainsString(is_array($route) ? implode(',', $route) : $route, $entry->content['notifiable']);
$this->assertSame($channel, $entry->content['channel']);
$this->assertNull($entry->content['response']);
}
}
Expand Down