Skip to content

Commit

Permalink
feat: Add payload checking
Browse files Browse the repository at this point in the history
  • Loading branch information
SMillerDev committed Nov 7, 2024
1 parent 411c308 commit 0fea2c1
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# SPDX-FileCopyrightText: Copyright 2021 M2mobi B.V., Amsterdam, The Netherlands
# SPDX-FileCopyrightText: Copyright 2022 Move Agency Group B.V., Zwolle, The Netherlands
# SPDX-License-Identifier: CC0-1.0

name: Integration Tests
on: [push, pull_request]

jobs:
phpunit:
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental }}
name: "PHP-${{ matrix.php-versions }}: Integration"
strategy:
matrix:
php-versions: ['8.3']
experimental: [false]
include:
- php-versions: 8.4
experimental: true
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: uopz
tools: phpunit:9.5.x

- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"

- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Install dependencies
run: composer update

- name: Run Payload dumper
run: php ./get_payload.php | tee payload.json

- name: Install JSONSchema
run: pipx install check-jsonschema

- name: Check payload
run: check-jsonschema --schemafile doc/schemas/message.schema.json payload.json
18 changes: 18 additions & 0 deletions doc/schemas/message.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "APNS Push Message",
"description": "A Push message for APNS",
"type": "object",
"properties": {
"aps": {
"type": "object",
"properties": {
"alert": {
"type": "object"
}
},
"required": ["alert"]
}
},
"required": ["aps"]
}
48 changes: 48 additions & 0 deletions get_payload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/**
* Push demo
*
* phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols, PSR1.Classes.ClassDeclaration.MissingNamespace
*
* SPDX-FileCopyrightText: Copyright 2010 Aldo Armiento ([email protected])
* SPDX-FileCopyrightText: Copyright 2021 M2mobi B.V., Amsterdam, The Netherlands
* SPDX-FileCopyrightText: Copyright 2022 Move Agency Group B.V., Zwolle, The Netherlands
* SPDX-License-Identifier: BSD-3-Clause
*/

// Adjust to your timezone
date_default_timezone_set('Europe/Rome');

// Report all PHP errors
error_reporting(-1);

// Using Composer autoload all classes are loaded on-demand
require_once 'vendor/autoload.php';

// Instantiate a new Message with a single recipient
$message = new \ApnsPHP\Message('1e82db91c7ceddd72bf33d74ae052ac9c84a065b35148ac401388843106a7485');

// Set a custom identifier. To get back this identifier use the getCustomIdentifier() method
// over a ApnsPHP_Message object retrieved with the getErrors() message.
$message->setCustomIdentifier('7530A828-E58E-433E-A38F-D8042208CF96');

// Set badge icon to "3"
$message->setBadge(3);

// Set a simple welcome text
$message->setText('Hello APNs-enabled device!');

// Play the default sound
$message->setSound();

// Set a custom property
$message->setCustomProperty('acme2', ['bang', 'whiz']);

// Set another custom property
$message->setCustomProperty('acme3', ['bing', 'bong']);

// Set the expiry value to 30 seconds
$message->setExpiry(30);

echo $message->getPayload();

0 comments on commit 0fea2c1

Please sign in to comment.