Skip to content

Commit 41803d0

Browse files
authored
Merge pull request #10 from ker0x/feature/tests
Improve tests
2 parents 0053a07 + 1b26509 commit 41803d0

File tree

7 files changed

+81
-17
lines changed

7 files changed

+81
-17
lines changed

CHANGELOG.md

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,36 @@ Version `2.x` of this library is a full rewrite to be compliant with [HTTP v1 AP
88

99
- 2.1.0 (2020-01)
1010
- Change class properties visibility from `protected` to `private`.
11-
- Add new configurations classes `Kerox\Fcm\Model\Message\Notification\AndroidNotification\Color::class`, `Kerox\Fcm\Model\Message\Notification\AndroidNotification\LightSettings::class`, `Kerox\Fcm\Model\Message\Notification\ApnsNotification\Sound::class`.
12-
- Add new options classes `\Kerox\Fcm\Model\Message\Options\AndroidOptions::class`, `Kerox\Fcm\Model\Message\Options\ApnsOptions::class`, `\Kerox\Fcm\Model\Message\Options\WebpushOptions::class`.
13-
- `\Kerox\Fcm\Model\Message\Notification\AndroidNotification::class`: add new properties `$channelId`, `$ticker`, `$sticky`, `$eventTime`, `$localOnly`, `$notificationPriority`, `$defaultSound`, `$defaultVibrateTimings`, `$defaultLightSettings`, `$vibrateTimings`, `$visibility`, `visibility`, `$lightSettings` and `$image`.
14-
- `\Kerox\Fcm\Model\Message\Notification\ApnsNotification\Alert::class`: add new properties `$subTitle`, `$subTitleLocKey` and `$subTitleLocArgs`.
15-
- `\Kerox\Fcm\Model\Message\Android::class`: add new property `$options`.
16-
- `\Kerox\Fcm\Model\Message\Apns::class`: add new property `$options`.
17-
- Method `\Kerox\Fcm\Model\Message\Webpush::setOptions()`, type `array` is deprecated, use class `\Kerox\Fcm\Model\Message\Options\WebpushOptions::class` instead.
18-
- Method `\Kerox\Fcm\Model\Message\AbstractNotification\Alert::setActionLocKey()` is deprecated and will be removed in 3.0 with no replacement.
11+
- Add new configurations classes
12+
* `Kerox\Fcm\Model\Message\Notification\AndroidNotification\Color::class`
13+
* `Kerox\Fcm\Model\Message\Notification\AndroidNotification\LightSettings::class`
14+
* `Kerox\Fcm\Model\Message\Notification\ApnsNotification\Sound::class`
15+
- Add new options classes
16+
* `Kerox\Fcm\Model\Message\Options\AndroidOptions::class`
17+
* `Kerox\Fcm\Model\Message\Options\ApnsOptions::class`
18+
* `Kerox\Fcm\Model\Message\Options\WebpushOptions::class`
19+
- `Kerox\Fcm\Model\Message\Notification\AndroidNotification::class`: add new properties
20+
* `$channelId`
21+
* `$ticker`
22+
* `$sticky`
23+
* `$eventTime`
24+
* `$localOnly`
25+
* `$notificationPriority`
26+
* `$defaultSound`
27+
* `$defaultVibrateTimings`
28+
* `$defaultLightSettings`
29+
* `$vibrateTimings`
30+
* `$visibility`
31+
* `$lightSettings`
32+
* `$image`
33+
- `Kerox\Fcm\Model\Message\Notification\ApnsNotification\Alert::class`: add new properties
34+
* `$subTitle`
35+
* `$subTitleLocKey`
36+
* `$subTitleLocArgs`
37+
- `Kerox\Fcm\Model\Message\Android::class`: add new property `$options`.
38+
- `Kerox\Fcm\Model\Message\Apns::class`: add new property `$options`.
39+
- Method `Kerox\Fcm\Model\Message\Webpush::setOptions()`, type `array` is deprecated, use class `Kerox\Fcm\Model\Message\Options\WebpushOptions::class` instead.
40+
- Method `Kerox\Fcm\Model\Message\AbstractNotification\Alert::setActionLocKey()` is deprecated and will be removed in 3.0 with no replacement.
1941

2042
- 2.0.0 (2018-09)
2143
- Rewrite library to be compatible with [HTTP v1 API](https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages)

src/Model/Message/Notification/AndroidNotification/Color.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function jsonSerialize(): array
5858
private function isValidValue(float $value): float
5959
{
6060
if ($value < 0 || $value > 1) {
61-
throw new \InvalidArgumentException('Value must be between 0 and 1.');
61+
throw new \InvalidArgumentException('RGBA value must be between 0 and 1.');
6262
}
6363

6464
return $value;

src/Model/Message/Notification/ApnsNotification.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class ApnsNotification implements \JsonSerializable
6464
public function setAlert($alert): self
6565
{
6666
if (\is_string($alert)) {
67-
$alert = (new Alert())->setBody($alert);
67+
$alert = (new Alert())->setTitle($alert);
6868
}
6969

7070
if (!$alert instanceof Alert) {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"aps": {
3+
"alert": {
4+
"title": "Breaking News"
5+
},
6+
"badge": 1,
7+
"sound": "default",
8+
"content-available": 0,
9+
"mutable-content": 0
10+
}
11+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Kerox\Fcm\Test\TestCase\Model\Message\Notification;
6+
7+
use Kerox\Fcm\Model\Message\Notification\AndroidNotification\Color;
8+
use Kerox\Fcm\Model\Message\Notification\AndroidNotification\LightSettings;
9+
use Kerox\Fcm\Test\TestCase\AbstractTestCase;
10+
11+
class AndroidNotificationTest extends AbstractTestCase
12+
{
13+
public function testLightSettingsWithInvalidColor(): void
14+
{
15+
$this->expectException(\InvalidArgumentException::class);
16+
$this->expectExceptionMessage('RGBA value must be between 0 and 1.');
17+
18+
(new LightSettings(
19+
new Color(0.1, 0.2, 0.3, 2),
20+
'3,5s',
21+
'3,5s'
22+
));
23+
}
24+
}

tests/TestCase/Model/Message/Notification/ApnsNotificationTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,11 @@ public function testApnsNotificationWithInvalidAlert(): void
1414

1515
(new ApnsNotification())->setAlert(true);
1616
}
17+
18+
public function testApnsNotificationWithStringAlert(): void
19+
{
20+
$apnsNotification = (new ApnsNotification())->setAlert('Breaking News');
21+
22+
$this->assertJsonStringEqualsJsonFile(__DIR__ . '/../../../../Mocks/Model/basic_apns_notification.json', json_encode($apnsNotification));
23+
}
1724
}

tests/TestCase/Model/MessageTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function testMessage(): void
9898
'count' => '3',
9999
])
100100
->setNotification(
101-
(new WebpushNotification())
101+
(new WebpushNotification)
102102
->setTitle('New Breaking')
103103
->setBody('Check out the Top Story')
104104
->setPermission(WebpushNotification::PERMISSION_GRANTED)
@@ -134,16 +134,16 @@ public function testMessage(): void
134134
)
135135
)
136136
->setApns(
137-
(new Apns())
137+
(new Apns)
138138
->setHeaders([
139139
'name' => 'wrench',
140140
'mass' => '1.3kg',
141141
'count' => '3',
142142
])
143143
->setPayload(
144-
(new ApnsNotification())
144+
(new ApnsNotification)
145145
->setAlert(
146-
(new Alert())
146+
(new Alert)
147147
->setTitle('Breaking News')
148148
->setBody('Check out the Top Story')
149149
->setSubTitle('Unbelievable')
@@ -164,7 +164,7 @@ public function testMessage(): void
164164
)
165165
->setBadge(true)
166166
->setSound(
167-
(new Sound())
167+
(new Sound)
168168
->isCritical()
169169
->setName(Sound::DEFAULT_NAME)
170170
->setVolume(0.5)
@@ -176,7 +176,7 @@ public function testMessage(): void
176176
->setTargetContentId('target-content-id')
177177
)
178178
->setOptions(
179-
(new ApnsOptions())
179+
(new ApnsOptions)
180180
->setAnalyticsLabel('apns')
181181
->setImage('https://example.com/image.jpg')
182182
)
@@ -185,7 +185,7 @@ public function testMessage(): void
185185
return (new Condition)->or('TopicB', 'TopicC');
186186
}))
187187
->setOptions(
188-
(new Options())
188+
(new Options)
189189
->setAnalyticsLabel('fcm')
190190
)
191191
;

0 commit comments

Comments
 (0)