Skip to content

[Notifier] smsapi - send messages in test mode #46047

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
Apr 19, 2022
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
3 changes: 2 additions & 1 deletion src/Symfony/Component/Notifier/Bridge/Smsapi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ CHANGELOG
6.1
---

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

5.2
---
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/Notifier/Bridge/Smsapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ DSN example
-----------

```
SMSAPI_DSN=smsapi://TOKEN@default?from=FROM&fast=FAST
SMSAPI_DSN=smsapi://TOKEN@default?from=FROM&fast=FAST&test=TEST
```

where:
- `TOKEN` is your API Token (OAuth)
- `FROM` is the sender name
- `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.
- `TEST` setting this parameter to "1" (default "0") will result in sending message in test mode (message is validated, but not sent).

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ final class SmsapiTransport extends AbstractTransport
private string $authToken;
private string $from;
private bool $fast = false;
private bool $test = false;

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

/**
* @return $this
*/
public function setTest(bool $test): static
{
$this->test = $test;

return $this;
}

public function __toString(): string
{
return sprintf('smsapi://%s?from=%s&fast=%d', $this->getEndpoint(), $this->from, (int) $this->fast);
Expand All @@ -75,9 +86,9 @@ protected function doSend(MessageInterface $message): SentMessage
'to' => $message->getPhone(),
'message' => $message->getSubject(),
'fast' => $this->fast,
'encoding' => 'utf-8',
'format' => 'json',
'encoding' => 'utf-8',
'test' => $this->test,
],
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ public function create(Dsn $dsn): SmsapiTransport
$from = $dsn->getRequiredOption('from');
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
$fast = filter_var($dsn->getOption('fast', false), \FILTER_VALIDATE_BOOLEAN);
$test = filter_var($dsn->getOption('test', false), \FILTER_VALIDATE_BOOLEAN);
$port = $dsn->getPort();

return (new SmsapiTransport($authToken, $from, $this->client, $this->dispatcher))->setFast($fast)->setHost($host)->setPort($port);
return (new SmsapiTransport($authToken, $from, $this->client, $this->dispatcher))
->setFast($fast)
->setHost($host)
->setPort($port)
->setTest($test);
}

protected function getSupportedSchemes(): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,36 @@ public function createProvider(): iterable
yield [
'smsapi://host.test?from=testFrom&fast=0',
'smsapi://token@host.test?from=testFrom',
'smsapi://token@host.test?from=testFrom&fast=0&test=0',
];

yield [
'smsapi://host.test?from=testFrom&fast=0',
'smsapi://token@host.test?from=testFrom&fast=0',
'smsapi://token@host.test?from=testFrom&fast=1&test=0',
'smsapi://token@host.test?from=testFrom&test=0',
];

yield [
'smsapi://host.test?from=testFrom&fast=1',
'smsapi://token@host.test?from=testFrom&fast=1',
'smsapi://token@host.test?from=testFrom&fast=1&test=1',
'smsapi://token@host.test?from=testFrom&test=1',
];

yield [
'smsapi://host.test?from=testFrom&fast=1',
'smsapi://token@host.test?from=testFrom&fast=true',
'smsapi://token@host.test?from=testFrom&fast=true&test=true',
'smsapi://token@host.test?from=testFrom&test=true',
];
}

public function supportsProvider(): iterable
{
yield [true, 'smsapi://host?from=testFrom'];
yield [true, 'smsapi://host?from=testFrom&fast=1'];
yield [true, 'smsapi://host?from=testFrom&fast=1&test=1'];
yield [false, 'somethingElse://host?from=testFrom'];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class SmsapiTransportTest extends TransportTestCase
{
public function createTransport(HttpClientInterface $client = null): SmsapiTransport
{
return (new SmsapiTransport('testToken', 'testFrom', $client ?? $this->createMock(HttpClientInterface::class)))->setFast(true)->setHost('test.host');
return (new SmsapiTransport('testToken', 'testFrom', $client ?? $this->createMock(HttpClientInterface::class)))->setFast(true)->setHost('test.host')->setTest(true);
}

public function toStringProvider(): iterable
Expand Down