Skip to content

Commit

Permalink
Merge pull request #778 from srinathreddydudi/nested-notification-routes
Browse files Browse the repository at this point in the history
Properly Implode Nested(Array) Notification Routes To Fix Array To String Conversion Exception
  • Loading branch information
taylorotwell authored Nov 23, 2019
2 parents 96df0ce + 7a4ad5f commit 05af183
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
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

0 comments on commit 05af183

Please sign in to comment.