Skip to content

Commit cd7e4d6

Browse files
StaffNowafabpot
authored andcommitted
[Notifier] [SMSBiuras] true/false mismatch for test_mode option
1 parent 5882b4f commit cd7e4d6

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

src/Symfony/Component/Notifier/Bridge/SmsBiuras/SmsBiurasTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected function doSend(MessageInterface $message): SentMessage
8585
'apikey' => $this->apiKey,
8686
'message' => $message->getSubject(),
8787
'from' => $this->from,
88-
'test' => $this->testMode ? 0 : 1,
88+
'test' => $this->testMode ? 1 : 0,
8989
'to' => $message->getPhone(),
9090
],
9191
]);

src/Symfony/Component/Notifier/Bridge/SmsBiuras/Tests/SmsBiurasTransportTest.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111

1212
namespace Symfony\Component\Notifier\Bridge\SmsBiuras\Tests;
1313

14+
use Symfony\Component\HttpClient\MockHttpClient;
1415
use Symfony\Component\Notifier\Bridge\SmsBiuras\SmsBiurasTransport;
1516
use Symfony\Component\Notifier\Message\ChatMessage;
1617
use Symfony\Component\Notifier\Message\MessageInterface;
1718
use Symfony\Component\Notifier\Message\SmsMessage;
1819
use Symfony\Component\Notifier\Test\TransportTestCase;
1920
use Symfony\Component\Notifier\Transport\TransportInterface;
2021
use Symfony\Contracts\HttpClient\HttpClientInterface;
22+
use Symfony\Contracts\HttpClient\ResponseInterface;
2123

2224
final class SmsBiurasTransportTest extends TransportTestCase
2325
{
@@ -44,4 +46,80 @@ public function unsupportedMessagesProvider(): iterable
4446
yield [new ChatMessage('Hello!')];
4547
yield [$this->createMock(MessageInterface::class)];
4648
}
49+
50+
/**
51+
* @dataProvider provideTestMode()
52+
*/
53+
public function testTestMode(array $expected, array $provided)
54+
{
55+
$message = new SmsMessage($provided['phone'], $provided['message']);
56+
57+
$response = $this->createMock(ResponseInterface::class);
58+
$response->expects($this->atLeast(1))
59+
->method('getStatusCode')
60+
->willReturn(200);
61+
$response->expects($this->atLeast(1))
62+
->method('getContent')
63+
->willReturn('OK: 519545');
64+
65+
$client = new MockHttpClient(function (string $method, string $url, array $options = []) use ($response, $expected): ResponseInterface {
66+
$this->assertSame('GET', $method);
67+
$this->assertSame(sprintf(
68+
'https://savitarna.smsbiuras.lt/api?uid=uid&apikey=api_key&message=%s&from=from&test=%s&to=%s',
69+
rawurlencode($expected['message']),
70+
$expected['transport']['test_mode'],
71+
rawurlencode($expected['phone']),
72+
), $url);
73+
$this->assertSame($expected['transport']['test_mode'], $options['query']['test']);
74+
75+
$this->assertSame(200, $response->getStatusCode());
76+
$this->assertSame('OK: 519545', $response->getContent());
77+
78+
return $response;
79+
});
80+
81+
$transport = new SmsBiurasTransport('uid', 'api_key', 'from', $provided['transport']['test_mode'], $client);
82+
83+
$sentMessage = $transport->send($message);
84+
85+
$this->assertSame('519545', $sentMessage->getMessageId());
86+
}
87+
88+
public static function provideTestMode(): array
89+
{
90+
return [
91+
[
92+
[
93+
'phone' => '+37012345678',
94+
'message' => 'Hello world!',
95+
'transport' => [
96+
'test_mode' => 0,
97+
],
98+
],
99+
[
100+
'phone' => '+37012345678',
101+
'message' => 'Hello world!',
102+
'transport' => [
103+
'test_mode' => 0,
104+
],
105+
],
106+
],
107+
[
108+
[
109+
'phone' => '+37012345678',
110+
'message' => 'Hello world!',
111+
'transport' => [
112+
'test_mode' => 1,
113+
],
114+
],
115+
[
116+
'phone' => '+37012345678',
117+
'message' => 'Hello world!',
118+
'transport' => [
119+
'test_mode' => 1,
120+
],
121+
],
122+
],
123+
];
124+
}
47125
}

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