-
Notifications
You must be signed in to change notification settings - Fork 664
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for notification class overrides (#1518)
* Add support for notification class overrides * use container * add test --------- Co-authored-by: Luke Morcom <[email protected]> Co-authored-by: Taylor Otwell <[email protected]>
- Loading branch information
1 parent
88bc1f9
commit 4c30f9c
Showing
5 changed files
with
68 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Laravel\Horizon\Contracts; | ||
|
||
interface LongWaitDetectedNotification | ||
{ | ||
// | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Laravel\Horizon\Tests\Feature; | ||
|
||
use Illuminate\Container\Container; | ||
use Illuminate\Notifications\Messages\MailMessage; | ||
use Illuminate\Support\Facades\Notification; | ||
use Laravel\Horizon\Contracts\LongWaitDetectedNotification as LongWaitDetectedNotificationContract; | ||
use Laravel\Horizon\Events\LongWaitDetected; | ||
use Laravel\Horizon\Horizon; | ||
use Laravel\Horizon\Notifications\LongWaitDetected as LongWaitDetectedNotification; | ||
use Laravel\Horizon\Tests\IntegrationTest; | ||
|
||
class NotificationOverridesTest extends IntegrationTest | ||
{ | ||
public function test_custom_notifications_are_sent_if_specified() | ||
{ | ||
Notification::fake(); | ||
|
||
Horizon::routeMailNotificationsTo('[email protected]'); | ||
|
||
Container::getInstance()->bind(LongWaitDetectedNotificationContract::class, CustomLongWaitDetectedNotification::class); | ||
|
||
event(new LongWaitDetected('redis', 'test-queue-2', 60)); | ||
|
||
Notification::assertSentOnDemand(CustomLongWaitDetectedNotification::class); | ||
} | ||
|
||
public function test_normal_notifications_are_sent_if_not_specified() | ||
{ | ||
Notification::fake(); | ||
|
||
Horizon::routeMailNotificationsTo('[email protected]'); | ||
|
||
event(new LongWaitDetected('redis', 'test-queue-2', 60)); | ||
|
||
Notification::assertSentOnDemand(LongWaitDetectedNotification::class); | ||
} | ||
} | ||
|
||
class CustomLongWaitDetectedNotification extends LongWaitDetectedNotification implements LongWaitDetectedNotificationContract | ||
{ | ||
public function toMail($notifiable) | ||
{ | ||
return (new MailMessage) | ||
->line('This is a custom notification for a long wait.'); | ||
} | ||
} |