|
8 | 8 | use Illuminate\Contracts\Queue\ShouldQueue;
|
9 | 9 | use Illuminate\Notifications\AnonymousNotifiable;
|
10 | 10 | use Illuminate\Notifications\ChannelManager;
|
| 11 | +use Illuminate\Notifications\Events\NotificationFailed; |
| 12 | +use Illuminate\Notifications\Events\NotificationSending; |
11 | 13 | use Illuminate\Notifications\Notifiable;
|
12 | 14 | use Illuminate\Notifications\Notification;
|
13 | 15 | use Illuminate\Notifications\NotificationSender;
|
14 | 16 | use Mockery as m;
|
15 | 17 | use PHPUnit\Framework\TestCase;
|
| 18 | +use Symfony\Component\Mailer\Exception\HttpTransportException; |
| 19 | +use Symfony\Component\Mailer\Exception\TransportException; |
| 20 | +use Symfony\Contracts\HttpClient\ResponseInterface; |
16 | 21 |
|
17 | 22 | class NotificationSenderTest extends TestCase
|
18 | 23 | {
|
@@ -138,6 +143,29 @@ public function testItCanSendQueuedWithViaConnectionsNotifications()
|
138 | 143 |
|
139 | 144 | $sender->send($notifiable, new DummyNotificationWithViaConnections);
|
140 | 145 | }
|
| 146 | + |
| 147 | + public function testNotificationFailedSentWithoutHttpTransportException() |
| 148 | + { |
| 149 | + $this->expectException(TransportException::class); |
| 150 | + |
| 151 | + $notifiable = new AnonymousNotifiable(); |
| 152 | + $manager = m::mock(ChannelManager::class); |
| 153 | + $manager->shouldReceive('driver')->andReturn($driver = m::mock()); |
| 154 | + $response = m::mock(ResponseInterface::class); |
| 155 | + $driver->shouldReceive('send')->andThrow(new HttpTransportException('Transport error', $response)); |
| 156 | + $bus = m::mock(BusDispatcher::class); |
| 157 | + |
| 158 | + $events = m::mock(EventDispatcher::class); |
| 159 | + $events->shouldReceive('listen')->once(); |
| 160 | + $events->shouldReceive('until')->with(m::type(NotificationSending::class))->andReturn(true); |
| 161 | + $events->shouldReceive('dispatch')->once()->withArgs(function ($event) { |
| 162 | + return $event instanceof NotificationFailed && $event->data['exception'] instanceof TransportException; |
| 163 | + }); |
| 164 | + |
| 165 | + $sender = new NotificationSender($manager, $bus, $events); |
| 166 | + |
| 167 | + $sender->sendNow($notifiable, new DummyNotificationWithViaConnections(), ['mail']); |
| 168 | + } |
141 | 169 | }
|
142 | 170 |
|
143 | 171 | class DummyQueuedNotificationWithStringVia extends Notification implements ShouldQueue
|
|
0 commit comments