Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dbedd28

Browse files
committed
minor #38315 [Notifier] Add Dsn test case (jschaedl)
This PR was merged into the 5.2-dev branch. Discussion ---------- [Notifier] Add Dsn test case | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | - <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | - <!-- required for new features --> <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Never break backward compatibility (see https://symfony.com/bc). - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too.) - Features and deprecations must be submitted against branch master. --> Commits ------- 6a0510d Add Dsn test case
2 parents 3f51de3 + 6a0510d commit dbedd28

File tree

1 file changed

+103
-0
lines changed
  • src/Symfony/Component/Notifier/Tests/Transport

1 file changed

+103
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Tests\Transport;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Notifier\Exception\InvalidArgumentException;
16+
use Symfony\Component\Notifier\Transport\Dsn;
17+
18+
class DsnTest extends TestCase
19+
{
20+
/**
21+
* @dataProvider fromStringProvider
22+
*/
23+
public function testFromString(string $string, Dsn $expectedDsn): void
24+
{
25+
$actualDsn = Dsn::fromString($string);
26+
27+
$this->assertSame($expectedDsn->getScheme(), $actualDsn->getScheme());
28+
$this->assertSame($expectedDsn->getHost(), $actualDsn->getHost());
29+
$this->assertSame($expectedDsn->getPort(), $actualDsn->getPort());
30+
$this->assertSame($expectedDsn->getUser(), $actualDsn->getUser());
31+
$this->assertSame($expectedDsn->getPassword(), $actualDsn->getPassword());
32+
$this->assertSame($expectedDsn->getPath(), $actualDsn->getPath());
33+
$this->assertSame($expectedDsn->getOption('from'), $actualDsn->getOption('from'));
34+
35+
$this->assertSame($string, $actualDsn->getOriginalDsn());
36+
}
37+
38+
public function fromStringProvider(): iterable
39+
{
40+
yield 'simple dsn' => [
41+
'scheme://localhost',
42+
new Dsn('scheme', 'localhost', null, null, null, [], null),
43+
];
44+
45+
yield 'dsn with user and pass' => [
46+
'scheme://u$er:pa$s@localhost',
47+
new Dsn('scheme', 'localhost', 'u$er', 'pa$s', null, [], null),
48+
];
49+
50+
yield 'dsn with user and pass and custom port' => [
51+
'scheme://u$er:pa$s@localhost:8000',
52+
new Dsn('scheme', 'localhost', 'u$er', 'pa$s', '8000', [], null),
53+
];
54+
55+
yield 'dsn with user and pass, custom port and custom path' => [
56+
'scheme://u$er:pa$s@localhost:8000/channel',
57+
new Dsn('scheme', 'localhost', 'u$er', 'pa$s', '8000', [], '/channel'),
58+
];
59+
60+
yield 'dsn with user and pass, custom port, custom path and custom options' => [
61+
'scheme://u$er:pa$s@localhost:8000/channel?from=FROM',
62+
new Dsn('scheme', 'localhost', 'u$er', 'pa$s', '8000', ['from' => 'FROM'], '/channel'),
63+
];
64+
}
65+
66+
/**
67+
* @dataProvider invalidDsnProvider
68+
*/
69+
public function testInvalidDsn(string $dsn, string $exceptionMessage): void
70+
{
71+
$this->expectException(InvalidArgumentException::class);
72+
$this->expectExceptionMessage($exceptionMessage);
73+
Dsn::fromString($dsn);
74+
}
75+
76+
public function invalidDsnProvider(): iterable
77+
{
78+
yield [
79+
'some://',
80+
'The "some://" notifier DSN is invalid.',
81+
];
82+
83+
yield [
84+
'//slack',
85+
'The "//slack" notifier DSN must contain a scheme.',
86+
];
87+
88+
yield [
89+
'file:///some/path',
90+
'The "file:///some/path" notifier DSN must contain a host (use "default" by default).',
91+
];
92+
}
93+
94+
public function testGetOption(): void
95+
{
96+
$options = ['with_value' => 'some value', 'nullable' => null];
97+
$dsn = new Dsn('scheme', 'localhost', 'u$er', 'pa$s', '8000', $options, '/channel');
98+
99+
$this->assertSame('some value', $dsn->getOption('with_value'));
100+
$this->assertSame('default', $dsn->getOption('nullable', 'default'));
101+
$this->assertSame('default', $dsn->getOption('not_existent_property', 'default'));
102+
}
103+
}

0 commit comments

Comments
 (0)