Skip to content

Commit 593acbc

Browse files
committed
improve code coverage
1 parent 839ee48 commit 593acbc

File tree

5 files changed

+65
-46
lines changed

5 files changed

+65
-46
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\Mailer\Bridge\Amazon\Tests;
1313

14-
use Psr\Log\LoggerInterface;
1514
use Symfony\Component\Mailer\Bridge\Amazon;
1615
use Symfony\Component\Mailer\Bridge\Amazon\Factory\SesTransportFactory;
1716
use Symfony\Component\Mailer\Tests\TransportFactoryTestCase;

src/Symfony/Component/Mailer/Tests/Transport/DsnTest.php

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,77 @@
1111

1212
namespace Symfony\Component\Mailer\Tests\Transport;
1313

14+
use PHPUnit\Framework\TestCase;
1415
use Symfony\Component\Mailer\Exception\InvalidArgumentException;
1516
use Symfony\Component\Mailer\Transport\Dsn;
1617

17-
class DsnTest
18+
class DsnTest extends TestCase
1819
{
19-
public function testFromString(): void
20+
/**
21+
* @dataProvider fromStringProvider
22+
*/
23+
public function testFromString(string $string, Dsn $dsn): void
2024
{
25+
$this->assertEquals($dsn, Dsn::fromString($string));
26+
}
27+
28+
public function testGetOption(): void
29+
{
30+
$dsn = new Dsn('smtp', 'example.com', null, null, null, ['foo' => 'foo_value', 'nullable' => null]);
2131

32+
$this->assertSame('foo_value', $dsn->getOption('foo'));
33+
$this->assertNull($dsn->getOption('nullable', 'default'));
34+
$this->assertSame('default', $dsn->getOption('bar', 'default'));
2235
}
2336

24-
public function testGetOption()
37+
/**
38+
* @dataProvider invalidDsnProvider
39+
*/
40+
public function testInvalidDsn(string $dsn, string $exceptionMessage): void
2541
{
26-
// ...
42+
$this->expectException(InvalidArgumentException::class);
43+
$this->expectExceptionMessage($exceptionMessage);
44+
Dsn::fromString($dsn);
2745
}
2846

2947
public function fromStringProvider(): iterable
3048
{
31-
// yield [
32-
// '',
33-
// new Dsn(),
34-
// ];
49+
yield 'simple smtp without user and pass' => [
50+
'smtp://example.com',
51+
new Dsn('smtp', 'example.com', null, null, null),
52+
];
53+
54+
yield 'simple smtp with custom port' => [
55+
'smtp://user1:pass2@example.com:99',
56+
new Dsn('smtp', 'example.com', 99, 'user1', 'pass2'),
57+
];
58+
59+
yield 'gmail smtp with urlencoded user and pass' => [
60+
'smtp://u%24er:pa%24s@gmail',
61+
new Dsn('smtp', 'gmail', null, 'u$er', 'pa$s'),
62+
];
63+
64+
yield 'mailgun api with custom options' => [
65+
'api://u%24er:pa%24s@mailgun?region=eu',
66+
new Dsn('smtp', 'mailgun', null, 'u$ser', 'pa$s', ['region' => 'eu']),
67+
];
3568
}
3669

37-
//TODO: test InvalidArgumentException throw (2 cases)
70+
public function invalidDsnProvider(): iterable
71+
{
72+
yield [
73+
'some://',
74+
'The "some://" mailer DSN is invalid.',
75+
];
76+
77+
yield [
78+
'//sendmail',
79+
'The "//sendmail" mailer DSN must contain a transport scheme.',
80+
];
81+
82+
yield [
83+
'file:///some/path',
84+
'The "file:///some/path" mailer DSN must contain a mailer name.',
85+
];
86+
}
3887
}

src/Symfony/Component/Mailer/Tests/TransportFactoryTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,18 @@
1212
namespace Symfony\Component\Mailer\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Psr\Log\LoggerInterface;
16-
use Symfony\Component\Mailer\Bridge\Amazon;
17-
use Symfony\Component\Mailer\Bridge\Google;
18-
use Symfony\Component\Mailer\Bridge\Mailchimp;
19-
use Symfony\Component\Mailer\Bridge\Mailgun;
20-
use Symfony\Component\Mailer\Bridge\Postmark;
21-
use Symfony\Component\Mailer\Bridge\Sendgrid;
2215

2316
class TransportFactoryTest extends TestCase
2417
{
2518
public function testSimpleTransport()
2619
{
27-
2820
}
2921

3022
public function testFailoverTransport()
3123
{
32-
3324
}
3425

3526
public function testRoundRobinTransport()
3627
{
37-
3828
}
3929
}

src/Symfony/Component/Mailer/Tests/TransportTest.php

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Psr\Log\LoggerInterface;
16-
use Symfony\Component\Mailer\Bridge\Amazon;
1716
use Symfony\Component\Mailer\Bridge\Google;
1817
use Symfony\Component\Mailer\Bridge\Mailchimp;
1918
use Symfony\Component\Mailer\Bridge\Mailgun;
2019
use Symfony\Component\Mailer\Bridge\Postmark;
2120
use Symfony\Component\Mailer\Bridge\Sendgrid;
22-
use Symfony\Component\Mailer\Exception\InvalidArgumentException;
2321
use Symfony\Component\Mailer\Exception\LogicException;
2422
use Symfony\Component\Mailer\Transport;
2523
use Symfony\Component\Mime\Email;
@@ -58,27 +56,6 @@ public function testFromDsnSmtp()
5856
$this->assertEquals(44, $transport->getStream()->getPort());
5957
}
6058

61-
public function testFromInvalidDsn()
62-
{
63-
$this->expectException(InvalidArgumentException::class);
64-
$this->expectExceptionMessage('The "some://" mailer DSN is invalid.');
65-
Transport::fromDsn('some://');
66-
}
67-
68-
public function testNoScheme()
69-
{
70-
$this->expectException(InvalidArgumentException::class);
71-
$this->expectExceptionMessage('The "//sendmail" mailer DSN must contain a transport scheme.');
72-
Transport::fromDsn('//sendmail');
73-
}
74-
75-
public function testFromInvalidDsnNoHost()
76-
{
77-
$this->expectException(InvalidArgumentException::class);
78-
$this->expectExceptionMessage('The "file:///some/path" mailer DSN must contain a mailer name.');
79-
Transport::fromDsn('file:///some/path');
80-
}
81-
8259
public function testFromInvalidTransportName()
8360
{
8461
$this->expectException(LogicException::class);

src/Symfony/Component/Mailer/Transport/Dsn.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,17 @@ public static function fromString(string $dsn): self
4141
throw new InvalidArgumentException(sprintf('The "%s" mailer DSN is invalid.', $dsn));
4242
}
4343

44+
if (!isset($parsedDsn['scheme'])) {
45+
throw new InvalidArgumentException(sprintf('The "%s" mailer DSN must contain a transport scheme.', $dsn));
46+
}
47+
4448
if (!isset($parsedDsn['host'])) {
4549
throw new InvalidArgumentException(sprintf('The "%s" mailer DSN must contain a mailer name.', $dsn));
4650
}
4751

48-
$user = \urldecode($parsedDsn['user'] ?? '');
49-
$pass = \urldecode($parsedDsn['pass'] ?? '');
50-
\parse_str($parsedDsn['query'] ?? '', $query);
52+
$user = urldecode($parsedDsn['user'] ?? '');
53+
$pass = urldecode($parsedDsn['pass'] ?? '');
54+
parse_str($parsedDsn['query'] ?? '', $query);
5155

5256
return new self($parsedDsn['scheme'], $parsedDsn['host'], $parsedDsn['port'] ?? null, $user, $pass, $query);
5357
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy