From b2410143579c21a03e4fdaa42b6c1a11724f72e8 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Thu, 7 Nov 2024 16:17:55 +0100 Subject: [PATCH] feat: Add payload checking --- .github/workflows/integration-tests.yml | 83 +++++++++++++++++++++++++ .github/workflows/php-tests.yml | 36 ----------- .reuse/dep5 | 4 ++ doc/schemas/message.schema.json | 53 ++++++++++++++++ get_payload.php | 44 +++++++++++++ 5 files changed, 184 insertions(+), 36 deletions(-) create mode 100644 .github/workflows/integration-tests.yml create mode 100644 doc/schemas/message.schema.json create mode 100644 get_payload.php diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml new file mode 100644 index 00000000..618bec3a --- /dev/null +++ b/.github/workflows/integration-tests.yml @@ -0,0 +1,83 @@ +# SPDX-FileCopyrightText: Copyright 2024 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: Install dependencies + run: composer update + + - name: Install JSONSchema + run: pipx install check-jsonschema + + - name: Check payload + run: | + for type in "message"; do + echo "Generate:" + php ./get_payload.php "$type" | tee "payload.$type.json" + + echo "\nValidate:" + check-jsonschema --schemafile "doc/schemas/$type.schema.json" "payload.$type.json" + done + + sample_push: + runs-on: ubuntu-latest + continue-on-error: ${{ matrix.experimental }} + name: "PHP-${{ matrix.php-versions }}: Sample" + strategy: + matrix: + php-versions: ['8.1', '8.2', '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 }} + coverage: none + extensions: uopz + + - name: Setup problem matchers for PHP + run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" + + - name: Install dependencies + run: composer update + + - name: Setup fake certificates + run: | + touch entrust_root_certification_authority.pem + touch server_certificates_bundle_sandbox.pem + + - name: Run sample + run: php sample_push.php | grep "Trying to initialize HTTP/2 backend" diff --git a/.github/workflows/php-tests.yml b/.github/workflows/php-tests.yml index 2df0930e..e589310a 100644 --- a/.github/workflows/php-tests.yml +++ b/.github/workflows/php-tests.yml @@ -56,42 +56,6 @@ jobs: - name: Run PHPUnit run: phpunit -c phpunit.xml - sample_push: - runs-on: ubuntu-latest - continue-on-error: ${{ matrix.experimental }} - name: "PHP-${{ matrix.php-versions }}: Sample" - strategy: - matrix: - php-versions: ['8.1', '8.2', '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 }} - coverage: none - extensions: uopz - - - name: Setup problem matchers for PHP - run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" - - - name: Install dependencies - run: composer update - - - name: Setup fake certificates - run: | - touch entrust_root_certification_authority.pem - touch server_certificates_bundle_sandbox.pem - - - name: Run sample - run: php sample_push.php | grep "Trying to initialize HTTP/2 backend" - phpcs: runs-on: ubuntu-latest continue-on-error: false diff --git a/.reuse/dep5 b/.reuse/dep5 index 49b938e7..f791fe6b 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -30,3 +30,7 @@ Copyright: 2015 Luca Bruno (luca.bruno@immobiliare.it) 2021 M2mobi B.V., Amsterdam, The Netherlands 2022 Move Agency Group B.V., Zwolle, The Netherlands License: CC0-1.0 + +Files: doc/schemas/*.json +Copyright: 2024 Move Agency Group B.V., Zwolle, The Netherlands +License: CC0-1.0 diff --git a/doc/schemas/message.schema.json b/doc/schemas/message.schema.json new file mode 100644 index 00000000..a7eea272 --- /dev/null +++ b/doc/schemas/message.schema.json @@ -0,0 +1,53 @@ +{ + "$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", + "additionalProperties": false, + "properties": { + "alert": { + "anyOf": [ + { + "type": "object", + "additionalProperties": false, + "properties": { + "title": { + "type": "string" + }, + "body": { + "type": "string" + } + } + }, + { + "type": "string" + } + ] + }, + "badge": { + "type": "number" + }, + "sound": { + "type": "string" + }, + "content-available": { + "type": "number" + }, + "mutable-content": { + "type": "number" + }, + "category": { + "type": "string" + }, + "thread-id": { + "type": "string" + } + }, + "required": ["alert"] + } + }, + "required": ["aps"] +} diff --git a/get_payload.php b/get_payload.php new file mode 100644 index 00000000..46a062df --- /dev/null +++ b/get_payload.php @@ -0,0 +1,44 @@ + new \ApnsPHP\Message(), +}; + +// 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();