Skip to content

Commit 55f6d9d

Browse files
minor symfony#46103 [Notifier] [Smsapi] Show test and fast in DSN only when true (OskarStark)
This PR was squashed before being merged into the 6.1 branch. Discussion ---------- [Notifier] [Smsapi] Show `test` and `fast` in DSN only when `true` | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Follows symfony#46047 | License | MIT | Doc PR | -- Commits ------- 692e277 [Notifier] [Smsapi] Show `test` and `fast` in DSN only when `true`
2 parents aad8aee + 692e277 commit 55f6d9d

File tree

4 files changed

+46
-19
lines changed

4 files changed

+46
-19
lines changed

src/Symfony/Component/Notifier/Bridge/Smsapi/SmsapiTransport.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,17 @@ public function setTest(bool $test): static
6464

6565
public function __toString(): string
6666
{
67-
return sprintf('smsapi://%s?from=%s&fast=%d', $this->getEndpoint(), $this->from, (int) $this->fast);
67+
$dsn = sprintf('smsapi://%s?from=%s', $this->getEndpoint(), $this->from);
68+
69+
if ($this->fast) {
70+
$dsn .= sprintf('&fast=%d', (int) $this->fast);
71+
}
72+
73+
if ($this->test) {
74+
$dsn .= sprintf('&test=%d', (int) $this->test);
75+
}
76+
77+
return $dsn;
6878
}
6979

7080
public function supports(MessageInterface $message): bool

src/Symfony/Component/Notifier/Bridge/Smsapi/SmsapiTransportFactory.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ public function create(Dsn $dsn): SmsapiTransport
3535
$test = filter_var($dsn->getOption('test', false), \FILTER_VALIDATE_BOOLEAN);
3636
$port = $dsn->getPort();
3737

38-
return (new SmsapiTransport($authToken, $from, $this->client, $this->dispatcher))
39-
->setFast($fast)
40-
->setHost($host)
41-
->setPort($port)
42-
->setTest($test);
38+
return (new SmsapiTransport($authToken, $from, $this->client, $this->dispatcher))->setFast($fast)->setHost($host)->setPort($port)->setTest($test);
4339
}
4440

4541
protected function getSupportedSchemes(): array

src/Symfony/Component/Notifier/Bridge/Smsapi/Tests/SmsapiTransportFactoryTest.php

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,38 +24,56 @@ public function createFactory(): SmsapiTransportFactory
2424
public function createProvider(): iterable
2525
{
2626
yield [
27-
'smsapi://host.test?from=testFrom&fast=0',
27+
'smsapi://host.test?from=testFrom',
2828
'smsapi://[email protected]?from=testFrom',
29-
'smsapi://[email protected]?from=testFrom&fast=0&test=0',
3029
];
3130

3231
yield [
33-
'smsapi://host.test?from=testFrom&fast=0',
34-
'smsapi://[email protected]?from=testFrom&fast=0',
35-
'smsapi://[email protected]?from=testFrom&fast=1&test=0',
32+
'smsapi://host.test?from=testFrom',
3633
'smsapi://[email protected]?from=testFrom&test=0',
3734
];
3835

36+
yield [
37+
'smsapi://host.test?from=testFrom',
38+
'smsapi://[email protected]?from=testFrom&fast=0',
39+
];
40+
41+
yield [
42+
'smsapi://host.test?from=testFrom',
43+
'smsapi://[email protected]?from=testFrom&test=false',
44+
];
45+
46+
yield [
47+
'smsapi://host.test?from=testFrom',
48+
'smsapi://[email protected]?from=testFrom&fast=false',
49+
];
50+
51+
yield [
52+
'smsapi://host.test?from=testFrom&test=1',
53+
'smsapi://[email protected]?from=testFrom&test=1',
54+
];
55+
3956
yield [
4057
'smsapi://host.test?from=testFrom&fast=1',
4158
'smsapi://[email protected]?from=testFrom&fast=1',
42-
'smsapi://[email protected]?from=testFrom&fast=1&test=1',
43-
'smsapi://[email protected]?from=testFrom&test=1',
59+
];
60+
61+
yield [
62+
'smsapi://host.test?from=testFrom&test=1',
63+
'smsapi://[email protected]?from=testFrom&test=true',
4464
];
4565

4666
yield [
4767
'smsapi://host.test?from=testFrom&fast=1',
4868
'smsapi://[email protected]?from=testFrom&fast=true',
49-
'smsapi://[email protected]?from=testFrom&fast=true&test=true',
50-
'smsapi://[email protected]?from=testFrom&test=true',
5169
];
5270
}
5371

5472
public function supportsProvider(): iterable
5573
{
5674
yield [true, 'smsapi://host?from=testFrom'];
5775
yield [true, 'smsapi://host?from=testFrom&fast=1'];
58-
yield [true, 'smsapi://host?from=testFrom&fast=1&test=1'];
76+
yield [true, 'smsapi://host?from=testFrom&test=1'];
5977
yield [false, 'somethingElse://host?from=testFrom'];
6078
}
6179

src/Symfony/Component/Notifier/Bridge/Smsapi/Tests/SmsapiTransportTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@
2323

2424
final class SmsapiTransportTest extends TransportTestCase
2525
{
26-
public function createTransport(HttpClientInterface $client = null): SmsapiTransport
26+
public function createTransport(HttpClientInterface $client = null, bool $fast = false, bool $test = false): SmsapiTransport
2727
{
28-
return (new SmsapiTransport('testToken', 'testFrom', $client ?? $this->createMock(HttpClientInterface::class)))->setFast(true)->setHost('test.host')->setTest(true);
28+
return (new SmsapiTransport('testToken', 'testFrom', $client ?? $this->createMock(HttpClientInterface::class)))->setHost('test.host')->setFast($fast)->setTest($test);
2929
}
3030

3131
public function toStringProvider(): iterable
3232
{
33-
yield ['smsapi://test.host?from=testFrom&fast=1', $this->createTransport()];
33+
yield ['smsapi://test.host?from=testFrom', $this->createTransport()];
34+
yield ['smsapi://test.host?from=testFrom&fast=1', $this->createTransport(null, true)];
35+
yield ['smsapi://test.host?from=testFrom&test=1', $this->createTransport(null, false, true)];
36+
yield ['smsapi://test.host?from=testFrom&fast=1&test=1', $this->createTransport(null, true, true)];
3437
}
3538

3639
public function supportedMessagesProvider(): iterable

0 commit comments

Comments
 (0)