Skip to content

Commit

Permalink
Prevent usage of database channel with anonymous notifiable
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints committed Jul 2, 2020
1 parent c914a3e commit 7a98829
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Illuminate/Notifications/AnonymousNotifiable.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Notifications;

use Illuminate\Contracts\Notifications\Dispatcher;
use InvalidArgumentException;

class AnonymousNotifiable
{
Expand All @@ -22,6 +23,10 @@ class AnonymousNotifiable
*/
public function route($channel, $route)
{
if ($channel === 'database') {
throw new InvalidArgumentException('Cannot use database channel for on-demand notifications.');
}

$this->routes[$channel] = $route;

return $this;
Expand Down
11 changes: 11 additions & 0 deletions tests/Notifications/NotificationRoutesNotificationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Illuminate\Container\Container;
use Illuminate\Contracts\Notifications\Dispatcher;
use Illuminate\Notifications\RoutesNotifications;
use Illuminate\Support\Facades\Notification;
use InvalidArgumentException;
use Mockery as m;
use PHPUnit\Framework\TestCase;
use stdClass;
Expand Down Expand Up @@ -50,6 +52,15 @@ public function testNotificationOptionRouting()
$this->assertSame('bar', $instance->routeNotificationFor('foo'));
$this->assertSame('taylor@laravel.com', $instance->routeNotificationFor('mail'));
}

public function testOnDemandNotificationsCannotUseDatabaseChannel()
{
$this->expectExceptionObject(
new InvalidArgumentException('Cannot use database channel for on-demand notifications.')
);

Notification::route('database', 'foo');
}
}

class RoutesNotificationsTestInstance
Expand Down

0 comments on commit 7a98829

Please sign in to comment.