Skip to content

Commit 915ca26

Browse files
minor symfony#61496 [Notifier] Add tests for option classes (OskarStark)
This PR was squashed before being merged into the 7.4 branch. Discussion ---------- [Notifier] Add tests for option classes | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | -- | License | MIT Commits ------- eb4e18e [Notifier] Add tests for option classes
2 parents d2d869f + eb4e18e commit 915ca26

File tree

9 files changed

+726
-16
lines changed

9 files changed

+726
-16
lines changed

src/Symfony/Component/Notifier/Bridge/Discord/Tests/DiscordOptionsTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ public function testDiscordOptions()
2828
->avatarUrl('http://ava.tar/pic.png')
2929
->tts(true);
3030

31-
$this->assertSame($discordOptions->toArray(), [
31+
$this->assertSame([
3232
'username' => 'name of the bot',
3333
'avatar_url' => 'http://ava.tar/pic.png',
3434
'tts' => true,
35-
]);
35+
], $discordOptions->toArray());
3636
}
3737

3838
public function testDiscordEmbedFields()
@@ -53,7 +53,7 @@ public function testDiscordEmbedFields()
5353
->title('New song added!')
5454
);
5555

56-
$this->assertSame($discordOptions->toArray(), [
56+
$this->assertSame([
5757
'embeds' => [
5858
[
5959
'description' => 'descript.io',
@@ -70,7 +70,7 @@ public function testDiscordEmbedFields()
7070
'title' => 'New song added!',
7171
],
7272
],
73-
]);
73+
], $discordOptions->toArray());
7474

7575
$discordOptions = (new DiscordOptions())
7676
->addEmbed((new DiscordEmbed())
@@ -108,7 +108,7 @@ public function testDiscordEmbedFields()
108108
)
109109
);
110110

111-
$this->assertSame($discordOptions->toArray(), [
111+
$this->assertSame([
112112
'embeds' => [
113113
[
114114
'description' => 'descript.io',
@@ -141,7 +141,7 @@ public function testDiscordEmbedFields()
141141
],
142142
],
143143
],
144-
]);
144+
], $discordOptions->toArray());
145145
}
146146

147147
public function testDiscordFooterEmbedFields()
@@ -152,11 +152,11 @@ public function testDiscordFooterEmbedFields()
152152
->proxyIconUrl('proxy icon url')
153153
;
154154

155-
$this->assertSame($footer->toArray(), [
155+
$this->assertSame([
156156
'text' => 'text',
157157
'icon_url' => 'icon url',
158158
'proxy_icon_url' => 'proxy icon url',
159-
]);
159+
], $footer->toArray());
160160
}
161161

162162
public function testDiscordMediaEmbedFields()
@@ -168,12 +168,12 @@ public function testDiscordMediaEmbedFields()
168168
->width(600)
169169
;
170170

171-
$this->assertSame($media->toArray(), [
171+
$this->assertSame([
172172
'url' => 'https://ur.l/',
173173
'proxy_url' => 'https://proxy.ur.l/',
174174
'height' => 900,
175175
'width' => 600,
176-
]);
176+
], $media->toArray());
177177
}
178178

179179
public function testDiscordAuthorEmbedFields()
@@ -185,12 +185,12 @@ public function testDiscordAuthorEmbedFields()
185185
->proxyIconUrl('https://proxy.ic.on/url')
186186
;
187187

188-
$this->assertSame($author->toArray(), [
188+
$this->assertSame([
189189
'name' => 'name field',
190190
'url' => 'https://ur.l/',
191191
'icon_url' => 'https://icon.ur.l/',
192192
'proxy_icon_url' => 'https://proxy.ic.on/url',
193-
]);
193+
], $author->toArray());
194194
}
195195

196196
#[DataProvider('getRecipientIdProvider')]
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\Firebase\Tests\Notification;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Notifier\Bridge\Firebase\Notification\AndroidNotification;
16+
17+
final class AndroidNotificationTest extends TestCase
18+
{
19+
public function testAndroidNotificationOptions()
20+
{
21+
$notification = new AndroidNotification('device_token', [
22+
'title' => 'Test Title',
23+
'body' => 'Test Body',
24+
], ['key' => 'value']);
25+
26+
$this->assertSame([
27+
'to' => 'device_token',
28+
'notification' => [
29+
'title' => 'Test Title',
30+
'body' => 'Test Body',
31+
],
32+
'data' => ['key' => 'value'],
33+
], $notification->toArray());
34+
35+
$this->assertSame('device_token', $notification->getRecipientId());
36+
}
37+
38+
public function testAndroidNotificationWithAllOptions()
39+
{
40+
$notification = (new AndroidNotification('device_token', []))
41+
->title('New Title')
42+
->body('New Body')
43+
->data(['custom' => 'data'])
44+
->channelId('channel_123')
45+
->icon('notification_icon')
46+
->sound('notification_sound')
47+
->tag('tag_123')
48+
->color('#FF0000')
49+
->clickAction('OPEN_ACTIVITY')
50+
->bodyLocKey('body_key')
51+
->bodyLocArgs(['arg1', 'arg2'])
52+
->titleLocKey('title_key')
53+
->titleLocArgs(['title_arg1', 'title_arg2']);
54+
55+
$expected = [
56+
'to' => 'device_token',
57+
'notification' => [
58+
'title' => 'New Title',
59+
'body' => 'New Body',
60+
'android_channel_id' => 'channel_123',
61+
'icon' => 'notification_icon',
62+
'sound' => 'notification_sound',
63+
'tag' => 'tag_123',
64+
'color' => '#FF0000',
65+
'click_action' => 'OPEN_ACTIVITY',
66+
'body_loc_key' => 'body_key',
67+
'body_loc_args' => ['arg1', 'arg2'],
68+
'title_loc_key' => 'title_key',
69+
'title_loc_args' => ['title_arg1', 'title_arg2'],
70+
],
71+
'data' => ['custom' => 'data'],
72+
];
73+
74+
$this->assertSame($expected, $notification->toArray());
75+
}
76+
77+
public function testAndroidNotificationChaining()
78+
{
79+
$notification = new AndroidNotification('device_token', []);
80+
81+
$result = $notification
82+
->channelId('test_channel')
83+
->icon('test_icon');
84+
85+
$this->assertSame($notification, $result);
86+
$this->assertSame([
87+
'to' => 'device_token',
88+
'notification' => [
89+
'android_channel_id' => 'test_channel',
90+
'icon' => 'test_icon',
91+
],
92+
'data' => [],
93+
], $notification->toArray());
94+
}
95+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\Firebase\Tests\Notification;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Notifier\Bridge\Firebase\Notification\IOSNotification;
16+
17+
final class IOSNotificationTest extends TestCase
18+
{
19+
public function testIOSNotificationOptions()
20+
{
21+
$notification = new IOSNotification('device_token', [
22+
'title' => 'Test Title',
23+
'body' => 'Test Body',
24+
], ['key' => 'value']);
25+
26+
$this->assertSame([
27+
'to' => 'device_token',
28+
'notification' => [
29+
'title' => 'Test Title',
30+
'body' => 'Test Body',
31+
],
32+
'data' => ['key' => 'value'],
33+
], $notification->toArray());
34+
35+
$this->assertSame('device_token', $notification->getRecipientId());
36+
}
37+
38+
public function testIOSNotificationWithAllOptions()
39+
{
40+
$notification = (new IOSNotification('device_token', []))
41+
->title('New Title')
42+
->body('New Body')
43+
->data(['custom' => 'data'])
44+
->sound('default')
45+
->badge('5')
46+
->clickAction('OPEN_ACTIVITY')
47+
->subtitle('Test Subtitle')
48+
->bodyLocKey('body_key')
49+
->bodyLocArgs(['arg1', 'arg2'])
50+
->titleLocKey('title_key')
51+
->titleLocArgs(['title_arg1', 'title_arg2']);
52+
53+
$expected = [
54+
'to' => 'device_token',
55+
'notification' => [
56+
'title' => 'New Title',
57+
'body' => 'New Body',
58+
'sound' => 'default',
59+
'badge' => '5',
60+
'click_action' => 'OPEN_ACTIVITY',
61+
'subtitle' => 'Test Subtitle',
62+
'body_loc_key' => 'body_key',
63+
'body_loc_args' => ['arg1', 'arg2'],
64+
'title_loc_key' => 'title_key',
65+
'title_loc_args' => ['title_arg1', 'title_arg2'],
66+
],
67+
'data' => ['custom' => 'data'],
68+
];
69+
70+
$this->assertSame($expected, $notification->toArray());
71+
}
72+
73+
public function testIOSNotificationChaining()
74+
{
75+
$notification = new IOSNotification('device_token', []);
76+
77+
$result = $notification
78+
->sound('ping.aiff')
79+
->badge('10')
80+
->subtitle('Important');
81+
82+
$this->assertSame($notification, $result);
83+
$this->assertSame([
84+
'to' => 'device_token',
85+
'notification' => [
86+
'sound' => 'ping.aiff',
87+
'badge' => '10',
88+
'subtitle' => 'Important',
89+
],
90+
'data' => [],
91+
], $notification->toArray());
92+
}
93+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\Firebase\Tests\Notification;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Notifier\Bridge\Firebase\Notification\WebNotification;
16+
17+
final class WebNotificationTest extends TestCase
18+
{
19+
public function testWebNotificationOptions()
20+
{
21+
$notification = new WebNotification('device_token', [
22+
'title' => 'Test Title',
23+
'body' => 'Test Body',
24+
], ['key' => 'value']);
25+
26+
$this->assertSame([
27+
'to' => 'device_token',
28+
'notification' => [
29+
'title' => 'Test Title',
30+
'body' => 'Test Body',
31+
],
32+
'data' => ['key' => 'value'],
33+
], $notification->toArray());
34+
35+
$this->assertSame('device_token', $notification->getRecipientId());
36+
}
37+
38+
public function testWebNotificationWithAllOptions()
39+
{
40+
$notification = (new WebNotification('device_token', []))
41+
->title('New Title')
42+
->body('New Body')
43+
->data(['custom' => 'data'])
44+
->icon('/images/icon.png')
45+
->clickAction('https://example.com');
46+
47+
$expected = [
48+
'to' => 'device_token',
49+
'notification' => [
50+
'title' => 'New Title',
51+
'body' => 'New Body',
52+
'icon' => '/images/icon.png',
53+
'click_action' => 'https://example.com',
54+
],
55+
'data' => ['custom' => 'data'],
56+
];
57+
58+
$this->assertSame($expected, $notification->toArray());
59+
}
60+
61+
public function testWebNotificationChaining()
62+
{
63+
$notification = new WebNotification('device_token', []);
64+
65+
$result = $notification
66+
->icon('/favicon.ico')
67+
->clickAction('https://myapp.com/action');
68+
69+
$this->assertSame($notification, $result);
70+
$this->assertSame([
71+
'to' => 'device_token',
72+
'notification' => [
73+
'icon' => '/favicon.ico',
74+
'click_action' => 'https://myapp.com/action',
75+
],
76+
'data' => [],
77+
], $notification->toArray());
78+
}
79+
}

0 commit comments

Comments
 (0)