Skip to content

Commit 7617a3b

Browse files
feature #46047 [Notifier] smsapi - send messages in test mode (Patryk Kozłowski)
This PR was merged into the 6.1 branch. Discussion ---------- [Notifier] smsapi - send messages in test mode | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Add possibility to send messages in test mode where they are validated only (not sent, not charged). Official documentation: https://www.smsapi.pl/docs/#2-pojedynczy-sms ``` test - Wiadomość nie jest wysyłana, wyświetlana jest jedynie odpowiedź (w celach testowych). (&test=1) ``` Not sure about tests. Commits ------- 8a07636 [Notifier] smsapi - send messages in test mode
2 parents 9391281 + 8a07636 commit 7617a3b

File tree

6 files changed

+31
-5
lines changed

6 files changed

+31
-5
lines changed

src/Symfony/Component/Notifier/Bridge/Smsapi/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ CHANGELOG
44
6.1
55
---
66

7-
* Added `fast` option to the DSN that allows sending message with the highest priority that ensures the quickest possible time of delivery
7+
* Add `fast` option to the DSN that allows sending message with the highest priority that ensures the quickest possible time of delivery
8+
* Add `test` option to the DSN that allows sending message in test mode (message is validated, but not sent)
89

910
5.2
1011
---

src/Symfony/Component/Notifier/Bridge/Smsapi/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ DSN example
77
-----------
88

99
```
10-
SMSAPI_DSN=smsapi://TOKEN@default?from=FROM&fast=FAST
10+
SMSAPI_DSN=smsapi://TOKEN@default?from=FROM&fast=FAST&test=TEST
1111
```
1212

1313
where:
1414
- `TOKEN` is your API Token (OAuth)
1515
- `FROM` is the sender name
1616
- `FAST` setting this parameter to "1" (default "0") will result in sending message with the highest priority which ensures the quickest possible time of delivery. Attention! Fast messages cost more than normal messages.
17+
- `TEST` setting this parameter to "1" (default "0") will result in sending message in test mode (message is validated, but not sent).
1718

1819
See your account info at https://ssl.smsapi.pl/
1920

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ final class SmsapiTransport extends AbstractTransport
3232
private string $authToken;
3333
private string $from;
3434
private bool $fast = false;
35+
private bool $test = false;
3536

3637
public function __construct(string $authToken, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
3738
{
@@ -51,6 +52,16 @@ public function setFast(bool $fast): static
5152
return $this;
5253
}
5354

55+
/**
56+
* @return $this
57+
*/
58+
public function setTest(bool $test): static
59+
{
60+
$this->test = $test;
61+
62+
return $this;
63+
}
64+
5465
public function __toString(): string
5566
{
5667
return sprintf('smsapi://%s?from=%s&fast=%d', $this->getEndpoint(), $this->from, (int) $this->fast);
@@ -75,9 +86,9 @@ protected function doSend(MessageInterface $message): SentMessage
7586
'to' => $message->getPhone(),
7687
'message' => $message->getSubject(),
7788
'fast' => $this->fast,
78-
'encoding' => 'utf-8',
7989
'format' => 'json',
8090
'encoding' => 'utf-8',
91+
'test' => $this->test,
8192
],
8293
]);
8394

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,14 @@ public function create(Dsn $dsn): SmsapiTransport
3232
$from = $dsn->getRequiredOption('from');
3333
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
3434
$fast = filter_var($dsn->getOption('fast', false), \FILTER_VALIDATE_BOOLEAN);
35+
$test = filter_var($dsn->getOption('test', false), \FILTER_VALIDATE_BOOLEAN);
3536
$port = $dsn->getPort();
3637

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

4045
protected function getSupportedSchemes(): array

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,36 @@ public function createProvider(): iterable
2626
yield [
2727
'smsapi://host.test?from=testFrom&fast=0',
2828
'smsapi://token@host.test?from=testFrom',
29+
'smsapi://token@host.test?from=testFrom&fast=0&test=0',
2930
];
3031

3132
yield [
3233
'smsapi://host.test?from=testFrom&fast=0',
3334
'smsapi://token@host.test?from=testFrom&fast=0',
35+
'smsapi://token@host.test?from=testFrom&fast=1&test=0',
36+
'smsapi://token@host.test?from=testFrom&test=0',
3437
];
3538

3639
yield [
3740
'smsapi://host.test?from=testFrom&fast=1',
3841
'smsapi://token@host.test?from=testFrom&fast=1',
42+
'smsapi://token@host.test?from=testFrom&fast=1&test=1',
43+
'smsapi://token@host.test?from=testFrom&test=1',
3944
];
4045

4146
yield [
4247
'smsapi://host.test?from=testFrom&fast=1',
4348
'smsapi://token@host.test?from=testFrom&fast=true',
49+
'smsapi://token@host.test?from=testFrom&fast=true&test=true',
50+
'smsapi://token@host.test?from=testFrom&test=true',
4451
];
4552
}
4653

4754
public function supportsProvider(): iterable
4855
{
4956
yield [true, 'smsapi://host?from=testFrom'];
5057
yield [true, 'smsapi://host?from=testFrom&fast=1'];
58+
yield [true, 'smsapi://host?from=testFrom&fast=1&test=1'];
5159
yield [false, 'somethingElse://host?from=testFrom'];
5260
}
5361

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class SmsapiTransportTest extends TransportTestCase
2525
{
2626
public function createTransport(HttpClientInterface $client = null): SmsapiTransport
2727
{
28-
return (new SmsapiTransport('testToken', 'testFrom', $client ?? $this->createMock(HttpClientInterface::class)))->setFast(true)->setHost('test.host');
28+
return (new SmsapiTransport('testToken', 'testFrom', $client ?? $this->createMock(HttpClientInterface::class)))->setFast(true)->setHost('test.host')->setTest(true);
2929
}
3030

3131
public function toStringProvider(): iterable

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy