23
23
use Symfony \Component \Mailer \Exception \InvalidArgumentException ;
24
24
use Symfony \Component \Mailer \Exception \LogicException ;
25
25
use Symfony \Component \Mailer \Transport ;
26
+ use Symfony \Component \Mime \Email ;
26
27
use Symfony \Contracts \HttpClient \HttpClientInterface ;
28
+ use Symfony \Contracts \HttpClient \ResponseInterface ;
27
29
28
30
class TransportTest extends TestCase
29
31
{
@@ -106,6 +108,15 @@ public function testFromDsnMailgun()
106
108
$ this ->assertEquals ('pa$s ' , $ transport ->getPassword ());
107
109
$ this ->assertProperties ($ transport , $ dispatcher , $ logger );
108
110
111
+ $ transport = Transport::fromDsn ('smtp:// ' .urlencode ('u$er ' ).': ' .urlencode ('pa$s ' ).'@mailgun ' , $ dispatcher , null , $ logger );
112
+ $ this ->assertEquals ('smtp.mailgun.org ' , $ transport ->getStream ()->getHost ());
113
+
114
+ $ transport = Transport::fromDsn ('smtp:// ' .urlencode ('u$er ' ).': ' .urlencode ('pa$s ' ).'@mailgun?region=eu ' , $ dispatcher , null , $ logger );
115
+ $ this ->assertEquals ('smtp.eu.mailgun.org ' , $ transport ->getStream ()->getHost ());
116
+
117
+ $ transport = Transport::fromDsn ('smtp:// ' .urlencode ('u$er ' ).': ' .urlencode ('pa$s ' ).'@mailgun?region=us ' , $ dispatcher , null , $ logger );
118
+ $ this ->assertEquals ('smtp.mailgun.org ' , $ transport ->getStream ()->getHost ());
119
+
109
120
$ client = $ this ->createMock (HttpClientInterface::class);
110
121
$ transport = Transport::fromDsn ('http:// ' .urlencode ('u$er ' ).': ' .urlencode ('pa$s ' ).'@mailgun ' , $ dispatcher , $ client , $ logger );
111
122
$ this ->assertInstanceOf (Mailgun \Http \MailgunTransport::class, $ transport );
@@ -115,6 +126,25 @@ public function testFromDsnMailgun()
115
126
'client ' => $ client ,
116
127
]);
117
128
129
+ $ response = $ this ->createMock (ResponseInterface::class);
130
+ $ response ->expects ($ this ->any ())->method ('getStatusCode ' )->willReturn (200 );
131
+ $ message = (new Email ())->from ('me@me.com ' )->to ('you@you.com ' )->subject ('hello ' )->text ('Hello you ' );
132
+
133
+ $ client = $ this ->createMock (HttpClientInterface::class);
134
+ $ client ->expects ($ this ->once ())->method ('request ' )->with ('POST ' , 'https://api.mailgun.net/v3/pa%24s/messages.mime ' )->willReturn ($ response );
135
+ $ transport = Transport::fromDsn ('http:// ' .urlencode ('u$er ' ).': ' .urlencode ('pa$s ' ).'@mailgun ' , $ dispatcher , $ client , $ logger );
136
+ $ transport ->send ($ message );
137
+
138
+ $ client = $ this ->createMock (HttpClientInterface::class);
139
+ $ client ->expects ($ this ->once ())->method ('request ' )->with ('POST ' , 'https://api.eu.mailgun.net/v3/pa%24s/messages.mime ' )->willReturn ($ response );
140
+ $ transport = Transport::fromDsn ('http:// ' .urlencode ('u$er ' ).': ' .urlencode ('pa$s ' ).'@mailgun?region=eu ' , $ dispatcher , $ client , $ logger );
141
+ $ transport ->send ($ message );
142
+
143
+ $ client = $ this ->createMock (HttpClientInterface::class);
144
+ $ client ->expects ($ this ->once ())->method ('request ' )->with ('POST ' , 'https://api.mailgun.net/v3/pa%24s/messages.mime ' )->willReturn ($ response );
145
+ $ transport = Transport::fromDsn ('http:// ' .urlencode ('u$er ' ).': ' .urlencode ('pa$s ' ).'@mailgun?region=us ' , $ dispatcher , $ client , $ logger );
146
+ $ transport ->send ($ message );
147
+
118
148
$ transport = Transport::fromDsn ('api:// ' .urlencode ('u$er ' ).': ' .urlencode ('pa$s ' ).'@mailgun ' , $ dispatcher , $ client , $ logger );
119
149
$ this ->assertInstanceOf (Mailgun \Http \Api \MailgunTransport::class, $ transport );
120
150
$ this ->assertProperties ($ transport , $ dispatcher , $ logger , [
@@ -123,6 +153,21 @@ public function testFromDsnMailgun()
123
153
'client ' => $ client ,
124
154
]);
125
155
156
+ $ client = $ this ->createMock (HttpClientInterface::class);
157
+ $ client ->expects ($ this ->once ())->method ('request ' )->with ('POST ' , 'https://api.mailgun.net/v3/pa%24s/messages ' )->willReturn ($ response );
158
+ $ transport = Transport::fromDsn ('api:// ' .urlencode ('u$er ' ).': ' .urlencode ('pa$s ' ).'@mailgun ' , $ dispatcher , $ client , $ logger );
159
+ $ transport ->send ($ message );
160
+
161
+ $ client = $ this ->createMock (HttpClientInterface::class);
162
+ $ client ->expects ($ this ->once ())->method ('request ' )->with ('POST ' , 'https://api.eu.mailgun.net/v3/pa%24s/messages ' )->willReturn ($ response );
163
+ $ transport = Transport::fromDsn ('api:// ' .urlencode ('u$er ' ).': ' .urlencode ('pa$s ' ).'@mailgun?region=eu ' , $ dispatcher , $ client , $ logger );
164
+ $ transport ->send ($ message );
165
+
166
+ $ client = $ this ->createMock (HttpClientInterface::class);
167
+ $ client ->expects ($ this ->once ())->method ('request ' )->with ('POST ' , 'https://api.mailgun.net/v3/pa%24s/messages ' )->willReturn ($ response );
168
+ $ transport = Transport::fromDsn ('api:// ' .urlencode ('u$er ' ).': ' .urlencode ('pa$s ' ).'@mailgun?region=us ' , $ dispatcher , $ client , $ logger );
169
+ $ transport->send ($ message );
170
+
126
171
$ this ->expectException (LogicException::class);
127
172
Transport::fromDsn ('foo://mailgun ' );
128
173
}
0 commit comments