|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\Notifier\Bridge\Zulip\Tests;
|
13 | 13 |
|
14 |
| -use PHPUnit\Framework\TestCase; |
15 | 14 | use Symfony\Component\Notifier\Bridge\Zulip\ZulipTransportFactory;
|
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 ZulipTransportFactoryTest extends TestCase |
| 18 | +final class ZulipTransportFactoryTest extends TransportFactoryTestCase |
22 | 19 | {
|
23 |
| - public function testCreateWithDsn() |
| 20 | + /** |
| 21 | + * @return ZulipTransportFactory |
| 22 | + */ |
| 23 | + public function createFactory(): TransportFactoryInterface |
24 | 24 | {
|
25 |
| - $factory = $this->createFactory(); |
26 |
| - |
27 |
| - $transport = $factory->create(Dsn::fromString('zulip://email:token@host.test?channel=testChannel')); |
28 |
| - |
29 |
| - $this->assertSame('zulip://host.test?channel=testChannel', (string) $transport); |
30 |
| - } |
31 |
| - |
32 |
| - public function testCreateWithMissingOptionChannelThrowsMissingRequiredOptionException() |
33 |
| - { |
34 |
| - $factory = $this->createFactory(); |
35 |
| - |
36 |
| - $this->expectException(MissingRequiredOptionException::class); |
37 |
| - |
38 |
| - $factory->create(Dsn::fromString('zulip://email:token@host')); |
39 |
| - } |
40 |
| - |
41 |
| - public function testCreateWithOnlyEmailOrTokenThrowsIncompleteDsnException() |
42 |
| - { |
43 |
| - $factory = $this->createFactory(); |
44 |
| - |
45 |
| - $this->expectException(IncompleteDsnException::class); |
46 |
| - $factory->create(Dsn::fromString('zulip://testOneOfEmailOrToken@host.test?channel=testChannel')); |
| 25 | + return new ZulipTransportFactory(); |
47 | 26 | }
|
48 | 27 |
|
49 |
| - public function testSupportsReturnsTrueWithSupportedScheme() |
| 28 | + public function createProvider(): iterable |
50 | 29 | {
|
51 |
| - $factory = $this->createFactory(); |
52 |
| - |
53 |
| - $this->assertTrue($factory->supports(Dsn::fromString('zulip://host?channel=testChannel'))); |
| 30 | + yield [ |
| 31 | + 'zulip://host.test?channel=testChannel', |
| 32 | + 'zulip://email:token@host.test?channel=testChannel', |
| 33 | + ]; |
54 | 34 | }
|
55 | 35 |
|
56 |
| - public function testSupportsReturnsFalseWithUnsupportedScheme() |
| 36 | + public function supportsProvider(): iterable |
57 | 37 | {
|
58 |
| - $factory = $this->createFactory(); |
59 |
| - |
60 |
| - $this->assertFalse($factory->supports(Dsn::fromString('somethingElse://host?channel=testChannel'))); |
| 38 | + yield [true, 'zulip://host?channel=testChannel']; |
| 39 | + yield [false, 'somethingElse://host?channel=testChannel']; |
61 | 40 | }
|
62 | 41 |
|
63 |
| - public function testUnsupportedSchemeThrowsUnsupportedSchemeException() |
| 42 | + public function incompleteDsnProvider(): iterable |
64 | 43 | {
|
65 |
| - $factory = $this->createFactory(); |
66 |
| - |
67 |
| - $this->expectException(UnsupportedSchemeException::class); |
68 |
| - $factory->create(Dsn::fromString('somethingElse://email:token@host?channel=testChannel')); |
| 44 | + yield 'missing email or token' => ['zulip://testOneOfEmailOrToken@host.test?channel=testChannel']; |
69 | 45 | }
|
70 | 46 |
|
71 |
| - public function testUnsupportedSchemeThrowsUnsupportedSchemeExceptionEvenIfRequiredOptionIsMissing() |
| 47 | + public function missingRequiredOptionProvider(): iterable |
72 | 48 | {
|
73 |
| - $factory = $this->createFactory(); |
74 |
| - |
75 |
| - $this->expectException(UnsupportedSchemeException::class); |
76 |
| - |
77 |
| - // unsupported scheme and missing "channel" option |
78 |
| - $factory->create(Dsn::fromString('somethingElse://email:token@host')); |
| 49 | + yield 'missing option: channel' => ['zulip://email:token@host']; |
79 | 50 | }
|
80 | 51 |
|
81 |
| - private function createFactory(): ZulipTransportFactory |
| 52 | + public function unsupportedSchemeProvider(): iterable |
82 | 53 | {
|
83 |
| - return new ZulipTransportFactory(); |
| 54 | + yield ['somethingElse://email:token@host?channel=testChannel']; |
| 55 | + yield ['somethingElse://email:token@host']; // missing "channel" option |
84 | 56 | }
|
85 | 57 | }
|
0 commit comments