8000 Merge branch '5.1' into 5.2 · symfony/symfony@904b05a · GitHub
[go: up one dir, main page]

Skip to content

Commit 904b05a

Browse files
committed
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
2 parents 6112be3 + 40672e1 commit 904b05a

17 files changed

+59
-76
lines changed

src/Symfony/Component/Notifier/Bridge/Firebase/Tests/FirebaseTransportFactoryTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ public function testCreateWithDsn()
2525
{
2626
$factory = $this->createFactory();
2727

28-
$transport = $factory->create(Dsn::fromString('firebase://username:password@default'));
29-
$transport->setHost('host.test');
28+
$transport = $factory->create(Dsn::fromString('firebase://username:password@host.test'));
3029

3130
$this->assertSame('firebase://host.test', (string) $transport);
3231
}

src/Symfony/Component/Notifier/Bridge/FreeMobile/FreeMobileTransport.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*/
2828
final class FreeMobileTransport extends AbstractTransport
2929
{
30-
protected const HOST = 'https://smsapi.free-mobile.fr/sendmsg';
30+
protected const HOST = 'smsapi.free-mobile.fr/sendmsg';
3131

3232
private $login;
3333
private $password;
@@ -58,7 +58,9 @@ protected function doSend(MessageInterface $message): SentMessage
5858
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)));
5959
}
6060

61-
$response = $this->client->request('POST', $this->getEndpoint(), [
61+
$endpoint = sprintf('https://%s', $this->getEndpoint());
62+
63+
$response = $this->client->request('POST', $endpoint, [
6264
'json' => [
6365
'user' => $this->login,
6466
'pass' => $this->password,

src/Symfony/Component/Notifier/Bridge/FreeMobile/FreeMobileTransportFactory.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ public function create(Dsn $dsn): TransportInterface
4343
throw new IncompleteDsnException('Missing phone.', $dsn->getOriginalDsn());
4444
}
4545

46-
return new FreeMobileTransport($login, $password, $phone, $this->client, $this->dispatcher);
46+
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
47+
$port = $dsn->getPort();
48+
49+
return (new FreeMobileTransport($login, $password, $phone, $this->client, $this->dispatcher))->setHost($host)->setPort($port);
4750
}
4851

4952
protected function getSupportedSchemes(): array

src/Symfony/Component/Notifier/Bridge/FreeMobile/Tests/FreeMobileTransportFactoryTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ public function testCreateWithDsn()
2323
{
2424
$factory = $this->createFactory();
2525

26-
$dsn = 'freemobile://login:pass@default?phone=0611223344';
27-
$transport = $factory->create(Dsn::fromString($dsn));
28-
$transport->setHost('host.test');
26+
$transport = $factory->create(Dsn::fromString('freemobile://login:pass@host.test?phone=0611223344'));
2927

3028
$this->assertSame('freemobile://host.test?phone=0611223344', (string) $transport);
3129
}

src/Symfony/Component/Notifier/Bridge/Mattermost/Tests/MattermostTransportFactoryTest.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,9 @@ public function testCreateWithDsn()
2626
{
2727
$factory = $this->createFactory();
2828

29-
$accessToken = 'testAccessToken';
30-
$host = 'testHost';
31-
$channel = 'testChannel';
29+
$transport = $factory->create(Dsn::fromString('mattermost://accessToken@host.test?channel=testChannel'));
3230

33-
$transport = $factory->create(Dsn::fromString(sprintf('mattermost://%s@%s/?channel=%s', $accessToken, $host, $channel)));
34-
35-
$this->assertSame(sprintf('mattermost://%s?channel=%s', $host, $channel), (string) $transport);
31+
$this->assertSame('mattermost://host.test?channel=testChannel', (string) $transport);
3632
}
3733

3834
public function testCreateWithMissingOptionChannelThrowsIncompleteDsnException()
@@ -49,21 +45,21 @@ public function testCreateWithNoTokenThrowsIncompleteDsnException()
4945
$factory = $this->createFactory();
5046

5147
$this->expectException(IncompleteDsnException::class);
52-
$factory->create(Dsn::fromString(sprintf('mattermost://%s/?channel=%s', 'testHost', 'testChannel')));
48+
$factory->create(Dsn::fromString('mattermost://host.test?channel=testChannel'));
5349
}
5450

5551
public function testSupportsReturnsTrueWithSupportedScheme()
5652
{
5753
$factory = $this->createFactory();
5854

59-
$this->assertTrue($factory->supports(Dsn::fromString('mattermost://token@host/?channel=testChannel')));
55+
$this->assertTrue($factory->supports(Dsn::fromString('mattermost://token@host?channel=testChannel')));
6056
}
6157

6258
public function testSupportsReturnsFalseWithUnsupportedScheme()
6359
{
6460
$factory = $this->createFactory();
6561

66-
$this->assertFalse($factory->supports(Dsn::fromString('somethingElse://token@host/?channel=testChannel')));
62+
$this->assertFalse($factory->supports(Dsn::fromString('somethingElse://token@host?channel=testChannel')));
6763
}
6864

6965
public function testUnsupportedSchemeThrowsUnsupportedSchemeException()
@@ -72,7 +68,7 @@ public function testUnsupportedSchemeThrowsUnsupportedSchemeException()
7268

7369
$this->expectException(UnsupportedSchemeException::class);
7470

75-
$factory->create(Dsn::fromString('somethingElse://token@host/?channel=testChannel'));
71+
$factory->create(Dsn::fromString('somethingElse://token@host?channel=testChannel'));
7672
}
7773

7874
public function testUnsupportedSchemeThrowsUnsupportedSchemeExceptionEvenIfRequiredOptionIsMissing()

src/Symfony/Component/Notifier/Bridge/Mattermost/Tests/MattermostTransportTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function testSupportsChatMessage()
3838
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
3939
}
4040

41-
public function testSendNonChatMessageThrows()
41+
public function testSendNonChatMessageThrowsLogicException()
4242
{
4343
$transport = $this->createTransport();
4444

src/Symfony/Component/Notifier/Bridge/Nexmo/Tests/NexmoTransportFactoryTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ public function testCreateWithDsn()
2323
{
2424
$factory = $this->createFactory();
2525

26-
$dsn = 'nexmo://apiKey:apiSecret@default?from=0611223344';
27-
$transport = $factory->create(Dsn::fromString($dsn));
28-
$transport->setHost('host.test');
26+
$transport = $factory->create(Dsn::fromString('nexmo://apiKey:apiSecret@host.test?from=0611223344'));
2927

3028
$this->assertSame('nexmo://host.test?from=0611223344', (string) $transport);
3129
}

src/Symfony/Component/Notifier/Bridge/OvhCloud/Tests/OvhCloudTransportFactoryTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ public function testCreateWithDsn()
2323
{
2424
$factory = $this->createFactory();
2525

26-
$dsn = '< 10000 span class=pl-s>ovhcloud://applicationKey:applicationSecret@default?consumer_key=consumerKey&service_name=serviceName';
27-
$transport = $factory->create(Dsn::fromString($dsn));
28-
$transport->setHost('host.test');
26+
$transport = $factory->create(Dsn::fromString('ovhcloud://applicationKey:applicationSecret@host.test?consumer_key=consumerKey&service_name=serviceName'));
2927

3028
$this->assertSame('ovhcloud://host.test?consumer_key=consumerKey&service_name=serviceName', (string) $transport);
3129
}

src/Symfony/Component/Notifier/Bridge/RocketChat/Tests/RocketChatTransportFactoryTest.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,35 +26,31 @@ public function testCreateWithDsn()
2626
{
2727
$factory = $this->createFactory();
2828

29-
$accessToken = 'testAccessToken';
30-
$host = 'testHost';
31-
$channel = 'testChannel';
29+
$transport = $factory->create(Dsn::fromString('rocketchat://accessToken@host.test?channel=testChannel'));
3230

33-
$transport = $factory->create(Dsn::fromString(sprintf('rocketchat://%s@%s/?channel=%s', $accessToken, $host, $channel)));
34-
35-
$this->assertSame(sprintf('rocketchat://%s?channel=%s', $host, $channel), (string) $transport);
31+
$this->assertSame('rocketchat://host.test?channel=testChannel', (string) $transport);
3632
}
3733

3834
public function testCreateWithNoTokenThrowsIncompleteDsnException()
3935
{
4036
$factory = $this->createFactory();
4137

4238
$this->expectException(IncompleteDsnException::class);
43-
$factory->create(Dsn::fromString(sprintf('rocketchat://%s/?channel=%s', 'testHost', 'testChannel')));
39+
$factory->create(Dsn::fromString('rocketchat://host.test?channel=testChannel'));
4440
}
4541

4642
public function testSupportsReturnsTrueWithSupportedScheme()
4743
{
4844
$factory = $this->createFactory();
4945

50-
$this->assertTrue($factory->supports(Dsn::fromString('rocketchat://token@host/?channel=testChannel')));
46+
$this->assertTrue($factory->supports(Dsn::fromString('rocketchat://token@host?channel=testChannel')));
5147
}
5248

5349
public function testSupportsReturnsFalseWithUnsupportedScheme()
5450
{
5551
$factory = $this->createFactory();
5652

57-
$this->assertFalse($factory->supports(Dsn::fromString('somethingElse://token@host/?channel=testChannel')));
53+
$this->assertFalse($factory->supports(Dsn::fromString('somethingElse://token@host?channel=testChannel')));
5854
}
5955

6056
public function testUnsupportedSchemeThrowsUnsupportedSchemeException()
@@ -63,7 +59,7 @@ public function testUnsupportedSchemeThrowsUnsupportedSchemeException()
6359

6460
$this->expectException(UnsupportedSchemeException::class);
6561

66-
$factory->create(Dsn::fromString('somethingElse://token@host/?channel=testChannel'));
62+
$factory->create(Dsn::fromString('somethingElse://token@host?channel=testChannel'));
6763
}
6864

6965
private function createFactory(): RocketChatTransportFactory

src/Symfony/Component/Notifier/Bridge/RocketChat/Tests/RocketChatTransportTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function testSupportsChatMessage()
3838
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
3939
}
4040

41-
public function testSendNonChatMessageThrows()
41+
public function testSendNonChatMessageThrowsLogicException()
4242
{
4343
$transport = $this->createTransport();
4444

src/Symfony/Component/Notifier/Bridge/Sinch/Tests/SinchTransportFactoryTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ public function testCreateWithDsn()
2323
{
2424
$factory = $this->createFactory();
2525

26-
$dsn = 'sinch://accountSid:authToken@default?from=0611223344';
27-
$transport = $factory->create(Dsn::fromString($dsn));
28-
$transport->setHost('host.test');
26+
$transport = $factory->create(Dsn::fromString('sinch://accountSid:authToken@host.test?from=0611223344'));
2927

3028
$this->assertSame('sinch://host.test?from=0611223344', (string) $transport);
3129
}

src/Symfony/Component/Notifier/Bridge/Slack/Tests/SlackTransportFactoryTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@ public function testCreateWithDsn()
2424
{
2525
$factory = new SlackTransportFactory();
2626

27-
$host = 'testHost';
28-
$channel = 'testChannel';
29-
$transport = $factory->create(Dsn::fromString(sprintf('slack://testUser@%s/?channel=%s', $host, $channel)));
27+
$transport = $factory->create(Dsn::fromString('slack://testUser@testHost/?channel=testChannel'));
3028

31-
$this->assertSame(sprintf('slack://%s?channel=%s', $host, $channel), (string) $transport);
29+
$this->assertSame('slack://testHost?channel=testChannel', (string) $transport);
3230
}
3331

34-
public function testCreateWithDeprecatedDsn(): void
32+
public function testCreateWithDeprecatedDsn()
3533
{
3634
$this->expectException(InvalidArgumentException::class);
3735
$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 @@ public function testCreateWithDeprecatedDsn(): void
4038
$factory->create(Dsn::fromString('slack://default/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX'));
4139
}
4240

43-
public function testCreateWithNoTokenThrowsMalformed(): void
41+
public function testCreateWithNoTokenThrowsMalformed()
4442
{
4543
$factory = new SlackTransportFactory();
4644

src/Symfony/Component/Notifier/Bridge/Slack/Tests/SlackTransportTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@ final class SlackTransportTest extends TestCase
2828
{
2929
public function testToStringContainsProperties()
3030
{
31-
$host = 'testHost';
3231
$channel = 'test Channel'; // invalid channel name to test url encoding of the channel
3332

3433
$transport = new SlackTransport('testToken', $channel, $this->createMock(HttpClientInterface::class));
3534
$transport->setHost('testHost');
3635

37-
$this->assertSame(sprintf('slack://%s?channel=%s', $host, urlencode($channel)), (string) $transport);
36+
$this->assertSame('slack://testHost?channel=test+Channel', (string) $transport);
3837
}
3938

4039
public function testSupportsChatMessage()
@@ -45,7 +44,7 @@ public function testSupportsChatMessage()
4544
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
4645
}
4746

48-
public function testSendNonChatMessageThrows()
47+
public function testSendNonChatMessageThrowsLogicException()
4948
{
5049
$this->expectException(LogicException::class);
5150

src/Symfony/Component/Notifier/Bridge/Telegram/Tests/TelegramTransportFactoryTest.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,42 +23,39 @@ public function testCreateWithDsn()
2323
{
2424
$factory = $this->createFactory();
2525

26-
$host = 'testHost';
27-
$channel = 'testChannel';
26+
$transport = $factory->create(Dsn::fromString('telegram://user:password@host.test?channel=testChannel'));
2827

29-
$transport = $factory->create(Dsn::fromString(sprintf('telegram://%s@%s/?channel=%s', 'testUser:testPassword', $host, $channel)));
30-
31-
$this->assertSame(sprintf('telegram://%s?channel=%s', $host, $channel), (string) $transport);
28+
$this->assertSame('telegram://host.test?channel=testChannel', (string) $transport);
3229
}
3330

3431
public function testCreateWithNoPasswordThrowsIncompleteDsnException()
3532
{
3633
$factory = $this->createFactory();
3734

3835
$this->expectException(IncompleteDsnException::class);
39-
$factory->create(Dsn::fromString(sprintf('telegram://%s@%s/?channel=%s', 'simpleToken', 'testHost', 'testChannel')));
36+
$factory->create(Dsn::fromString('telegram://simpleToken@host.test?channel=testChannel'));
4037
}
4138

4239
public function testCreateWithNoTokenThrowsIncompleteDsnException()
4340
{
4441
$factory = $this->createFactory();
4542

4643
$this->expectException(IncompleteDsnException::class);
47-
$factory->create(Dsn::fromString(sprintf('telegram://%s/?channel=%s', 'testHost', 'testChannel')));
44+
$factory->create(Dsn::fromString('telegram://host.test?channel=testChannel'));
4845
}
4946

5047
public function testSupportsReturnsTrueWithSupportedScheme()
5148
{
5249
$factory = $this->createFactory();
5350

54-
$this->assertTrue($factory->supports(Dsn::fromString('telegram://host/?channel=testChannel')));
51+
$this->assertTrue($factory->supports(Dsn::fromString('telegram://host?channel=testChannel')));
5552
}
5653

5754
public function testSupportsReturnsFalseWithUnsupportedScheme()
5855
{
5956
$factory = $this->createFactory();
6057

61-
$this->assertFalse($factory->supports(Dsn::fromString('somethingElse://host/?channel=testChannel')));
58+
$this->assertFalse($factory->supports(Dsn::fromString('somethingElse://host?channel=testChannel')));
6259
}
6360

6461
public function testUnsupportedSchemeThrowsUnsupportedSchemeException()
@@ -67,7 +64,7 @@ public function testUnsupportedSchemeThrowsUnsupportedSchemeException()
6764

6865
$this->expectException(UnsupportedSchemeException::class);
6966

70-
$factory->create(Dsn::fromString('somethingElse://user:pwd@host/?channel=testChannel'));
67+
$factory->create(Dsn::fromString('somethingElse://user:pwd@host?channel=testChannel'));
7168
}
7269

7370
private function createFactory(): TelegramTransportFactory

src/Symfony/Component/Notifier/Bridge/Telegram/Tests/TelegramTransportTest.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,24 @@ final class TelegramTransportTest extends TestCase
2626
{
2727
public function testToStringContainsProperties()
2828
{
29-
$channel = 'testChannel';
30-
31-
$transport = new TelegramTransport('testToken', $channel, $this->createMock(HttpClientInterface::class));
32-
$transport->setHost('host.test');
29+
$transport = $this->createTransport();
3330

34-
$this->assertSame(sprintf('telegram://%s?channel=%s', 'host.test', $channel), (string) $transport);
31+
$this->assertSame('telegram://host.test?channel=testChannel', (string) $transport);
3532
}
3633

3734
public function testSupportsChatMessage()
3835
{
39-
$transport = new TelegramTransport('testToken', 'testChannel', $this->createMock(HttpClientInterface::class));
36+
$transport = $this->createTransport();
4037

4138
$this->assertTrue($transport->supports(new ChatMessage('testChatMessage')));
4239
$this->assertFalse($transport->supports($this->createMock(MessageInterface::class)));
4340
}
4441

45-
public function testSendNonChatMessageThrows()
42+
public function testSendNonChatMessageThrowsLogicException()
4643
{
44+
$transport = $this->createTransport();
45+
4746
$this->expectException(LogicException::class);
48-
$transport = new TelegramTransport('testToken', 'testChannel', $this->createMock(HttpClientInterface::class));
4947

5048
$transport->send($this->createMock(MessageInterface::class));
5149
}
@@ -67,7 +65,7 @@ public function testSendWithErrorResponseThrows()
6765
return $response;
6866
});
6967

70-
$transport = new TelegramTransport('testToken', 'testChannel', $client);
68+
$transport = $this->createTransport('testChannel', $client);
7169

7270
$transport->send(new ChatMessage('testMessage'));
7371
}
@@ -121,12 +119,12 @@ public function testSendWithOptions()
121119
return $response;
122120
});
123121

124-
$transport = new TelegramTransport('testToken', $channel, $client);
122+
$transport = $this->createTransport($channel, $client);
125123

126124
$sentMessage = $transport->send(new ChatMessage('testMessage'));
127125

128126
$this->assertEquals(1, $sentMessage->getMessageId());
129-
$this->assertEquals('telegram://api.telegram.org?channel=testChannel', $sentMessage->getTransport());
127+
$this->assertEquals('telegram://host.test?channel=testChannel', $sentMessage->getTransport());
130128
}
131129

132130
public function testSendWithChannelOverride()
@@ -177,14 +175,19 @@ public function testSendWithChannelOverride()
177175
return $response;
178176
});
179177

180-
$transport = new TelegramTransport('testToken', 'defaultChannel', $client);
178+
$transport = $this->createTransport('defaultChannel', $client);
181179

182180
$messageOptions = new TelegramOptions();
183181
$messageOptions->chatId($channelOverride);
184182

185183
$sentMessage = $transport->send(new ChatMessage('testMessage', $messageOptions));
186184

187185
$this->assertEquals(1, $sentMessage->getMessageId());
188-
$this->assertEquals('telegram://api.telegram.org?channel=defaultChannel', $sentMessage->getTransport());
186+
$this->assertEquals('telegram://host.test?channel=defaultChannel', $sentMessage->getTransport());
187+
}
188+
189+
private function createTransport($channel = 'testChannel', ?HttpClientInterface $client = null): TelegramTransport
190+
{
191+
return (new TelegramTransport('token', $channel, $client ?: $this->createMock(HttpClientInterface::class)))->setHost('host.test');
189192
}
190193
}

0 commit comments

Comments
 (0)
0