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