@@ -89,7 +89,7 @@ public function testPayloadFormat()
89
89
$ this ->assertEquals ('Qux ' , $ replyTo ['Name ' ]);
90
90
}
91
91
92
- public function testDoSendApiSuccess ()
92
+ public function testSendSuccess ()
93
93
{
94
94
$ json = json_encode ([
95
95
'Messages ' => [
@@ -106,63 +106,61 @@ public function testDoSendApiSuccess()
106
106
$ client = new MockHttpClient ($ response );
107
107
108
108
$ transport = new MailjetApiTransport (self ::USER , self ::PASSWORD , $ client );
109
- $ method = new \ReflectionMethod (MailjetApiTransport::class, 'doSendApi ' );
110
- $ method ->setAccessible (true );
111
109
112
110
$ email = new Email ();
113
- $ envelope =
new Envelope (
new Address (
'[email protected] ' ,
'Foo ' ), [
new Address (
'[email protected] ' ,
'Bar ' )]);
114
-
115
- $ sentMessage = $ this ->createMock (SentMessage::class);
116
- $ sentMessage
117
- ->expects (self ::once ())
118
- ->method ('setMessageId ' );
111
+ $ email
112
+
113
+
114
+ ->text ('foobar ' );
119
115
120
- $ method ->invoke ($ transport , $ sentMessage , $ email , $ envelope );
116
+ $ sentMessage = $ transport ->send ($ email );
117
+ $ this ->assertInstanceOf (SentMessage::class, $ sentMessage );
118
+ $ this ->assertSame ('baz ' , $ sentMessage ->getMessageId ());
121
119
}
122
120
123
- public function testDoSendApiWithDecodingException ()
121
+ public function testSendWithDecodingException ()
124
122
{
125
123
$ response = new MockResponse ('cannot-be-decoded ' );
126
124
127
125
$ client = new MockHttpClient ($ response );
128
126
129
127
$ transport = new MailjetApiTransport (self ::USER , self ::PASSWORD , $ client );
130
- $ method = new \ReflectionMethod (MailjetApiTransport::class, 'doSendApi ' );
131
- $ method ->setAccessible (true );
132
128
133
129
$ email = new Email ();
134
- $ envelope =
new Envelope (
new Address (
'[email protected] ' ,
'Foo ' ), [
new Address (
'[email protected] ' ,
'Bar ' )]);
135
-
136
- $ sentMessage = $ this ->createMock (SentMessage::class);
130
+ $ email
131
+
132
+
133
+ ->text ('foobar ' );
137
134
138
135
$ this ->expectExceptionObject (
139
136
new HttpTransportException ('Unable to send an email: "cannot-be-decoded" (code 200). ' , $ response )
140
137
);
141
- $ method ->invoke ($ transport , $ sentMessage , $ email , $ envelope );
138
+
139
+ $ transport ->send ($ email );
142
140
}
143
141
144
- public function testDoSendApiWithTransportException ()
142
+ public function testSendWithTransportException ()
145
143
{
146
144
$ response = new MockResponse ('' , ['error ' => 'foo ' ]);
147
145
148
146
$ client = new MockHttpClient ($ response );
149
147
150
148
$ transport = new MailjetApiTransport (self ::USER , self ::PASSWORD , $ client );
151
- $ method = new \ReflectionMethod (MailjetApiTransport::class, 'doSendApi ' );
152
- $ method ->setAccessible (true );
153
149
154
150
$ email = new Email ();
155
- $ envelope =
new Envelope (
new Address (
'[email protected] ' ,
'Foo ' ), [
new Address (
'[email protected] ' ,
'Bar ' )]);
156
-
157
- $ sentMessage = $ this ->createMock (SentMessage::class);
151
+ $ email
152
+
153
+
154
+ ->text ('foobar ' );
158
155
159
156
$ this ->expectExceptionObject (
160
157
new HttpTransportException ('Could not reach the remote Mailjet server. ' , $ response )
161
158
);
162
- $ method ->invoke ($ transport , $ sentMessage , $ email , $ envelope );
159
+
160
+ $ transport ->send ($ email );
163
161
}
164
162
165
- public function testDoSendApiWithBadRequestResponse ()
163
+ public function testSendWithBadRequestResponse ()
166
164
{
167
165
$ json = json_encode ([
168
166
'Messages ' => [
@@ -186,45 +184,45 @@ public function testDoSendApiWithBadRequestResponse()
186
184
$ client = new MockHttpClient ($ response );
187
185
188
186
$ transport = new MailjetApiTransport (self ::USER , self ::PASSWORD , $ client );
189
- $ method = new \ReflectionMethod (MailjetApiTransport::class, 'doSendApi ' );
190
- $ method ->setAccessible (true );
191
187
192
188
$ email = new Email ();
193
- $ envelope =
new Envelope (
new Address (
'[email protected] ' ,
'Foo ' ), [
new Address (
'[email protected] ' ,
'Bar ' )]);
194
-
195
- $ sentMessage = $ this ->createMock (SentMessage::class);
189
+ $ email
190
+
191
+
192
+ ->text ('foobar ' );
196
193
197
194
$ this ->expectExceptionObject (
198
195
new HttpTransportException ('Unable to send an email: "The To is mandatory but missing from the input" (code 400). ' , $ response )
199
196
);
200
- $ method ->invoke ($ transport , $ sentMessage , $ email , $ envelope );
197
+
198
+ $ transport ->send ($ email );
201
199
}
202
200
203
- public function testDoSendApiWithNoErrorMessageBadRequestResponse ()
201
+ public function testSendWithNoErrorMessageBadRequestResponse ()
204
202
{
205
203
$ response = new MockResponse ('response-content ' , ['http_code ' => 400 ]);
206
204
207
205
$ client = new MockHttpClient ($ response );
208
206
209
207
$ transport = new MailjetApiTransport (self ::USER , self ::PASSWORD , $ client );
210
- $ method = new \ReflectionMethod (MailjetApiTransport::class, 'doSendApi ' );
211
- $ method ->setAccessible (true );
212
208
213
209
$ email = new Email ();
214
- $ envelope =
new Envelope (
new Address (
'[email protected] ' ,
'Foo ' ), [
new Address (
'[email protected] ' ,
'Bar ' )]);
215
-
216
- $ sentMessage = $ this ->createMock (SentMessage::class);
210
+ $ email
211
+
212
+
213
+ ->text ('foobar ' );
217
214
218
215
$ this ->expectExceptionObject (
219
216
new HttpTransportException ('Unable to send an email: "response-content" (code 400). ' , $ response )
220
217
);
221
- $ method ->invoke ($ transport , $ sentMessage , $ email , $ envelope );
218
+
219
+ $ transport ->send ($ email );
222
220
}
223
221
224
222
/**
225
223
* @dataProvider getMalformedResponse
226
224
*/
227
- public function testDoSendApiWithMalformedResponse (array $ body )
225
+ public function testSendWithMalformedResponse (array $ body )
228
226
{
229
227
$ json = json_encode ($ body );
230
228
@@ -233,18 +231,19 @@ public function testDoSendApiWithMalformedResponse(array $body)
233
231
$ client = new MockHttpClient ($ response );
234
232
235
233
$ transport = new MailjetApiTransport (self ::USER , self ::PASSWORD , $ client );
236
- $ method = new \ReflectionMethod (MailjetApiTransport::class, 'doSendApi ' );
237
- $ method ->setAccessible (true );
238
234
239
235
$ email = new Email ();
240
- $ envelope =
new Envelope (
new Address (
'[email protected] ' ,
'Foo ' ), [
new Address (
'[email protected] ' ,
'Bar ' )]);
236
+ $ email
237
+
238
+
239
+ ->text ('foobar ' );
241
240
242
- $ sentMessage = $ this ->createMock (SentMessage::class);
243
241
244
242
$ this ->expectExceptionObject (
245
243
new HttpTransportException (sprintf ('Unable to send an email: "%s" malformed api response. ' , $ json ), $ response )
246
244
);
247
- $ method ->invoke ($ transport , $ sentMessage , $ email , $ envelope );
245
+
246
+ $ transport ->send ($ email );
248
247
}
249
248
250
249
public function getMalformedResponse (): \Generator
0 commit comments