2323use Symfony \Component \Mailer \Exception \InvalidArgumentException ;
2424use Symfony \Component \Mailer \Exception \LogicException ;
2525use Symfony \Component \Mailer \Transport ;
26+ use Symfony \Component \Mime \Email ;
2627use Symfony \Contracts \HttpClient \HttpClientInterface ;
28+ use Symfony \Contracts \HttpClient \ResponseInterface ;
2729
2830class TransportTest extends TestCase
2931{
@@ -106,6 +108,15 @@ public function testFromDsnMailgun()
106108 $ this ->assertEquals ('pa$s ' , $ transport ->getPassword ());
107109 $ this ->assertProperties ($ transport , $ dispatcher , $ logger );
108110
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+
109120 $ client = $ this ->createMock (HttpClientInterface::class);
110121 $ transport = Transport::fromDsn ('http:// ' .urlencode ('u$er ' ).': ' .urlencode ('pa$s ' ).'@mailgun ' , $ dispatcher , $ client , $ logger );
111122 $ this ->assertInstanceOf (Mailgun \Http \MailgunTransport::class, $ transport );
@@ -115,6 +126,25 @@ public function testFromDsnMailgun()
115126 'client ' => $ client ,
116127 ]);
117128
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+
118148 $ transport = Transport::fromDsn ('api:// ' .urlencode ('u$er ' ).': ' .urlencode ('pa$s ' ).'@mailgun ' , $ dispatcher , $ client , $ logger );
119149 $ this ->assertInstanceOf (Mailgun \Http \Api \MailgunTransport::class, $ transport );
120150 $ this ->assertProperties ($ transport , $ dispatcher , $ logger , [
@@ -123,6 +153,21 @@ public function testFromDsnMailgun()
123153 'client ' => $ client ,
124154 ]);
125155
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+
126171 $ this ->expectException (LogicException::class);
127172 Transport::fromDsn ('foo://mailgun ' );
128173 }
0 commit comments