diff --git a/src/Symfony/Component/Notifier/Bridge/Firebase/Tests/FirebaseTransportFactoryTest.php b/src/Symfony/Component/Notifier/Bridge/Firebase/Tests/FirebaseTransportFactoryTest.php index 80a1153a1b2f5..841df2adf9304 100644 --- a/src/Symfony/Component/Notifier/Bridge/Firebase/Tests/FirebaseTransportFactoryTest.php +++ b/src/Symfony/Component/Notifier/Bridge/Firebase/Tests/FirebaseTransportFactoryTest.php @@ -25,8 +25,7 @@ public function testCreateWithDsn() { $factory = $this->createFactory(); - $transport = $factory->create(Dsn::fromString('firebase://username:password@default')); - $transport->setHost('host.test'); + $transport = $factory->create(Dsn::fromString('firebase://username:password@host.test')); $this->assertSame('firebase://host.test', (string) $transport); } diff --git a/src/Symfony/Component/Notifier/Bridge/Mattermost/Tests/MattermostTransportFactoryTest.php b/src/Symfony/Component/Notifier/Bridge/Mattermost/Tests/MattermostTransportFactoryTest.php index c65b598198db7..daa774130a1f9 100644 --- a/src/Symfony/Component/Notifier/Bridge/Mattermost/Tests/MattermostTransportFactoryTest.php +++ b/src/Symfony/Component/Notifier/Bridge/Mattermost/Tests/MattermostTransportFactoryTest.php @@ -26,13 +26,9 @@ public function testCreateWithDsn() { $factory = $this->createFactory(); - $accessToken = 'testAccessToken'; - $host = 'testHost'; - $channel = 'testChannel'; + $transport = $factory->create(Dsn::fromString('mattermost://accessToken@host.test?channel=testChannel')); - $transport = $factory->create(Dsn::fromString(sprintf('mattermost://%s@%s/?channel=%s', $accessToken, $host, $channel))); - - $this->assertSame(sprintf('mattermost://%s?channel=%s', $host, $channel), (string) $transport); + $this->assertSame('mattermost://host.test?channel=testChannel', (string) $transport); } public function testCreateWithMissingOptionChannelThrowsIncompleteDsnException() @@ -49,21 +45,21 @@ public function testCreateWithNoTokenThrowsIncompleteDsnException() $factory = $this->createFactory(); $this->expectException(IncompleteDsnException::class); - $factory->create(Dsn::fromString(sprintf('mattermost://%s/?channel=%s', 'testHost', 'testChannel'))); + $factory->create(Dsn::fromString('mattermost://host.test?channel=testChannel')); } public function testSupportsReturnsTrueWithSupportedScheme() { $factory = $this->createFactory(); - $this->assertTrue($factory->supports(Dsn::fromString('mattermost://token@host/?channel=testChannel'))); + $this->assertTrue($factory->supports(Dsn::fromString('mattermost://token@host?channel=testChannel'))); } public function testSupportsReturnsFalseWithUnsupportedScheme() { $factory = $this->createFactory(); - $this->assertFalse($factory->supports(Dsn::fromString('somethingElse://token@host/?channel=testChannel'))); + $this->assertFalse($factory->supports(Dsn::fromString('somethingElse://token@host?channel=testChannel'))); } public function testUnsupportedSchemeThrowsUnsupportedSchemeException() @@ -72,7 +68,7 @@ public function testUnsupportedSchemeThrowsUnsupportedSchemeException() $this->expectException(UnsupportedSchemeException::class); - $factory->create(Dsn::fromString('somethingElse://token@host/?channel=testChannel')); + $factory->create(Dsn::fromString('somethingElse://token@host?channel=testChannel')); } public function testUnsupportedSchemeThrowsUnsupportedSchemeExceptionEvenIfRequiredOptionIsMissing() diff --git a/src/Symfony/Component/Notifier/Bridge/Mattermost/Tests/MattermostTransportTest.php b/src/Symfony/Component/Notifier/Bridge/Mattermost/Tests/MattermostTransportTest.php index 2ef829d8ffe26..7bd203baafb7a 100644 --- a/src/Symfony/Component/Notifier/Bridge/Mattermost/Tests/MattermostTransportTest.php +++ b/src/Symfony/Component/Notifier/Bridge/Mattermost/Tests/MattermostTransportTest.php @@ -38,7 +38,7 @@ public function testSupportsChatMessage() $this->assertFalse($transport->supports($this->createMock(MessageInterface::class))); } - public function testSendNonChatMessageThrows() + public function testSendNonChatMessageThrowsLogicException() { $transport = $this->createTransport(); diff --git a/src/Symfony/Component/Notifier/Bridge/Nexmo/Tests/NexmoTransportFactoryTest.php b/src/Symfony/Component/Notifier/Bridge/Nexmo/Tests/NexmoTransportFactoryTest.php index 5cc9064538891..2334147b029b4 100644 --- a/src/Symfony/Component/Notifier/Bridge/Nexmo/Tests/NexmoTransportFactoryTest.php +++ b/src/Symfony/Component/Notifier/Bridge/Nexmo/Tests/NexmoTransportFactoryTest.php @@ -23,9 +23,7 @@ public function testCreateWithDsn() { $factory = $this->createFactory(); - $dsn = 'nexmo://apiKey:apiSecret@default?from=0611223344'; - $transport = $factory->create(Dsn::fromString($dsn)); - $transport->setHost('host.test'); + $transport = $factory->create(Dsn::fromString('nexmo://apiKey:apiSecret@host.test?from=0611223344')); $this->assertSame('nexmo://host.test?from=0611223344', (string) $transport); } diff --git a/src/Symfony/Component/Notifier/Bridge/OvhCloud/Tests/OvhCloudTransportFactoryTest.php b/src/Symfony/Component/Notifier/Bridge/OvhCloud/Tests/OvhCloudTransportFactoryTest.php index dd9745fe23d20..e3fdb3edfe6b8 100644 --- a/src/Symfony/Component/Notifier/Bridge/OvhCloud/Tests/OvhCloudTransportFactoryTest.php +++ b/src/Symfony/Component/Notifier/Bridge/OvhCloud/Tests/OvhCloudTransportFactoryTest.php @@ -23,9 +23,7 @@ public function testCreateWithDsn() { $factory = $this->createFactory(); - $dsn = 'ovhcloud://applicationKey:applicationSecret@default?consumer_key=consumerKey&service_name=serviceName'; - $transport = $factory->create(Dsn::fromString($dsn)); - $transport->setHost('host.test'); + $transport = $factory->create(Dsn::fromString('ovhcloud://applicationKey:applicationSecret@host.test?consumer_key=consumerKey&service_name=serviceName')); $this->assertSame('ovhcloud://host.test?consumer_key=consumerKey&service_name=serviceName', (string) $transport); } diff --git a/src/Symfony/Component/Notifier/Bridge/RocketChat/Tests/RocketChatTransportFactoryTest.php b/src/Symfony/Component/Notifier/Bridge/RocketChat/Tests/RocketChatTransportFactoryTest.php index b6da446db3bef..7d7c06e4e1989 100644 --- a/src/Symfony/Component/Notifier/Bridge/RocketChat/Tests/RocketChatTransportFactoryTest.php +++ b/src/Symfony/Component/Notifier/Bridge/RocketChat/Tests/RocketChatTransportFactoryTest.php @@ -26,13 +26,9 @@ public function testCreateWithDsn() { $factory = $this->createFactory(); - $accessToken = 'testAccessToken'; - $host = 'testHost'; - $channel = 'testChannel'; + $transport = $factory->create(Dsn::fromString('rocketchat://accessToken@host.test?channel=testChannel')); - $transport = $factory->create(Dsn::fromString(sprintf('rocketchat://%s@%s/?channel=%s', $accessToken, $host, $channel))); - - $this->assertSame(sprintf('rocketchat://%s?channel=%s', $host, $channel), (string) $transport); + $this->assertSame('rocketchat://host.test?channel=testChannel', (string) $transport); } public function testCreateWithNoTokenThrowsIncompleteDsnException() @@ -40,21 +36,21 @@ public function testCreateWithNoTokenThrowsIncompleteDsnException() $factory = $this->createFactory(); $this->expectException(IncompleteDsnException::class); - $factory->create(Dsn::fromString(sprintf('rocketchat://%s/?channel=%s', 'testHost', 'testChannel'))); + $factory->create(Dsn::fromString('rocketchat://host.test?channel=testChannel')); } public function testSupportsReturnsTrueWithSupportedScheme() { $factory = $this->createFactory(); - $this->assertTrue($factory->supports(Dsn::fromString('rocketchat://token@host/?channel=testChannel'))); + $this->assertTrue($factory->supports(Dsn::fromString('rocketchat://token@host?channel=testChannel'))); } public function testSupportsReturnsFalseWithUnsupportedScheme() { $factory = $this->createFactory(); - $this->assertFalse($factory->supports(Dsn::fromString('somethingElse://token@host/?channel=testChannel'))); + $this->assertFalse($factory->supports(Dsn::fromString('somethingElse://token@host?channel=testChannel'))); } public function testUnsupportedSchemeThrowsUnsupportedSchemeException() @@ -63,7 +59,7 @@ public function testUnsupportedSchemeThrowsUnsupportedSchemeException() $this->expectException(UnsupportedSchemeException::class); - $factory->create(Dsn::fromString('somethingElse://token@host/?channel=testChannel')); + $factory->create(Dsn::fromString('somethingElse://token@host?channel=testChannel')); } private function createFactory(): RocketChatTransportFactory diff --git a/src/Symfony/Component/Notifier/Bridge/RocketChat/Tests/RocketChatTransportTest.php b/src/Symfony/Component/Notifier/Bridge/RocketChat/Tests/RocketChatTransportTest.php index 6384e5811b445..f28e57ff52287 100644 --- a/src/Symfony/Component/Notifier/Bridge/RocketChat/Tests/RocketChatTransportTest.php +++ b/src/Symfony/Component/Notifier/Bridge/RocketChat/Tests/RocketChatTransportTest.php @@ -38,7 +38,7 @@ public function testSupportsChatMessage() $this->assertFalse($transport->supports($this->createMock(MessageInterface::class))); } - public function testSendNonChatMessageThrows() + public function testSendNonChatMessageThrowsLogicException() { $transport = $this->createTransport(); diff --git a/src/Symfony/Component/Notifier/Bridge/Sinch/Tests/SinchTransportFactoryTest.php b/src/Symfony/Component/Notifier/Bridge/Sinch/Tests/SinchTransportFactoryTest.php index 969ed96df862d..74fa7e38b9fe6 100644 --- a/src/Symfony/Component/Notifier/Bridge/Sinch/Tests/SinchTransportFactoryTest.php +++ b/src/Symfony/Component/Notifier/Bridge/Sinch/Tests/SinchTransportFactoryTest.php @@ -23,9 +23,7 @@ public function testCreateWithDsn() { $factory = $this->createFactory(); - $dsn = 'sinch://accountSid:authToken@default?from=0611223344'; - $transport = $factory->create(Dsn::fromString($dsn)); - $transport->setHost('host.test'); + $transport = $factory->create(Dsn::fromString('sinch://accountSid:authToken@host.test?from=0611223344')); $this->assertSame('sinch://host.test?from=0611223344', (string) $transport); } diff --git a/src/Symfony/Component/Notifier/Bridge/Slack/Tests/SlackTransportFactoryTest.php b/src/Symfony/Component/Notifier/Bridge/Slack/Tests/SlackTransportFactoryTest.php index edf3f099a3fc0..e45e68054bfb7 100644 --- a/src/Symfony/Component/Notifier/Bridge/Slack/Tests/SlackTransportFactoryTest.php +++ b/src/Symfony/Component/Notifier/Bridge/Slack/Tests/SlackTransportFactoryTest.php @@ -23,11 +23,9 @@ public function testCreateWithDsn() { $factory = $this->createFactory(); - $host = 'testHost'; - $path = 'testPath'; - $transport = $factory->create(Dsn::fromString(sprintf('slack://%s/%s', $host, $path))); + $transport = $factory->create(Dsn::fromString('slack://host.test/testPath')); - $this->assertSame(sprintf('slack://%s/%s', $host, $path), (string) $transport); + $this->assertSame('slack://host.test/testPath', (string) $transport); } public function testCreateWithMissingOptionIdThrowsIncompleteDsnException() diff --git a/src/Symfony/Component/Notifier/Bridge/Slack/Tests/SlackTransportTest.php b/src/Symfony/Component/Notifier/Bridge/Slack/Tests/SlackTransportTest.php index 0018e5ad70cd3..abe171a2892ae 100644 --- a/src/Symfony/Component/Notifier/Bridge/Slack/Tests/SlackTransportTest.php +++ b/src/Symfony/Component/Notifier/Bridge/Slack/Tests/SlackTransportTest.php @@ -29,7 +29,6 @@ final class SlackTransportTest extends TestCase public function testToStringContainsProperties() { $transport = $this->createTransport(); - $transport->setHost('host.test'); $this->assertSame('slack://host.test/testPath', (string) $transport); } @@ -42,7 +41,7 @@ public function testSupportsChatMessage() $this->assertFalse($transport->supports($this->createMock(MessageInterface::class))); } - public function testSendNonChatMessageThrows() + public function testSendNonChatMessageThrowsLogicException() { $transport = $this->createTransport(); diff --git a/src/Symfony/Component/Notifier/Bridge/Telegram/Tests/TelegramTransportFactoryTest.php b/src/Symfony/Component/Notifier/Bridge/Telegram/Tests/TelegramTransportFactoryTest.php index de8aff87869bf..8d43b1619e200 100644 --- a/src/Symfony/Component/Notifier/Bridge/Telegram/Tests/TelegramTransportFactoryTest.php +++ b/src/Symfony/Component/Notifier/Bridge/Telegram/Tests/TelegramTransportFactoryTest.php @@ -23,12 +23,9 @@ public function testCreateWithDsn() { $factory = $this->createFactory(); - $host = 'testHost'; - $channel = 'testChannel'; + $transport = $factory->create(Dsn::fromString('telegram://user:password@host.test?channel=testChannel')); - $transport = $factory->create(Dsn::fromString(sprintf('telegram://%s@%s/?channel=%s', 'testUser:testPassword', $host, $channel))); - - $this->assertSame(sprintf('telegram://%s?channel=%s', $host, $channel), (string) $transport); + $this->assertSame('telegram://host.test?channel=testChannel', (string) $transport); } public function testCreateWithNoPasswordThrowsIncompleteDsnException() @@ -36,7 +33,7 @@ public function testCreateWithNoPasswordThrowsIncompleteDsnException() $factory = $this->createFactory(); $this->expectException(IncompleteDsnException::class); - $factory->create(Dsn::fromString(sprintf('telegram://%s@%s/?channel=%s', 'simpleToken', 'testHost', 'testChannel'))); + $factory->create(Dsn::fromString('telegram://simpleToken@host.test?channel=testChannel')); } public function testCreateWithNoTokenThrowsIncompleteDsnException() @@ -44,21 +41,21 @@ public function testCreateWithNoTokenThrowsIncompleteDsnException() $factory = $this->createFactory(); $this->expectException(IncompleteDsnException::class); - $factory->create(Dsn::fromString(sprintf('telegram://%s/?channel=%s', 'testHost', 'testChannel'))); + $factory->create(Dsn::fromString('telegram://host.test?channel=testChannel')); } public function testSupportsReturnsTrueWithSupportedScheme() { $factory = $this->createFactory(); - $this->assertTrue($factory->supports(Dsn::fromString('telegram://host/?channel=testChannel'))); + $this->assertTrue($factory->supports(Dsn::fromString('telegram://host?channel=testChannel'))); } public function testSupportsReturnsFalseWithUnsupportedScheme() { $factory = $this->createFactory(); - $this->assertFalse($factory->supports(Dsn::fromString('somethingElse://host/?channel=testChannel'))); + $this->assertFalse($factory->supports(Dsn::fromString('somethingElse://host?channel=testChannel'))); } public function testUnsupportedSchemeThrowsUnsupportedSchemeException() @@ -67,7 +64,7 @@ public function testUnsupportedSchemeThrowsUnsupportedSchemeException() $this->expectException(UnsupportedSchemeException::class); - $factory->create(Dsn::fromString('somethingElse://user:pwd@host/?channel=testChannel')); + $factory->create(Dsn::fromString('somethingElse://user:pwd@host?channel=testChannel')); } private function createFactory(): TelegramTransportFactory diff --git a/src/Symfony/Component/Notifier/Bridge/Telegram/Tests/TelegramTransportTest.php b/src/Symfony/Component/Notifier/Bridge/Telegram/Tests/TelegramTransportTest.php index c7407ed06d9e6..3fa710b8c5f90 100644 --- a/src/Symfony/Component/Notifier/Bridge/Telegram/Tests/TelegramTransportTest.php +++ b/src/Symfony/Component/Notifier/Bridge/Telegram/Tests/TelegramTransportTest.php @@ -26,26 +26,24 @@ final class TelegramTransportTest extends TestCase { public function testToStringContainsProperties() { - $channel = 'testChannel'; - - $transport = new TelegramTransport('testToken', $channel, $this->createMock(HttpClientInterface::class)); - $transport->setHost('host.test'); + $transport = $this->createTransport(); - $this->assertSame(sprintf('telegram://%s?channel=%s', 'host.test', $channel), (string) $transport); + $this->assertSame('telegram://host.test?channel=testChannel', (string) $transport); } public function testSupportsChatMessage() { - $transport = new TelegramTransport('testToken', 'testChannel', $this->createMock(HttpClientInterface::class)); + $transport = $this->createTransport(); $this->assertTrue($transport->supports(new ChatMessage('testChatMessage'))); $this->assertFalse($transport->supports($this->createMock(MessageInterface::class))); } - public function testSendNonChatMessageThrows() + public function testSendNonChatMessageThrowsLogicException() { + $transport = $this->createTransport(); + $this->expectException(LogicException::class); - $transport = new TelegramTransport('testToken', 'testChannel', $this->createMock(HttpClientInterface::class)); $transport->send($this->createMock(MessageInterface::class)); } @@ -67,7 +65,7 @@ public function testSendWithErrorResponseThrows() return $response; }); - $transport = new TelegramTransport('testToken', 'testChannel', $client); + $transport = $this->createTransport('testChannel', $client); $transport->send(new ChatMessage('testMessage')); } @@ -96,7 +94,7 @@ public function testSendWithOptions() return $response; }); - $transport = new TelegramTransport('testToken', $channel, $client); + $transport = $this->createTransport($channel, $client); $transport->send(new ChatMessage('testMessage')); } @@ -125,7 +123,7 @@ public function testSendWithChannelOverride() return $response; }); - $transport = new TelegramTransport('testToken', 'defaultChannel', $client); + $transport = $this->createTransport('defaultChannel', $client); $messageOptions = $this->createMock(MessageOptionsInterface::class); $messageOptions @@ -135,4 +133,9 @@ public function testSendWithChannelOverride() $transport->send(new ChatMessage('testMessage', $messageOptions)); } + + private function createTransport($channel = 'testChannel', ?HttpClientInterface $client = null): TelegramTransport + { + return (new TelegramTransport('token', $channel, $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test'); + } } diff --git a/src/Symfony/Component/Notifier/Bridge/Twilio/Tests/TwilioTransportFactoryTest.php b/src/Symfony/Component/Notifier/Bridge/Twilio/Tests/TwilioTransportFactoryTest.php index cabc48cd4e4bd..73855e6043a69 100644 --- a/src/Symfony/Component/Notifier/Bridge/Twilio/Tests/TwilioTransportFactoryTest.php +++ b/src/Symfony/Component/Notifier/Bridge/Twilio/Tests/TwilioTransportFactoryTest.php @@ -23,9 +23,7 @@ public function testCreateWithDsn() { $factory = $this->createFactory(); - $dsn = 'twilio://accountSid:authToken@default?from=0611223344'; - $transport = $factory->create(Dsn::fromString($dsn)); - $transport->setHost('host.test'); + $transport = $factory->create(Dsn::fromString('twilio://accountSid:authToken@host.test?from=0611223344')); $this->assertSame('twilio://host.test?from=0611223344', (string) $transport); }