Skip to content

[Notifier] Fix toString when optional parameter is not set #39532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public function __construct(string $accessToken, string $chatChannel = null, Htt

public function __toString(): string
{
if (null === $this->chatChannel) {
return sprintf('rocketchat://%s', $this->getEndpoint());
}

return sprintf('rocketchat://%s?channel=%s', $this->getEndpoint(), $this->chatChannel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ public function testToStringContainsProperties()
$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()
{
$transport = $this->createTransport();
Expand All @@ -46,8 +53,8 @@ public function testSendNonChatMessageThrowsLogicException()
$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');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public function __construct(string $token, string $channel = null, HttpClientInt

public function __toString(): string
{
if (null === $this->chatChannel) {
return sprintf('telegram://%s', $this->getEndpoint());
}

return sprintf('telegram://%s?channel=%s', $this->getEndpoint(), $this->chatChannel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ public function testToStringContainsProperties()
$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()
{
$transport = $this->createTransport();
Expand Down Expand Up @@ -186,7 +193,7 @@ public function testSendWithChannelOverride()
$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');
}
Expand Down