bug #39532 [Notifier] Fix toString when optional parameter is not set (OskarStark)
This PR was merged into the 5.2 branch.
Discussion
----------
[Notifier] Fix toString when optional parameter is not set
| Q | A
| ------------- | ---
| Branch? | 5.2
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | ---
| License | MIT
| Doc PR | ---
Commits
-------
e61363c1f2
[Notifier] Fix toString when optional parameter is not set
This commit is contained in:
commit
cf08a502ac
@ -43,6 +43,10 @@ final class RocketChatTransport extends AbstractTransport
|
|||||||
|
|
||||||
public function __toString(): string
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
|
if (null === $this->chatChannel) {
|
||||||
|
return sprintf('rocketchat://%s', $this->getEndpoint());
|
||||||
|
}
|
||||||
|
|
||||||
return sprintf('rocketchat://%s?channel=%s', $this->getEndpoint(), $this->chatChannel);
|
return sprintf('rocketchat://%s?channel=%s', $this->getEndpoint(), $this->chatChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,13 @@ final class RocketChatTransportTest extends TestCase
|
|||||||
$this->assertSame('rocketchat://host.test?channel=testChannel', (string) $transport);
|
$this->assertSame('rocketchat://host.test?channel=testChannel', (string) $transport);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testToStringContainsNoChannelBecauseItsOptional()
|
||||||
|
{
|
||||||
|
$transport = $this->createTransport(null);
|
||||||
|
|
||||||
|
$this->assertSame('rocketchat://host.test', (string) $transport);
|
||||||
|
}
|
||||||
|
|
||||||
public function testSupportsChatMessage()
|
public function testSupportsChatMessage()
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport();
|
$transport = $this->createTransport();
|
||||||
@ -46,8 +53,8 @@ final class RocketChatTransportTest extends TestCase
|
|||||||
$transport->send($this->createMock(MessageInterface::class));
|
$transport->send($this->createMock(MessageInterface::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createTransport(): RocketChatTransport
|
private function createTransport(?string $channel = 'testChannel'): RocketChatTransport
|
||||||
{
|
{
|
||||||
return (new RocketChatTransport('testAccessToken', 'testChannel', $this->createMock(HttpClientInterface::class)))->setHost('host.test');
|
return (new RocketChatTransport('testAccessToken', $channel, $this->createMock(HttpClientInterface::class)))->setHost('host.test');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,10 @@ final class TelegramTransport extends AbstractTransport
|
|||||||
|
|
||||||
public function __toString(): string
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
|
if (null === $this->chatChannel) {
|
||||||
|
return sprintf('telegram://%s', $this->getEndpoint());
|
||||||
|
}
|
||||||
|
|
||||||
return sprintf('telegram://%s?channel=%s', $this->getEndpoint(), $this->chatChannel);
|
return sprintf('telegram://%s?channel=%s', $this->getEndpoint(), $this->chatChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +31,13 @@ final class TelegramTransportTest extends TestCase
|
|||||||
$this->assertSame('telegram://host.test?channel=testChannel', (string) $transport);
|
$this->assertSame('telegram://host.test?channel=testChannel', (string) $transport);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testToStringContainsNoChannelBecauseItsOptional()
|
||||||
|
{
|
||||||
|
$transport = $this->createTransport(null);
|
||||||
|
|
||||||
|
$this->assertSame('telegram://host.test', (string) $transport);
|
||||||
|
}
|
||||||
|
|
||||||
public function testSupportsChatMessage()
|
public function testSupportsChatMessage()
|
||||||
{
|
{
|
||||||
$transport = $this->createTransport();
|
$transport = $this->createTransport();
|
||||||
@ -186,7 +193,7 @@ JSON;
|
|||||||
$this->assertEquals('telegram://host.test?channel=defaultChannel', $sentMessage->getTransport());
|
$this->assertEquals('telegram://host.test?channel=defaultChannel', $sentMessage->getTransport());
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createTransport($channel = 'testChannel', ?HttpClientInterface $client = null): TelegramTransport
|
private function createTransport(?string $channel = 'testChannel', ?HttpClientInterface $client = null): TelegramTransport
|
||||||
{
|
{
|
||||||
return (new TelegramTransport('token', $channel, $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
|
return (new TelegramTransport('token', $channel, $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user