Skip to content

Commit a016fc2

Browse files
committed
Add one more test
1 parent e24c463 commit a016fc2

File tree

5 files changed

+91
-24
lines changed

5 files changed

+91
-24
lines changed

src/Symfony/Component/Mailer/Bridge/Amazon/Factory/SesTransportFactory.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ public function create(Dsn $dsn): TransportInterface
3636

3737
$region = $dsn->getOption('region');
3838

39-
if ('smtp' === $scheme) {
40-
return new Amazon\Smtp\SesTransport($user, $password, $region, $this->dispatcher, $this->logger);
41-
}
42-
4339
if ('api' === $scheme) {
4440
return new Amazon\Http\Api\SesTransport($user, $password, $region, $this->client, $this->dispatcher, $this->logger);
4541
}
@@ -48,6 +44,10 @@ public function create(Dsn $dsn): TransportInterface
4844
return new Amazon\Http\SesTransport($user, $password, $region, $this->client, $this->dispatcher, $this->logger);
4945
}
5046

47+
if ('smtp' === $scheme) {
48+
return new Amazon\Smtp\SesTransport($user, $password, $region, $this->dispatcher, $this->logger);
49+
}
50+
5151
throw new UnsupportedSchemeException($dsn);
5252
}
5353

src/Symfony/Component/Mailer/Bridge/Amazon/Tests/SesTransportFactoryTest.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ public function getFactory(): TransportFactoryInterface
2727
public function supportsProvider(): iterable
2828
{
2929
yield [
30-
new Dsn('smtp', 'ses'),
30+
new Dsn('api', 'ses'),
3131
true,
3232
];
3333

3434
yield [
35-
new Dsn('api', 'ses'),
35+
new Dsn('http', 'ses'),
3636
true,
3737
];
3838

3939
yield [
40-
new Dsn('http', 'ses'),
40+
new Dsn('smtp', 'ses'),
4141
true,
4242
];
4343

@@ -49,11 +49,6 @@ public function supportsProvider(): iterable
4949

5050
public function createProvider(): iterable
5151
{
52-
yield [
53-
new Dsn('smtp', 'ses', self::USER, self::PASSWORD),
54-
new Amazon\Smtp\SesTransport(self::USER, self::PASSWORD, null, $this->getDispatcher(), $this->getLogger()),
55-
];
56-
5752
yield [
5853
new Dsn('api', 'ses', self::USER, self::PASSWORD),
5954
new Amazon\Http\Api\SesTransport(self::USER, self::PASSWORD, null, $this->getClient(), $this->getDispatcher(), $this->getLogger()),
@@ -63,6 +58,11 @@ public function createProvider(): iterable
6358
new Dsn('http', 'ses', self::USER, self::PASSWORD),
6459
new Amazon\Http\SesTransport(self::USER, self::PASSWORD, null, $this->getClient(), $this->getDispatcher(), $this->getLogger()),
6560
];
61+
62+
yield [
63+
new Dsn('smtp', 'ses', self::USER, self::PASSWORD),
64+
new Amazon\Smtp\SesTransport(self::USER, self::PASSWORD, null, $this->getDispatcher(), $this->getLogger()),
65+
];
6666
//TODO: region /eu-west-1
6767
//TODO: add test for invalid argument exception
6868
}

src/Symfony/Component/Mailer/Bridge/Mailgun/Factory/MailgunTransportFactory.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ public function create(Dsn $dsn): TransportInterface
2929
$password = $dsn->getPassword();
3030
$region = $dsn->getOption('region');
3131

32-
if ('smtp' === $scheme) {
33-
return new Mailgun\Smtp\MailgunTransport($user, $password, $region, $this->dispatcher, $this->logger);
32+
if ('api' === $scheme) {
33+
return new Mailgun\Http\Api\MailgunTransport($user, $password, $this->client, $region, $this->dispatcher, $this->logger);
3434
}
3535

3636
if ('http' === $scheme) {
3737
return new Mailgun\Http\MailgunTransport($user, $password, $this->client, $region, $this->dispatcher, $this->logger);
3838
}
3939

40-
if ('api' === $scheme) {
41-
return new Mailgun\Http\Api\MailgunTransport($user, $password, $this->client, $region, $this->dispatcher, $this->logger);
40+
if ('smtp' === $scheme) {
41+
return new Mailgun\Smtp\MailgunTransport($user, $password, $region, $this->dispatcher, $this->logger);
4242
}
4343

4444
throw new UnsupportedSchemeException($dsn);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace Symfony\Component\Mailer\Bridge\Mailgun\Tests\Factory;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Symfony\Component\Mailer\Bridge\Mailgun;
7+
use Symfony\Component\Mailer\Bridge\Mailgun\Factory\MailgunTransportFactory;
8+
use Symfony\Component\Mailer\Tests\TransportFactoryTestCase;
9+
use Symfony\Component\Mailer\Transport\Dsn;
10+
use Symfony\Component\Mailer\Transport\TransportFactoryInterface;
11+
12+
class MailgunTransportFactoryTest extends TransportFactoryTestCase
13+
{
14+
public function getFactory(): TransportFactoryInterface
15+
{
16+
return new MailgunTransportFactory($this->getDispatcher(), $this->getClient(), $this->getLogger());
17+
}
18+
19+
public function supportsProvider(): iterable
20+
{
21+
yield [
22+
new Dsn('api', 'mailgun'),
23+
true,
24+
];
25+
26+
yield [
27+
new Dsn('http', 'mailgun'),
28+
true,
29+
];
30+
31+
yield [
32+
new Dsn('smtp', 'mailgun'),
33+
true,
34+
];
35+
36+
yield [
37+
new Dsn('smtp', 'example.com'),
38+
false,
39+
];
40+
}
41+
42+
public function createProvider(): iterable
43+
{
44+
yield [
45+
new Dsn('api', 'mailgun', self::USER, self::PASSWORD),
46+
new Mailgun\Http\Api\MailgunTransport(self::USER, self::PASSWORD, null, $this->getClient(), $this->getDispatcher(), $this->getLogger()),
47+
];
48+
49+
yield [
50+
new Dsn('api', 'mailgun', self::USER, self::PASSWORD, null, ['region' => 'eu']),
51+
new Mailgun\Http\Api\MailgunTransport(self::USER, self::PASSWORD, 'eu', $this->getClient(), $this->getDispatcher(), $this->getLogger()),
52+
];
53+
54+
yield [
55+
new Dsn('http', 'mailgun', self::USER, self::PASSWORD),
56+
new Mailgun\Http\MailgunTransport(self::USER, self::PASSWORD, null, $this->getClient(), $this->getDispatcher(), $this->getLogger()),
57+
];
58+
59+
yield [
60+
new Dsn('smtp', 'mailgun', self::USER, self::PASSWORD),
61+
new Mailgun\Smtp\MailgunTransport(self::USER, self::PASSWORD, null, $this->getDispatcher(), $this->getLogger()),
62+
];
63+
}
64+
65+
public function unsupportedSchemeProvider(): iterable
66+
{
67+
yield [new Dsn('foo', 'mailgun', self::USER, self::PASSWORD)];
68+
}
69+
}

src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransportFactory.php

+6-8
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ final class EsmtpTransportFactory extends AbstractTransportFactory
2222
{
2323
public function create(Dsn $dsn): TransportInterface
2424
{
25-
$transport = new EsmtpTransport(
26-
$dsn->getHost(),
27-
$dsn->getPort(25),
28-
$dsn->getOption('encryption'),
29-
$dsn->getOption('auth_mode'),
30-
$this->dispatcher,
31-
$this->logger
32-
);
25+
$encryption = $dsn->getOption('encryption');
26+
$authMode = $dsn->getOption('auth_mode');
27+
$port = $dsn->getPort(25);
28+
$host = $dsn->getHost();
29+
30+
$transport = new EsmtpTransport($host, $port, $encryption, $authMode, $this->dispatcher, $this->logger);
3331

3432
if ($user = $dsn->getUser()) {
3533
$transport->setUsername($user);

0 commit comments

Comments
 (0)