File tree Expand file tree Collapse file tree 3 files changed +15
-8
lines changed Expand file tree Collapse file tree 3 files changed +15
-8
lines changed Original file line number Diff line number Diff line change 66
77use Psr \Http \Message \ResponseInterface ;
88use RuntimeException ;
9+ use Throwable ;
910
1011class CouldNotSendNotification extends RuntimeException
1112{
12- public static function pushbulletRespondedWithAnError (ResponseInterface $ response ): self
13+ public static function pushbulletRespondedWithAnError (ResponseInterface $ response, Throwable $ previous = null ): self
1314 {
1415 $ code = $ response ->getStatusCode ();
1516
1617 $ message = $ response ->getBody ();
1718
18- return new self ("Pushbullet responded with error: ` {$ code } - {$ message }`. " );
19+ return new self ("Pushbullet responded with error: ` {$ code } - {$ message }`. " , 0 , $ previous );
1920 }
2021
2122 public static function providedEmailIsInvalid (string $ email ): self
2223 {
2324 return new self ("Provided email ` {$ email }` of `notifiable` is not valid. " );
2425 }
2526
26- public static function couldNotCommunicateWithPushbullet (): self
27+ public static function couldNotCommunicateWithPushbullet (Throwable $ previous = null ): self
2728 {
28- return new self ('Could not connect to Pushbullet API. ' );
29+ return new self ('Could not connect to Pushbullet API. ' , 0 , $ previous );
2930 }
3031}
Original file line number Diff line number Diff line change @@ -68,9 +68,9 @@ public function send($params): ResponseInterface
6868 'headers ' => $ this ->getHeaders (),
6969 ]);
7070 } catch (ClientException $ exception ) {
71- throw CouldNotSendNotification::pushbulletRespondedWithAnError ($ exception ->getResponse ());
71+ throw CouldNotSendNotification::pushbulletRespondedWithAnError ($ exception ->getResponse (), $ exception );
7272 } catch (Exception $ exception ) {
73- throw CouldNotSendNotification::couldNotCommunicateWithPushbullet ();
73+ throw CouldNotSendNotification::couldNotCommunicateWithPushbullet ($ exception );
7474 }
7575 }
7676}
Original file line number Diff line number Diff line change 44
55namespace NotificationChannels \Pushbullet \Test \Exceptions ;
66
7+ use Exception ;
78use NotificationChannels \Pushbullet \Exceptions \CouldNotSendNotification ;
89use PHPUnit \Framework \TestCase ;
910use Psr \Http \Message \ResponseInterface ;
@@ -24,12 +25,14 @@ public function invalid_email_exception_can_be_created(): void
2425 /** @test */
2526 public function pushbullet_connection_exception_can_be_created (): void
2627 {
27- $ exception = CouldNotSendNotification::couldNotCommunicateWithPushbullet ();
28+ $ previousException = new Exception ();
29+ $ exception = CouldNotSendNotification::couldNotCommunicateWithPushbullet ($ previousException );
2830
2931 $ this ->assertEquals (
3032 'Could not connect to Pushbullet API. ' ,
3133 $ exception ->getMessage ()
3234 );
35+ $ this ->assertSame ($ previousException , $ exception ->getPrevious ());
3336 }
3437
3538 /** @test */
@@ -45,11 +48,14 @@ public function pushbullet_error_exception_can_be_created(): void
4548 ->method ('getBody ' )
4649 ->willReturn ('Oops ' );
4750
48- $ exception = CouldNotSendNotification::pushbulletRespondedWithAnError ($ response );
51+ $ previousException = new Exception ();
52+
53+ $ exception = CouldNotSendNotification::pushbulletRespondedWithAnError ($ response , $ previousException );
4954
5055 $ this ->assertEquals (
5156 'Pushbullet responded with error: `400 - Oops`. ' ,
5257 $ exception ->getMessage ()
5358 );
59+ $ this ->assertSame ($ previousException , $ exception ->getPrevious ());
5460 }
5561}
You can’t perform that action at this time.
0 commit comments