Skip to content
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

Full package refactoring #21

Merged
merged 5 commits into from
May 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
✅ Fix serialization and tests
  • Loading branch information
ker0x committed May 20, 2023
commit b765d331b24560b36cfb38d51bee9b5665021e30
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/.php-cs-fixer.dist.php export-ignore
/phpstan.neon.dis export-ignore
/phpunit.xml.dist export-ignore
/rector.php export-ignore
2 changes: 1 addition & 1 deletion src/Model/Config/AndroidConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(
public ?string $restrictedPackageName = null,
public array $data = [],
public ?AndroidNotification $notification = null,
public ?AndroidFcmOptions $options = null,
public ?AndroidFcmOptions $fcmOptions = null,
public bool $directBootOk = false,
) {
}
Expand Down
14 changes: 12 additions & 2 deletions src/Model/Config/ApnsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,23 @@
*/
final readonly class ApnsConfig
{
public object $payload;

/**
* @param array<string, string> $headers
*/
public function __construct(
?ApnsNotification $notification = null,
public array $headers = [],
public ?ApnsNotification $payload = null,
public ?ApnsFcmOptions $options = null,
public ?ApnsFcmOptions $fcmOptions = null,
) {
if (null !== $notification) {
$this->payload = new class($notification) {
public function __construct(
public ApnsNotification $aps
) {
}
};
}
}
}
2 changes: 1 addition & 1 deletion src/Model/Config/WebpushConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(
public array $headers = [],
public array $data = [],
public ?WebpushNotification $notification = null,
public ?WebpushFcmOptions $options = null,
public ?WebpushFcmOptions $fcmOptions = null,
) {
}
}
2 changes: 1 addition & 1 deletion src/Model/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(
public ?AndroidConfig $android = null,
public ?WebpushConfig $webpush = null,
public ?ApnsConfig $apns = null,
public ?FcmOptions $options = null,
public ?FcmOptions $fcmOptions = null,
) {
$this->notification = \is_string($notification)
? new Notification($notification)
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Option/ApnsFcmOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{
public function __construct(
public ?string $analyticsLabel = null,
public ?string $images = null,
public ?string $image = null,
) {
}
}
84 changes: 43 additions & 41 deletions tests/Fixtures/message.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
},
"image": "https:\/\/example.com\/image.jpg"
},
"options": {
"fcm_options": {
"analytics_label": "android"
},
"direct_boot_ok": true
Expand Down Expand Up @@ -109,7 +109,7 @@
300
]
},
"options": {
"fcm_options": {
"analytics_label": "webpush",
"link": "https:\/\/example.com"
}
Expand All @@ -119,49 +119,51 @@
"apns-priority": "5"
},
"payload": {
"alert": {
"title": "Breaking News",
"subtitle": "Unbelievable",
"body": "Check out the Top Story",
"launch-image": "launch-image.jpg",
"title-loc-key": "title-loc-key",
"title-loc-args": [
"title-loc-args"
],
"subtitle-loc-key": "subtitle-loc-key",
"subtitle-loc-args": [
"subtitle-loc-args"
],
"loc-key": "loc-key",
"loc-args": [
"loc-args"
]
},
"badge": 2,
"sound": {
"critical": 1,
"name": "default",
"volume": 0.5
},
"thread-id": "thread-id",
"category": "category",
"content-available": 1,
"mutable-content": 1,
"target-content-id": "target-content-id",
"interruption-level": "interruption-level",
"relevance-score": 1.0,
"filter-criteria": "filter-criteria",
"stale-date": 1,
"content-state": "content-state",
"timestamp": 1684478064,
"events": "events"
"aps": {
"alert": {
"title": "Breaking News",
"subtitle": "Unbelievable",
"body": "Check out the Top Story",
"launch-image": "launch-image.jpg",
"title-loc-key": "title-loc-key",
"title-loc-args": [
"title-loc-args"
],
"subtitle-loc-key": "subtitle-loc-key",
"subtitle-loc-args": [
"subtitle-loc-args"
],
"loc-key": "loc-key",
"loc-args": [
"loc-args"
]
},
"badge": 2,
"sound": {
"critical": 1,
"name": "default",
"volume": 0.5
},
"thread-id": "thread-id",
"category": "category",
"content-available": 1,
"mutable-content": 1,
"target-content-id": "target-content-id",
"interruption-level": "interruption-level",
"relevance-score": 1.0,
"filter-criteria": "filter-criteria",
"stale-date": 1,
"content-state": "content-state",
"timestamp": 1684478064,
"events": "events"
}
},
"options": {
"fcm_options": {
"analytics_label": "apns",
"images": "https:\/\/example.com\/image.jpg"
"image": "https:\/\/example.com\/image.jpg"
}
},
"options": {
"fcm_options": {
"analytics_label": "fcm"
}
}
3 changes: 3 additions & 0 deletions tests/Fixtures/response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "projects/tales-from-a-dev/messages/4183526938010908279"
}
18 changes: 9 additions & 9 deletions tests/Model/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function testItCanSerializeMessage(): void
),
image: 'https://example.com/image.jpg',
),
options: new AndroidFcmOptions('android'),
fcmOptions: new AndroidFcmOptions('android'),
directBootOk: true,
),
webpush: new WebpushConfig(
Expand Down Expand Up @@ -165,16 +165,13 @@ public function testItCanSerializeMessage(): void
300,
],
),
options: new WebpushFcmOptions(
fcmOptions: new WebpushFcmOptions(
analyticsLabel: 'webpush',
link: 'https://example.com',
)
),
apns: new ApnsConfig(
headers: [
'apns-priority' => '5',
],
payload: new ApnsNotification(
notification: new ApnsNotification(
alert: new Alert(
title: 'Breaking News',
subtitle: 'Unbelievable',
Expand Down Expand Up @@ -211,12 +208,15 @@ public function testItCanSerializeMessage(): void
timestamp: 1684478064,
events: 'events',
),
options: new ApnsFcmOptions(
headers: [
'apns-priority' => '5',
],
fcmOptions: new ApnsFcmOptions(
analyticsLabel: 'apns',
images: 'https://example.com/image.jpg',
image: 'https://example.com/image.jpg',
)
),
options: new FcmOptions(
fcmOptions: new FcmOptions(
'fcm',
)
);
Expand Down