|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\Notifier\Bridge\Esendex\Tests;
|
13 | 13 |
|
14 |
| -use PHPUnit\Framework\TestCase; |
15 | 14 | use Symfony\Component\Notifier\Bridge\Esendex\EsendexTransportFactory;
|
16 |
| -use Symfony\Component\Notifier\Exception\IncompleteDsnException; |
17 |
| -use Symfony\Component\Notifier\Exception\MissingRequiredOptionException; |
18 |
| -use Symfony\Component\Notifier\Exception\UnsupportedSchemeException; |
19 |
| -use Symfony\Component\Notifier\Transport\Dsn; |
| 15 | +use Symfony\Component\Notifier\Tests\TransportFactoryTestCase; |
| 16 | +use Symfony\Component\Notifier\Transport\TransportFactoryInterface; |
20 | 17 |
|
21 |
| -final class EsendexTransportFactoryTest extends TestCase |
| 18 | +final class EsendexTransportFactoryTest extends TransportFactoryTestCase |
22 | 19 | {
|
23 |
| - public function testCreateWithDsn() |
| 20 | + /** |
| 21 | + * @return EsendexTransportFactory |
| 22 | + */ |
| 23 | + public function createFactory(): TransportFactoryInterface |
24 | 24 | {
|
25 |
| - $factory = $this->createFactory(); |
26 |
| - |
27 |
| - $transport = $factory->create(Dsn::fromString('esendex://email:password@host.test?accountreference=testAccountreference&from=testFrom')); |
28 |
| - |
29 |
| - $this->assertSame('esendex://host.test?accountreference=testAccountreference&from=testFrom', (string) $transport); |
30 |
| - } |
31 |
| - |
32 |
| - public function testCreateWithMissingEmailThrowsIncompleteDsnException() |
33 |
| - { |
34 |
| - $factory = $this->createFactory(); |
35 |
| - |
36 |
| - $this->expectException(IncompleteDsnException::class); |
37 |
| - |
38 |
| - $factory->create(Dsn::fromString('esendex://:password@host?accountreference=testAccountreference&from=FROM')); |
39 |
| - } |
40 |
| - |
41 |
| - public function testCreateWithMissingPasswordThrowsIncompleteDsnException() |
42 |
| - { |
43 |
| - $factory = $this->createFactory(); |
44 |
| - |
45 |
| - $this->expectException(IncompleteDsnException::class); |
46 |
| - |
47 |
| - $factory->create(Dsn::fromString('esendex://email:@host?accountreference=testAccountreference&from=FROM')); |
48 |
| - } |
49 |
| - |
50 |
| - public function testCreateWithMissingOptionAccountreferenceThrowsMissingRequiredOptionException() |
51 |
| - { |
52 |
| - $factory = $this->createFactory(); |
53 |
| - |
54 |
| - $this->expectException(MissingRequiredOptionException::class); |
55 |
| - |
56 |
| - $factory->create(Dsn::fromString('esendex://email:password@host?from=FROM')); |
57 |
| - } |
58 |
| - |
59 |
| - public function testCreateWithMissingOptionFromThrowsMissingRequiredOptionException() |
60 |
| - { |
61 |
| - $factory = $this->createFactory(); |
62 |
| - |
63 |
| - $this->expectException(MissingRequiredOptionException::class); |
64 |
| - |
65 |
| - $factory->create(Dsn::fromString('esendex://email:password@host?accountreference=ACCOUNTREFERENCE')); |
| 25 | + return new EsendexTransportFactory(); |
66 | 26 | }
|
67 | 27 |
|
68 |
| - public function testSupportsReturnsTrueWithSupportedScheme() |
| 28 | + public function createProvider(): iterable |
69 | 29 | {
|
70 |
| - $factory = $this->createFactory(); |
71 |
| - |
72 |
| - $this->assertTrue($factory->supports(Dsn::fromString('esendex://email:password@host?accountreference=ACCOUNTREFERENCE&from=FROM'))); |
| 30 | + yield [ |
| 31 | + 'esendex://host.test?accountreference=ACCOUNTREFERENCE&from=FROM', |
| 32 | + 'esendex://email:password@host.test?accountreference=ACCOUNTREFERENCE&from=FROM', |
| 33 | + ]; |
73 | 34 | }
|
74 | 35 |
|
75 |
| - public function testSupportsReturnsFalseWithUnsupportedScheme() |
| 36 | + public function supportsProvider(): iterable |
76 | 37 | {
|
77 |
| - $factory = $this->createFactory(); |
78 |
| - |
79 |
| - $this->assertFalse($factory->supports(Dsn::fromString('somethingElse://email:password@host?accountreference=ACCOUNTREFERENCE&from=FROM'))); |
| 38 | + yield [true, 'esendex://email:password@host?accountreference=ACCOUNTREFERENCE&from=FROM']; |
| 39 | + yield [false, 'somethingElse://email:password@default']; |
80 | 40 | }
|
81 | 41 |
|
82 |
| - public function testUnsupportedSchemeThrowsUnsupportedSchemeException() |
| 42 | + public function incompleteDsnProvider(): iterable |
83 | 43 | {
|
84 |
| - $factory = $this->createFactory(); |
85 |
| - |
86 |
| - $this->expectException(UnsupportedSchemeException::class); |
87 |
| - $factory->create(Dsn::fromString('somethingElse://email:password@host?accountreference=REFERENCE&from=FROM')); |
| 44 | + yield 'missing credentials' => ['esendex://host?accountreference=ACCOUNTREFERENCE&from=FROM']; |
| 45 | + yield 'missing email' => ['esendex://:password@host?accountreference=ACCOUNTREFERENCE&from=FROM']; |
| 46 | + yield 'missing password' => ['esendex://email:@host?accountreference=ACCOUNTREFERENCE&from=FROM']; |
88 | 47 | }
|
89 | 48 |
|
90 |
| - public function testUnsupportedSchemeThrowsUnsupportedSchemeExceptionEvenIfRequiredOptionIsMissing() |
| 49 | + public function missingRequiredOptionProvider(): iterable |
91 | 50 | {
|
92 |
| - $factory = $this->createFactory(); |
93 |
| - |
94 |
| - $this->expectException(UnsupportedSchemeException::class); |
95 |
| - |
96 |
| - // unsupported scheme and missing "from" option |
97 |
| - $factory->create(Dsn::fromString('somethingElse://email:password@host?accountreference=REFERENCE')); |
| 51 | + yield 'missing option: from' => ['esendex://email:password@host?accountreference=ACCOUNTREFERENCE']; |
| 52 | + yield 'missing option: accountreference' => ['esendex://email:password@host?from=FROM']; |
98 | 53 | }
|
99 | 54 |
|
100 |
| - private function createFactory(): EsendexTransportFactory |
| 55 | + public function unsupportedSchemeProvider(): iterable |
101 | 56 | {
|
102 |
| - return new EsendexTransportFactory(); |
| 57 | + yield ['somethingElse://email:password@default?accountreference=ACCOUNTREFERENCE&from=FROM']; |
| 58 | + yield ['somethingElse://email:password@host?accountreference=ACCOUNTREFERENCE']; // missing "from" option |
103 | 59 | }
|
104 | 60 | }
|
0 commit comments