Skip to content

Commit 136c273

Browse files
OskarStarkderrabus
authored andcommitted
[Notifier] Use abstract test cases in 5.x
1 parent 1eb4b24 commit 136c273

File tree

1 file changed

+23
-51
lines changed

1 file changed

+23
-51
lines changed

Tests/ZulipTransportFactoryTest.php

Lines changed: 23 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,75 +11,47 @@
1111

1212
namespace Symfony\Component\Notifier\Bridge\Zulip\Tests;
1313

14-
use PHPUnit\Framework\TestCase;
1514
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;
2017

21-
final class ZulipTransportFactoryTest extends TestCase
18+
final class ZulipTransportFactoryTest extends TransportFactoryTestCase
2219
{
23-
public function testCreateWithDsn()
20+
/**
21+
* @return ZulipTransportFactory
22+
*/
23+
public function createFactory(): TransportFactoryInterface
2424
{
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();
4726
}
4827

49-
public function testSupportsReturnsTrueWithSupportedScheme()
28+
public function createProvider(): iterable
5029
{
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+
];
5434
}
5535

56-
public function testSupportsReturnsFalseWithUnsupportedScheme()
36+
public function supportsProvider(): iterable
5737
{
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'];
6140
}
6241

63-
public function testUnsupportedSchemeThrowsUnsupportedSchemeException()
42+
public function incompleteDsnProvider(): iterable
6443
{
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'];
6945
}
7046

71-
public function testUnsupportedSchemeThrowsUnsupportedSchemeExceptionEvenIfRequiredOptionIsMissing()
47+
public function missingRequiredOptionProvider(): iterable
7248
{
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'];
7950
}
8051

81-
private function createFactory(): ZulipTransportFactory
52+
public function unsupportedSchemeProvider(): iterable
8253
{
83-
return new ZulipTransportFactory();
54+
yield ['somethingElse://email:token@host?channel=testChannel'];
55+
yield ['somethingElse://email:token@host']; // missing "channel" option
8456
}
8557
}

0 commit comments

Comments
 (0)