-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apns: Split alert payload from base payload
- Loading branch information
1 parent
47dfb4a
commit 6f99419
Showing
13 changed files
with
247 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/** | ||
* This file contains functionality to generate Apple Push Notification Service payloads. | ||
* | ||
* SPDX-FileCopyrightText: Copyright 2014 M2mobi B.V., Amsterdam, The Netherlands | ||
* SPDX-FileCopyrightText: Copyright 2022 Move Agency Group B.V., Zwolle, The Netherlands | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
namespace Lunr\Vortex\APNS; | ||
|
||
/** | ||
* Apple Push Notification Service Payload Generator. | ||
* @phpstan-import-type APNSBasePayloadElements from APNSPayload | ||
*/ | ||
class APNSAlertPayload extends APNSPayload | ||
{ | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Destructor. | ||
*/ | ||
public function __destruct() | ||
{ | ||
parent::__destruct(); | ||
} | ||
|
||
/** | ||
* Construct the payload for the push notification. | ||
* | ||
* @return APNSBasePayloadElements APNSPayload elements | ||
*/ | ||
public function get_payload(): array | ||
{ | ||
return parent::get_payload(); | ||
} | ||
|
||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
/** | ||
* This file contains the APNSAlertPayloadGetTest class. | ||
* | ||
* SPDX-FileCopyrightText: Copyright 2024 Move Agency Group B.V., Zwolle, The Netherlands | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
namespace Lunr\Vortex\APNS\Tests; | ||
|
||
/** | ||
* This class contains tests for the getters of the APNSAlertPayload class. | ||
* | ||
* @covers Lunr\Vortex\APNS\APNSAlertPayload | ||
*/ | ||
class APNSAlertPayloadGetTest extends APNSAlertPayloadTest | ||
{ | ||
|
||
/** | ||
* Test get_payload() with alert being present. | ||
* | ||
* @param string $file The path to the payload file | ||
* @param array $data_array The data to compare get_payload against | ||
* | ||
* @dataProvider payloadProvider | ||
* @covers Lunr\Vortex\APNS\APNSAlertPayload::get_payload | ||
*/ | ||
public function testGetPayloadWithAlert(string $file, array $data_array): void | ||
{ | ||
$file = TEST_STATICS . $file; | ||
$elements = $data_array; | ||
|
||
$this->set_reflection_property_value('elements', $elements); | ||
|
||
$result = $this->get_reflection_method('get_payload')->invokeArgs($this->class, []); | ||
|
||
$this->assertJsonStringEqualsJsonFile($file, json_encode($result)); | ||
} | ||
|
||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
/** | ||
* This file contains the APNSPayloadTest class. | ||
* | ||
* SPDX-FileCopyrightText: Copyright 2014 M2mobi B.V., Amsterdam, The Netherlands | ||
* SPDX-FileCopyrightText: Copyright 2022 Move Agency Group B.V., Zwolle, The Netherlands | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
namespace Lunr\Vortex\APNS\Tests; | ||
|
||
use Lunr\Halo\LunrBaseTest; | ||
use Lunr\Vortex\APNS\APNSAlertPayload; | ||
|
||
/** | ||
* This class contains common setup routines, providers | ||
* and shared attributes for testing the APNSPayload class. | ||
* | ||
* @covers Lunr\Vortex\APNS\APNSPayload | ||
*/ | ||
abstract class APNSAlertPayloadTest extends LunrBaseTest | ||
{ | ||
|
||
/** | ||
* Sample payload json | ||
* @var string | ||
*/ | ||
protected string $payload; | ||
|
||
/** | ||
* Instance of the tested class. | ||
* @var APNSAlertPayload | ||
*/ | ||
protected APNSAlertPayload $class; | ||
|
||
/** | ||
* Testcase Constructor. | ||
*/ | ||
public function setUp(): void | ||
{ | ||
$elements_array = [ | ||
'alert' => 'apnsmessage', | ||
'badge' => 10, | ||
'sound' => 'bingbong.wav', | ||
'custom_data' => [ | ||
'key1' => 'value1', | ||
'key2' => 'value2', | ||
], | ||
]; | ||
|
||
$this->payload = json_encode($elements_array); | ||
|
||
$this->class = new APNSAlertPayload(); | ||
|
||
parent::baseSetUp($this->class); | ||
} | ||
|
||
/** | ||
* TestCase Destructor. | ||
*/ | ||
public function tearDown(): void | ||
{ | ||
unset($this->payload); | ||
unset($this->class); | ||
|
||
parent::tearDown(); | ||
} | ||
|
||
/** | ||
* Unit test data provider for payload files. | ||
* | ||
* @return array $values Array of non-object values | ||
*/ | ||
public function payloadProvider(): array | ||
{ | ||
$values = []; | ||
$values[] = [ '/Vortex/apns/alert.json', [ 'alert' => 'apnsmessage' ] ]; | ||
$values[] = [ '/Vortex/apns/custom_data.json', [ 'custom_data' => [ 'key1' => 'value1', 'key2' => 'value2' ] ] ]; | ||
$values[] = [ '/Vortex/apns/badge.json', [ 'badge' => 10 ] ]; | ||
$values[] = [ | ||
'/Vortex/apns/apns.json', | ||
[ | ||
'alert' => 'apnsmessage', | ||
'badge' => 10, | ||
'sound' => 'bingbong.wav', | ||
'custom_data' => [ 'key1' => 'value1', 'key2' => 'value2' ], | ||
], | ||
]; | ||
|
||
return $values; | ||
} | ||
|
||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.