Merge branch '5.1' into 5.2

* 5.1:
  [Notifier] Improve tests (5.1)
  [Notifier] Fix wrong package names
  [Notifier] [Free Mobile] Could not use custom host in DSN
This commit is contained in:
Alexander M. Turek 2020-12-16 08:59:53 +01:00
commit 904b05a0de
17 changed files with 59 additions and 76 deletions

View File

@ -25,8 +25,7 @@ final class FirebaseTransportFactoryTest extends TestCase
{
$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);
}

View File

@ -27,7 +27,7 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
*/
final class FreeMobileTransport extends AbstractTransport
{
protected const HOST = 'https://smsapi.free-mobile.fr/sendmsg';
protected const HOST = 'smsapi.free-mobile.fr/sendmsg';
private $login;
private $password;
@ -58,7 +58,9 @@ final class FreeMobileTransport extends AbstractTransport
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given) and configured with your phone number.', __CLASS__, SmsMessage::class, \get_class($message)));
}
$response = $this->client->request('POST', $this->getEndpoint(), [
$endpoint = sprintf('https://%s', $this->getEndpoint());
$response = $this->client->request('POST', $endpoint, [
'json' => [
'user' => $this->login,
'pass' => $this->password,

View File

@ -43,7 +43,10 @@ final class FreeMobileTransportFactory extends AbstractTransportFactory
throw new IncompleteDsnException('Missing phone.', $dsn->getOriginalDsn());
}
return new FreeMobileTransport($login, $password, $phone, $this->client, $this->dispatcher);
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
$port = $dsn->getPort();
return (new FreeMobileTransport($login, $password, $phone, $this->client, $this->dispatcher))->setHost($host)->setPort($port);
}
protected function getSupportedSchemes(): array

View File

@ -23,9 +23,7 @@ final class FreeMobileTransportFactoryTest extends TestCase
{
$factory = $this->createFactory();
$dsn = 'freemobile://login:pass@default?phone=0611223344';
$transport = $factory->create(Dsn::fromString($dsn));
$transport->setHost('host.test');
$transport = $factory->create(Dsn::fromString('freemobile://login:pass@host.test?phone=0611223344'));
$this->assertSame('freemobile://host.test?phone=0611223344', (string) $transport);
}

View File

@ -26,13 +26,9 @@ final class MattermostTransportFactoryTest extends TestCase
{
$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 @@ final class MattermostTransportFactoryTest extends TestCase
$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 @@ final class MattermostTransportFactoryTest extends TestCase
$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()

View File

@ -38,7 +38,7 @@ final class MattermostTransportTest extends TestCase
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
}
public function testSendNonChatMessageThrows()
public function testSendNonChatMessageThrowsLogicException()
{
$transport = $this->createTransport();

View File

@ -23,9 +23,7 @@ final class NexmoTransportFactoryTest extends TestCase
{
$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);
}

View File

@ -23,9 +23,7 @@ final class OvhCloudTransportFactoryTest extends TestCase
{
$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);
}

View File

@ -26,13 +26,9 @@ final class RocketChatTransportFactoryTest extends TestCase
{
$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 @@ final class RocketChatTransportFactoryTest extends TestCase
$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 @@ final class RocketChatTransportFactoryTest extends TestCase
$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

View File

@ -38,7 +38,7 @@ final class RocketChatTransportTest extends TestCase
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
}
public function testSendNonChatMessageThrows()
public function testSendNonChatMessageThrowsLogicException()
{
$transport = $this->createTransport();

View File

@ -23,9 +23,7 @@ final class SinchTransportFactoryTest extends TestCase
{
$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);
}

View File

@ -24,14 +24,12 @@ final class SlackTransportFactoryTest extends TestCase
{
$factory = new SlackTransportFactory();
$host = 'testHost';
$channel = 'testChannel';
$transport = $factory->create(Dsn::fromString(sprintf('slack://testUser@%s/?channel=%s', $host, $channel)));
$transport = $factory->create(Dsn::fromString('slack://testUser@testHost/?channel=testChannel'));
$this->assertSame(sprintf('slack://%s?channel=%s', $host, $channel), (string) $transport);
$this->assertSame('slack://testHost?channel=testChannel', (string) $transport);
}
public function testCreateWithDeprecatedDsn(): void
public function testCreateWithDeprecatedDsn()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Support for Slack webhook DSN has been dropped since 5.2 (maybe you haven\'t updated the DSN when upgrading from 5.1).');
@ -40,7 +38,7 @@ final class SlackTransportFactoryTest extends TestCase
$factory->create(Dsn::fromString('slack://default/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX'));
}
public function testCreateWithNoTokenThrowsMalformed(): void
public function testCreateWithNoTokenThrowsMalformed()
{
$factory = new SlackTransportFactory();

View File

@ -28,13 +28,12 @@ final class SlackTransportTest extends TestCase
{
public function testToStringContainsProperties()
{
$host = 'testHost';
$channel = 'test Channel'; // invalid channel name to test url encoding of the channel
$transport = new SlackTransport('testToken', $channel, $this->createMock(HttpClientInterface::class));
$transport->setHost('testHost');
$this->assertSame(sprintf('slack://%s?channel=%s', $host, urlencode($channel)), (string) $transport);
$this->assertSame('slack://testHost?channel=test+Channel', (string) $transport);
}
public function testSupportsChatMessage()
@ -45,7 +44,7 @@ final class SlackTransportTest extends TestCase
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
}
public function testSendNonChatMessageThrows()
public function testSendNonChatMessageThrowsLogicException()
{
$this->expectException(LogicException::class);

View File

@ -23,12 +23,9 @@ final class TelegramTransportFactoryTest extends TestCase
{
$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 @@ final class TelegramTransportFactoryTest extends TestCase
$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 @@ final class TelegramTransportFactoryTest extends TestCase
$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 @@ final class TelegramTransportFactoryTest extends TestCase
$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

View File

@ -26,26 +26,24 @@ final class TelegramTransportTest extends TestCase
{
public function testToStringContainsProperties()
{
$channel = 'testChannel';
$transport = $this->createTransport();
$transport = new TelegramTransport('testToken', $channel, $this->createMock(HttpClientInterface::class));
$transport->setHost('host.test');
$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 @@ final class TelegramTransportTest extends TestCase
return $response;
});
$transport = new TelegramTransport('testToken', 'testChannel', $client);
$transport = $this->createTransport('testChannel', $client);
$transport->send(new ChatMessage('testMessage'));
}
@ -121,12 +119,12 @@ JSON;
return $response;
});
$transport = new TelegramTransport('testToken', $channel, $client);
$transport = $this->createTransport($channel, $client);
$sentMessage = $transport->send(new ChatMessage('testMessage'));
$this->assertEquals(1, $sentMessage->getMessageId());
$this->assertEquals('telegram://api.telegram.org?channel=testChannel', $sentMessage->getTransport());
$this->assertEquals('telegram://host.test?channel=testChannel', $sentMessage->getTransport());
}
public function testSendWithChannelOverride()
@ -177,7 +175,7 @@ JSON;
return $response;
});
$transport = new TelegramTransport('testToken', 'defaultChannel', $client);
$transport = $this->createTransport('defaultChannel', $client);
$messageOptions = new TelegramOptions();
$messageOptions->chatId($channelOverride);
@ -185,6 +183,11 @@ JSON;
$sentMessage = $transport->send(new ChatMessage('testMessage', $messageOptions));
$this->assertEquals(1, $sentMessage->getMessageId());
$this->assertEquals('telegram://api.telegram.org?channel=defaultChannel', $sentMessage->getTransport());
$this->assertEquals('telegram://host.test?channel=defaultChannel', $sentMessage->getTransport());
}
private function createTransport($channel = 'testChannel', ?HttpClientInterface $client = null): TelegramTransport
{
return (new TelegramTransport('token', $channel, $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
}
}

View File

@ -23,9 +23,7 @@ final class TwilioTransportFactoryTest extends TestCase
{
$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);
}

View File

@ -44,7 +44,7 @@ class UnsupportedSchemeException extends LogicException
],
'rocketchat' => [
'class' => Bridge\RocketChat\RocketChatTransportFactory::class,
'package' => 'rocketchat-notifier',
'package' => 'symfony/rocket-chat-notifier',
],
'twilio' => [
'class' => Bridge\Twilio\TwilioTransportFactory::class,
@ -64,7 +64,7 @@ class UnsupportedSchemeException extends LogicException
],
'ovhcloud' => [
'class' => Bridge\OvhCloud\OvhCloudTransportFactory::class,
'package' => 'symfony/ovhcloud-notifier',
'package' => 'symfony/ovh-cloud-notifier',
],
'sinch' => [
'class' => Bridge\Sinch\SinchTransportFactory::class,