Skip to content

Commit

Permalink
[Revert] Database channel should store custom type too
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkomarev committed Feb 21, 2018
1 parent 0e4b174 commit dadfb95
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 45 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Notifications/Channels/DatabaseChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Illuminate\Notifications\Channels;

use RuntimeException;
use Illuminate\Notifications\Notification;
use RuntimeException;

class DatabaseChannel
{
Expand All @@ -18,7 +18,7 @@ public function send($notifiable, Notification $notification)
{
return $notifiable->routeNotificationFor('database', $notification)->create([
'id' => $notification->id,
'type' => $notification->broadcastAs(),
'type' => get_class($notification),
'data' => $this->getData($notifiable, $notification),
'read_at' => null,
]);
Expand Down
10 changes: 0 additions & 10 deletions src/Illuminate/Notifications/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@ class Notification
*/
public $id;

/**
* Get the type of the broadcasted event.
*
* @return string
*/
public function broadcastAs()
{
return get_class($this);
}

/**
* Get the channels the event should broadcast on.
*
Expand Down
36 changes: 3 additions & 33 deletions tests/Notifications/NotificationDatabaseChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Illuminate\Tests\Notifications;

use Mockery;
use PHPUnit\Framework\TestCase;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Channels\DatabaseChannel;
use Illuminate\Notifications\Messages\DatabaseMessage;
use Illuminate\Notifications\Notification;
use Mockery;
use PHPUnit\Framework\TestCase;

class NotificationDatabaseChannelTest extends TestCase
{
Expand All @@ -31,23 +31,6 @@ public function testDatabaseChannelCreatesDatabaseRecordWithProperData()
$channel = new DatabaseChannel;
$channel->send($notifiable, $notification);
}

public function testDatabaseChannelCreatesDatabaseRecordWithCustomType()
{
$notification = new NotificationDatabaseChannelWithCustomTypeTestNotification;
$notification->id = 1;
$notifiable = Mockery::mock();

$notifiable->shouldReceive('routeNotificationFor->create')->with([
'id' => 1,
'type' => $notification->broadcastAs(),
'data' => ['invoice_id' => 1],
'read_at' => null,
]);

$channel = new DatabaseChannel;
$channel->send($notifiable, $notification);
}
}

class NotificationDatabaseChannelTestNotification extends Notification
Expand All @@ -57,16 +40,3 @@ public function toDatabase($notifiable)
return new DatabaseMessage(['invoice_id' => 1]);
}
}

class NotificationDatabaseChannelWithCustomTypeTestNotification extends Notification
{
public function toDatabase($notifiable)
{
return new DatabaseMessage(['invoice_id' => 1]);
}

public function broadcastAs()
{
return 'custom.type';
}
}

0 comments on commit dadfb95

Please sign in to comment.