@@ -101,7 +101,7 @@ public function testSend()
101
101
public function testSendThrowsForErrorResponse ()
102
102
{
103
103
$ client = new MockHttpClient (static function (string $ method , string $ url , array $ options ): ResponseInterface {
104
- return new MockResponse (json_encode (['Message ' => 'i \'m a teapot ' , ' ErrorCode ' => 418 ]), [
104
+ return new MockResponse (json_encode (['error ' => 'i \'m a teapot ' ]), [
105
105
'http_code ' => 418 ,
106
106
'response_headers ' => [
107
107
'content-type ' => 'application/json ' ,
@@ -118,7 +118,31 @@ public function testSendThrowsForErrorResponse()
118
118
->text ('Hello There! ' );
119
119
120
120
$ this ->expectException (HttpTransportException::class);
121
- $ this ->expectExceptionMessage ('Unable to send an email: i \'m a teapot (code 418). ' );
121
+ $ this ->expectExceptionMessage ('Unable to send an email: {"error":"i \'m a teapot"} ' );
122
+ $ transport ->send ($ mail );
123
+ }
124
+
125
+ public function testSendThrowsForMultipleErrorResponses ()
126
+ {
127
+ $ client = new MockHttpClient (static function (string $ method , string $ url , array $ options ): ResponseInterface {
128
+ return new MockResponse (json_encode (['errors ' => ["to " => "undefined field " ]]), [
129
+ 'http_code ' => 418 ,
130
+ 'response_headers ' => [
131
+ 'content-type ' => 'application/json ' ,
132
+ ],
133
+ ]);
134
+ });
135
+ $ transport = new OhMySmtpApiTransport ('KEY ' , $ client );
136
+ $ transport ->setPort (8984 );
137
+
138
+ $ mail = new Email ();
139
+ $ mail ->subject ('Hello! ' )
140
+ ->to (new Address ('saif.gmati@symfony.com ' , 'Saif Eddin ' ))
141
+ ->from (new Address ('fabpot@symfony.com ' , 'Fabien ' ))
142
+ ->text ('Hello There! ' );
143
+
144
+ $ this ->expectException (HttpTransportException::class);
145
+ $ this ->expectExceptionMessage ('Unable to send an email: {"errors":{"to":"undefined field"}} ' );
122
146
$ transport ->send ($ mail );
123
147
}
124
148
0 commit comments