Skip to content

[Notifier] Improve tests (5.1) #39509

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 16, 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 @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testSupportsChatMessage()
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
}

public function testSendNonChatMessageThrows()
public function testSendNonChatMessageThrowsLogicException()
{
$transport = $this->createTransport();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,31 @@ 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()
{
$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()
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testSupportsChatMessage()
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
}

public function testSendNonChatMessageThrows()
public function testSendNonChatMessageThrowsLogicException()
{
$transport = $this->createTransport();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -42,7 +41,7 @@ public function testSupportsChatMessage()
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
}

public function testSendNonChatMessageThrows()
public function testSendNonChatMessageThrowsLogicException()
{
$transport = $this->createTransport();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,39 @@ 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()
{
$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()
{
$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()
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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'));
}
Expand Down Expand Up @@ -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'));
}
Expand Down Expand Up @@ -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
Expand All @@ -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');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down