|
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\ZulipTransport;
|
16 |
| -use Symfony\Component\Notifier\Exception\LogicException; |
17 | 15 | use Symfony\Component\Notifier\Message\ChatMessage;
|
18 | 16 | use Symfony\Component\Notifier\Message\MessageInterface;
|
| 17 | +use Symfony\Component\Notifier\Message\SmsMessage; |
| 18 | +use Symfony\Component\Notifier\Tests\TransportTestCase; |
| 19 | +use Symfony\Component\Notifier\Transport\TransportInterface; |
19 | 20 | use Symfony\Contracts\HttpClient\HttpClientInterface;
|
20 | 21 |
|
21 |
| -final class ZulipTransportTest extends TestCase |
| 22 | +final class ZulipTransportTest extends TransportTestCase |
22 | 23 | {
|
23 |
| - public function testToStringContainsProperties() |
| 24 | + /** |
| 25 | + * @return ZulipTransport |
| 26 | + */ |
| 27 | + public function createTransport(?HttpClientInterface $client = null): TransportInterface |
24 | 28 | {
|
25 |
| - $transport = $this->createTransport(); |
26 |
| - |
27 |
| - $this->assertSame('zulip://test.host?channel=testChannel', (string) $transport); |
| 29 | + return (new ZulipTransport('testEmail', 'testToken', 'testChannel', $client ?: $this->createMock(HttpClientInterface::class)))->setHost('test.host'); |
28 | 30 | }
|
29 | 31 |
|
30 |
| - public function testSupportsChatMessage() |
| 32 | + public function toStringProvider(): iterable |
31 | 33 | {
|
32 |
| - $transport = $this->createTransport(); |
33 |
| - |
34 |
| - $this->assertTrue($transport->supports(new ChatMessage('testChatMessage'))); |
35 |
| - $this->assertFalse($transport->supports($this->createMock(MessageInterface::class))); |
| 34 | + yield ['zulip://test.host?channel=testChannel', $this->createTransport()]; |
36 | 35 | }
|
37 | 36 |
|
38 |
| - public function testSendNonChatMessageThrows() |
| 37 | + public function supportedMessagesProvider(): iterable |
39 | 38 | {
|
40 |
| - $transport = $this->createTransport(); |
41 |
| - |
42 |
| - $this->expectException(LogicException::class); |
43 |
| - $transport->send($this->createMock(MessageInterface::class)); |
| 39 | + yield [new ChatMessage('Hello!')]; |
44 | 40 | }
|
45 | 41 |
|
46 |
| - private function createTransport(): ZulipTransport |
| 42 | + public function unsupportedMessagesProvider(): iterable |
47 | 43 | {
|
48 |
| - return (new ZulipTransport('testEmail', 'testToken', 'testChannel', $this->createMock(HttpClientInterface::class)))->setHost('test.host'); |
| 44 | + yield [new SmsMessage('0611223344', 'Hello!')]; |
| 45 | + yield [$this->createMock(MessageInterface::class)]; |
49 | 46 | }
|
50 | 47 | }
|
0 commit comments