Skip to content

Commit 0fea2c1

Browse files
committed
feat: Add payload checking
1 parent 411c308 commit 0fea2c1

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# SPDX-FileCopyrightText: Copyright 2021 M2mobi B.V., Amsterdam, The Netherlands
2+
# SPDX-FileCopyrightText: Copyright 2022 Move Agency Group B.V., Zwolle, The Netherlands
3+
# SPDX-License-Identifier: CC0-1.0
4+
5+
name: Integration Tests
6+
on: [push, pull_request]
7+
8+
jobs:
9+
phpunit:
10+
runs-on: ubuntu-latest
11+
continue-on-error: ${{ matrix.experimental }}
12+
name: "PHP-${{ matrix.php-versions }}: Integration"
13+
strategy:
14+
matrix:
15+
php-versions: ['8.3']
16+
experimental: [false]
17+
include:
18+
- php-versions: 8.4
19+
experimental: true
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v3
23+
24+
- name: Setup PHP
25+
uses: shivammathur/setup-php@v2
26+
with:
27+
php-version: ${{ matrix.php-versions }}
28+
extensions: uopz
29+
tools: phpunit:9.5.x
30+
31+
- name: Setup problem matchers for PHP
32+
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
33+
34+
- name: Setup problem matchers for PHPUnit
35+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
36+
37+
- name: Install dependencies
38+
run: composer update
39+
40+
- name: Run Payload dumper
41+
run: php ./get_payload.php | tee payload.json
42+
43+
- name: Install JSONSchema
44+
run: pipx install check-jsonschema
45+
46+
- name: Check payload
47+
run: check-jsonschema --schemafile doc/schemas/message.schema.json payload.json

doc/schemas/message.schema.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"title": "APNS Push Message",
4+
"description": "A Push message for APNS",
5+
"type": "object",
6+
"properties": {
7+
"aps": {
8+
"type": "object",
9+
"properties": {
10+
"alert": {
11+
"type": "object"
12+
}
13+
},
14+
"required": ["alert"]
15+
}
16+
},
17+
"required": ["aps"]
18+
}

get_payload.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/**
4+
* Push demo
5+
*
6+
* phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols, PSR1.Classes.ClassDeclaration.MissingNamespace
7+
*
8+
* SPDX-FileCopyrightText: Copyright 2010 Aldo Armiento ([email protected])
9+
* SPDX-FileCopyrightText: Copyright 2021 M2mobi B.V., Amsterdam, The Netherlands
10+
* SPDX-FileCopyrightText: Copyright 2022 Move Agency Group B.V., Zwolle, The Netherlands
11+
* SPDX-License-Identifier: BSD-3-Clause
12+
*/
13+
14+
// Adjust to your timezone
15+
date_default_timezone_set('Europe/Rome');
16+
17+
// Report all PHP errors
18+
error_reporting(-1);
19+
20+
// Using Composer autoload all classes are loaded on-demand
21+
require_once 'vendor/autoload.php';
22+
23+
// Instantiate a new Message with a single recipient
24+
$message = new \ApnsPHP\Message('1e82db91c7ceddd72bf33d74ae052ac9c84a065b35148ac401388843106a7485');
25+
26+
// Set a custom identifier. To get back this identifier use the getCustomIdentifier() method
27+
// over a ApnsPHP_Message object retrieved with the getErrors() message.
28+
$message->setCustomIdentifier('7530A828-E58E-433E-A38F-D8042208CF96');
29+
30+
// Set badge icon to "3"
31+
$message->setBadge(3);
32+
33+
// Set a simple welcome text
34+
$message->setText('Hello APNs-enabled device!');
35+
36+
// Play the default sound
37+
$message->setSound();
38+
39+
// Set a custom property
40+
$message->setCustomProperty('acme2', ['bang', 'whiz']);
41+
42+
// Set another custom property
43+
$message->setCustomProperty('acme3', ['bing', 'bong']);
44+
45+
// Set the expiry value to 30 seconds
46+
$message->setExpiry(30);
47+
48+
echo $message->getPayload();

0 commit comments

Comments
 (0)