8000 [Notifier] Adding more tests for PushoverTransport · symfony/symfony@19f8f37 · GitHub
[go: up one dir, main page]

Skip to content

Commit 19f8f37

Browse files
committed
[Notifier] Adding more tests for PushoverTransport
1 parent 08cd6dd commit 19f8f37

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed

src/Symfony/Component/Notifier/Bridge/Pushover/PushoverOptions.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ public function title(string $title): static
165165
/**
166166
* @see https://pushover.net/api#urls
167167
*
168-
*
169168
* @return $this
170169
*/
171170
public function url(string $url): static
@@ -178,7 +177,6 @@ public function url(string $url): static
178177
/**
179178
* @see https://pushover.net/api#urls
180179
*
181-
*
182180
* @return $this
183181
*/
184182
public function urlTitle(string $urlTitle): static

src/Symfony/Component/Notifier/Bridge/Pushover/PushoverTransport.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ protected function doSend(MessageInterface $message): SentMessage
5656
$opts = $message->getOptions();
5757
$options = $opts ? $opts->toArray() : [];
5858
$options['message'] = $message->getContent();
59+
$options['title'] = $message->getSubject();
5960
$options['token'] = $this->appToken;
6061
$options['user'] = $this->userKey;
6162

src/Symfony/Component/Notifier/Bridge/Pushover/Tests/PushoverTransportTest.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
use Symfony\Component\Notifier\Bridge\Pushover\PushoverTransport;
1616
use Symfony\Component\Notifier\Message\ChatMessage;
1717
use Symfony\Component\Notifier\Message\PushMessage;
18+
use Symfony\Component\Notifier\Notification\Notification;
1819
use Symfony\Component\Notifier\Test\TransportTestCase;
1920
use Symfony\Component\Notifier\Tests\Transport\DummyMessage;
2021
use Symfony\Contracts\HttpClient\HttpClientInterface;
22+
use Symfony\Contracts\HttpClient\ResponseInterface;
2123

2224
final class PushoverTransportTest extends TransportTestCase
2325
{
@@ -41,4 +43,81 @@ public static function unsupportedMessagesProvider(): iterable
4143
yield [new ChatMessage('Hello!')];
4244
yield [new DummyMessage()];
4345
}
46+
47+
public function testSendWithOptions()
48+
{
49+
$messageSubject = 'testMessageSubject';
50+
$messageContent = 'testMessageContent';
51+
52+
$response = $this->createMock(ResponseInterface::class);
53+
54+
$response->expects($this->exactly(2))
55+
->method('getStatusCode')
56+
->willReturn(200);
57+
58+
$response->expects($this->once())
59+
->method('getContent')
60+
->willReturn(json_encode(['status' => 1, 'request' => 'uuid']));
61+
62+
$expectedBody = http_build_query([
63+
'message' => 'testMessageContent',
64+
'title' => 'testMessageSubject',
65+
'token' => 'appToken',
66+
'user' => 'userKey',
67+
]);
68+
69+
$client = new MockHttpClient(function (string $method, string $url, array $options = []) use (
70+
$response,
71+
$expectedBody
72+
): ResponseInterface {
73+
$this->assertSame($expectedBody, $options['body']);
74+
75+
return $response;
76+
});
77+
$transport = self::createTransport($client);
78+
79+
$sentMessage = $transport->send(new PushMessage($messageSubject, $messageContent));
80+
81+
$this->assertSame('uuid', $sentMessage->getMessageId());
82+
}
83+
84+
public function testSendWithNotification()
85+
{
86+
$messageSubject = 'testMessageSubject';
87+
$messageContent = 'testMessageContent';
88+
89+
$response = $this->createMock(ResponseInterface::class);
90+
91+
$response->expects($this->exactly(2))
92+
->method('getStatusCode')
93+
->willReturn(200);
94+
95+
$response->expects($this->once())
96+
->method('getContent')
97+
->willReturn(json_encode(['status' => 1, 'request' => 'uuid']));
98+
99+
$notification = (new Notification($messageSubject))->content($messageContent);
100+
$pushMessage = PushMessage::fromNotification($notification);
101+
102+
$expectedBody = http_build_query([
103+
'message' => 'testMessageContent',
104+
'title' => 'testMessageSubject',
105+
'token' => 'appToken',
106+
'user' => 'userKey',
107+
]);
108+
109+
$client = new MockHttpClient(function (string $method, string $url, array $options = []) use (
110+
$response,
111+
$expectedBody
112+
): ResponseInterface {
113+
$this->assertSame($expectedBody, $options['body']);
114+
115+
return $response;
116+
});
117+
$transport = self::createTransport($client);
118+
119+
$sentMessage = $transport->send($pushMessage);
120+
121+
$this->assertSame('uuid', $sentMessage->getMessageId());
122+
}
44123
}

0 commit comments

Comments
 (0)
0