Skip to content

Commit e045c42

Browse files
committed
Removed possibility to use deprecated PushType MPNS - Microsoft Push Notification Service.
Added deprecation warning for old APNS PushType. In case FCM is chosen as PushType type REST query param gets fcm value instead of gcm.
1 parent 3e196c3 commit e045c42

14 files changed

Lines changed: 248 additions & 317 deletions

examples/basic_usage/mobile_push.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
// Define channels to enable push notifications on
2121
$channelsForPush = ["news", "alerts", "promotions"];
2222

23-
// FCM/GCM device token (typically a long string generated by Firebase)
23+
// FCM device token (typically a long string generated by Firebase)
2424
$deviceId = "fcm-device-registration-token-from-firebase";
2525

2626
try {
2727
// Register the device to receive push notifications on the specified channels
2828
$result = $pubnub->addChannelsToPush()
29-
->pushType(PNPushType::FCM) // Use GCM/FCM for Android devices
29+
->pushType(PNPushType::FCM) // Use FCM for Android devices
3030
->channels($channelsForPush)
3131
->deviceId($deviceId)
3232
->sync();

phpstan-baseline.neon

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5740,11 +5740,6 @@ parameters:
57405740
count: 1
57415741
path: tests/functional/push/ListPushProvisionsTest.php
57425742

5743-
-
5744-
message: "#^Method Tests\\\\Functional\\\\Push\\\\ListPushProvisionsTest\\:\\:testListChannelGroupMPNS\\(\\) has no return type specified\\.$#"
5745-
count: 1
5746-
path: tests/functional/push/ListPushProvisionsTest.php
5747-
57485743
-
57495744
message: "#^Method Tests\\\\Functional\\\\Push\\\\RemoveChannelsFromPushExposed\\:\\:buildParams\\(\\) return type has no value type specified in iterable type array\\.$#"
57505745
count: 1
@@ -5780,11 +5775,6 @@ parameters:
57805775
count: 1
57815776
path: tests/functional/push/RemoveDeviceFromPushTest.php
57825777

5783-
-
5784-
message: "#^Method Tests\\\\Functional\\\\Push\\\\RemoveDeviceFromPushTest\\:\\:testRemovePushMPNS\\(\\) has no return type specified\\.$#"
5785-
count: 1
5786-
path: tests/functional/push/RemoveDeviceFromPushTest.php
5787-
57885778
-
57895779
message: "#^Method Tests\\\\Integrational\\\\AddChannelChannelGroupEndpointTest\\:\\:testChannelMissing\\(\\) has no return type specified\\.$#"
57905780
count: 1
@@ -6130,11 +6120,6 @@ parameters:
61306120
count: 1
61316121
path: tests/integrational/ListPushProvisionsTest.php
61326122

6133-
-
6134-
message: "#^Method Tests\\\\Integrational\\\\Push\\\\ListPushProvisionsTest\\:\\:testMicrosoftSuccess\\(\\) has no return type specified\\.$#"
6135-
count: 1
6136-
path: tests/integrational/ListPushProvisionsTest.php
6137-
61386123
-
61396124
message: "#^Method Tests\\\\Integrational\\\\Push\\\\ListPushProvisionsTest\\:\\:testNullDeviceId\\(\\) has no return type specified\\.$#"
61406125
count: 1
@@ -6170,11 +6155,6 @@ parameters:
61706155
count: 1
61716156
path: tests/integrational/ModifyPushChannelsForDeviceTest.php
61726157

6173-
-
6174-
message: "#^Method Tests\\\\Integrational\\\\Push\\\\ModifyPushChannelsForDeviceTest\\:\\:testAddMicrosoftSuccessSync\\(\\) has no return type specified\\.$#"
6175-
count: 1
6176-
path: tests/integrational/ModifyPushChannelsForDeviceTest.php
6177-
61786158
-
61796159
message: "#^Method Tests\\\\Integrational\\\\Push\\\\ModifyPushChannelsForDeviceTest\\:\\:testAppleSuccessRemove\\(\\) has no return type specified\\.$#"
61806160
count: 1
@@ -6240,16 +6220,6 @@ parameters:
62406220
count: 1
62416221
path: tests/integrational/ModifyPushChannelsForDeviceTest.php
62426222

6243-
-
6244-
message: "#^Method Tests\\\\Integrational\\\\Push\\\\ModifyPushChannelsForDeviceTest\\:\\:testMicrosoftSuccessRemove\\(\\) has no return type specified\\.$#"
6245-
count: 1
6246-
path: tests/integrational/ModifyPushChannelsForDeviceTest.php
6247-
6248-
-
6249-
message: "#^Method Tests\\\\Integrational\\\\Push\\\\ModifyPushChannelsForDeviceTest\\:\\:testMicrosoftSuccessRemoveAll\\(\\) has no return type specified\\.$#"
6250-
count: 1
6251-
path: tests/integrational/ModifyPushChannelsForDeviceTest.php
6252-
62536223
-
62546224
message: "#^Method Tests\\\\Integrational\\\\Push\\\\ModifyPushChannelsForDeviceTest\\:\\:testMissingChannels\\(\\) has no return type specified\\.$#"
62556225
count: 1
@@ -7025,11 +6995,6 @@ parameters:
70256995
count: 1
70266996
path: tests/integrational/push/ListPushProvisionsEndpointTest.php
70276997

7028-
-
7029-
message: "#^Method Tests\\\\Integrational\\\\Push\\\\ListPushProvisionsEndpointTest\\:\\:testListChannelGroupMPNS\\(\\) has no return type specified\\.$#"
7030-
count: 1
7031-
path: tests/integrational/push/ListPushProvisionsEndpointTest.php
7032-
70336998
-
70346999
message: "#^Method Tests\\\\Integrational\\\\Push\\\\ListPushProvisionsEndpointTest\\:\\:testWarningWhenUsingDeprecatedGCMType\\(\\) has no return type specified\\.$#"
70357000
count: 1
@@ -7070,11 +7035,6 @@ parameters:
70707035
count: 1
70717036
path: tests/integrational/push/RemoveDeviceFromPushEndpointTest.php
70727037

7073-
-
7074-
message: "#^Method Tests\\\\Integrational\\\\Push\\\\RemoveDeviceFromPushEndpointTest\\:\\:testRemovePushMPNS\\(\\) has no return type specified\\.$#"
7075-
count: 1
7076-
path: tests/integrational/push/RemoveDeviceFromPushEndpointTest.php
7077-
70787038
-
70797039
message: "#^Method Tests\\\\Integrational\\\\Push\\\\RemoveDeviceFromPushEndpointTest\\:\\:testWarningWhenUsingDeprecatedGCMType\\(\\) has no return type specified\\.$#"
70807040
count: 1

src/PubNub/Endpoints/Push/PushEndpoint.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ protected function validatePushType()
6666
trigger_error("GCM is deprecated. Please use FCM instead.", E_USER_DEPRECATED);
6767
}
6868

69+
if ($this->pushType === PNPushType::APNS) {
70+
trigger_error("APNS is deprecated. Please use APNS2 instead.", E_USER_DEPRECATED);
71+
}
72+
6973
if (!in_array($this->pushType, PNPushType::all())) {
7074
throw new PubNubValidationException("Invalid push type");
7175
}
@@ -149,6 +153,6 @@ protected function getName()
149153

150154
protected function getPushType(): string
151155
{
152-
return $this->pushType == PNPushType::FCM ? 'gcm' : $this->pushType;
156+
return $this->pushType == PNPushType::FCM ? 'fcm' : $this->pushType;
153157
}
154158
}

src/PubNub/Enums/PNPushType.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,25 @@
44

55
class PNPushType
66
{
7-
public const APNS = "apns";
7+
88
public const APNS2 = "apns2";
9-
public const MPNS = "mpns";
10-
public const GCM = "gcm";
119
public const FCM = "fcm";
1210

11+
/**
12+
* @deprecated Use APNS2 instead. APNS will be removed in a future version.
13+
*/
14+
public const APNS = "apns";
15+
16+
/**
17+
* @deprecated Use FCM instead. GCM will be removed in a future version.
18+
*/
19+
public const GCM = "gcm";
20+
1321
public static function all()
1422
{
1523
return [
1624
self::APNS,
1725
self::APNS2,
18-
self::MPNS,
1926
self::GCM,
2027
self::FCM
2128
];

tests/functional/push/AddChannelsToPushTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testPushAddMultipleChannels()
4343
$add = new AddChannelsToPushExposed($this->pubnub);
4444

4545
$add->channels(["ch1", "ch2"])
46-
->pushType(PNPushType::MPNS)
46+
->pushType(PNPushType::FCM)
4747
->deviceId("coolDevice");
4848

4949
$this->assertEquals(sprintf(
@@ -55,7 +55,7 @@ public function testPushAddMultipleChannels()
5555
$this->assertEquals([
5656
"pnsdk" => PubNubUtil::urlEncode(PubNub::getSdkFullName()),
5757
"uuid" => $this->pubnub->getConfiguration()->getUuid(),
58-
"type" => "mpns",
58+
"type" => "fcm",
5959
"add" => "ch1,ch2"
6060
], $add->buildParams());
6161

@@ -110,7 +110,7 @@ public function testPushAddFCM()
110110
$this->assertEquals([
111111
"pnsdk" => PubNubUtil::urlEncode(PubNub::getSdkFullName()),
112112
"uuid" => $this->pubnub->getConfiguration()->getUuid(),
113-
"type" => "gcm",
113+
"type" => "fcm",
114114
"add" => "ch1,ch2,ch3"
115115
], $add->buildParams());
116116

tests/functional/push/ListPushProvisionsTest.php

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -75,29 +75,7 @@ public function testListChannelGroupFCM()
7575
$this->assertEquals([
7676
"pnsdk" => PubNubUtil::urlEncode(PubNub::getSdkFullName()),
7777
"uuid" => $this->pubnub->getConfiguration()->getUuid(),
78-
"type" => "gcm"
79-
], $list->buildParams());
80-
}
81-
82-
public function testListChannelGroupMPNS()
83-
{
84-
$this->pubnub->getConfiguration()->setUuid("sampleUUID");
85-
86-
$list = new ListPushProvisionsExposed($this->pubnub);
87-
88-
$list->pushType(PNPushType::MPNS)
89-
->deviceId("coolDevice");
90-
91-
$this->assertEquals(sprintf(
92-
ListPushProvisions::PATH,
93-
$this->pubnub->getConfiguration()->getSubscribeKey(),
94-
"coolDevice"
95-
), $list->buildPath());
96-
97-
$this->assertEquals([
98-
"pnsdk" => PubNubUtil::urlEncode(PubNub::getSdkFullName()),
99-
"uuid" => $this->pubnub->getConfiguration()->getUuid(),
100-
"type" => "mpns"
78+
"type" => "fcm"
10179
], $list->buildParams());
10280
}
10381
}

tests/functional/push/RemoveChannelsFromPushTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function testPushRemoveMultipleChannels()
4141
$remove = new RemoveChannelsFromPushExposed($this->pubnub);
4242

4343
$remove->channels(['ch1', 'ch2'])
44-
->pushType(PNPushType::MPNS)
44+
->pushType(PNPushType::FCM)
4545
->deviceId('coolDevice');
4646

4747
$this->assertEquals(sprintf(
@@ -53,7 +53,7 @@ public function testPushRemoveMultipleChannels()
5353
$this->assertEquals([
5454
"pnsdk" => PubNubUtil::urlEncode(PubNub::getSdkFullName()),
5555
"uuid" => $this->pubnub->getConfiguration()->getUuid(),
56-
"type" => "mpns",
56+
"type" => "fcm",
5757
"remove" => "ch1,ch2"
5858
], $remove->buildParams());
5959
}
@@ -77,7 +77,7 @@ public function testPushRemoveFCM()
7777
$this->assertEquals([
7878
"pnsdk" => PubNubUtil::urlEncode(PubNub::getSdkFullName()),
7979
"uuid" => $this->pubnub->getConfiguration()->getUuid(),
80-
"type" => "gcm",
80+
"type" => "fcm",
8181
"remove" => "ch1,ch2,ch3"
8282
], $remove->buildParams());
8383
}

tests/functional/push/RemoveDeviceFromPushTest.php

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,6 @@ public function testRemovePushAPNS()
3232
], $remove->buildParams());
3333
}
3434

35-
public function testRemovePushMPNS()
36-
{
37-
$this->pubnub->getConfiguration()->setUuid("sampleUUID");
38-
39-
$remove = new RemoveDeviceFromPushExposed($this->pubnub);
40-
41-
$remove->pushType(PNPushType::MPNS)
42-
->deviceId('coolDevice');
43-
44-
$this->assertEquals(sprintf(
45-
RemoveDeviceFromPush::PATH,
46-
$this->pubnub->getConfiguration()->getSubscribeKey(),
47-
"coolDevice"
48-
), $remove->buildPath());
49-
50-
$this->assertEquals([
51-
"pnsdk" => PubNubUtil::urlEncode(PubNub::getSdkFullName()),
52-
"uuid" => $this->pubnub->getConfiguration()->getUuid(),
53-
"type" => "mpns",
54-
], $remove->buildParams());
55-
}
56-
5735
public function testRemovePushFCM()
5836
{
5937
$this->pubnub->getConfiguration()->setUuid("sampleUUID");
@@ -72,7 +50,7 @@ public function testRemovePushFCM()
7250
$this->assertEquals([
7351
"pnsdk" => PubNubUtil::urlEncode(PubNub::getSdkFullName()),
7452
"uuid" => $this->pubnub->getConfiguration()->getUuid(),
75-
"type" => "gcm",
53+
"type" => "fcm",
7654
], $remove->buildParams());
7755
}
7856
}

tests/integrational/ListPushProvisionsTest.php

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testFCMSuccess()
3636

3737
$list->stubFor("/v1/push/sub-key/demo/devices/coolDevice")
3838
->withQuery([
39-
"type" => "gcm",
39+
"type" => "fcm",
4040
"pnsdk" => $this->encodedSdkName,
4141
"uuid" => $this->pubnub_demo->getConfiguration()->getUuid(),
4242
])
@@ -49,25 +49,6 @@ public function testFCMSuccess()
4949
$this->assertInstanceOf(\PubNub\Models\Consumer\Push\PNPushListProvisionsResult::class, $response);
5050
}
5151

52-
public function testMicrosoftSuccess()
53-
{
54-
$list = new ListPushProvisionsExposed($this->pubnub_demo);
55-
56-
$list->stubFor("/v1/push/sub-key/demo/devices/coolDevice")
57-
->withQuery([
58-
"type" => "mpns",
59-
"pnsdk" => $this->encodedSdkName,
60-
"uuid" => $this->pubnub_demo->getConfiguration()->getUuid(),
61-
])
62-
->setResponseBody("[\"ch1\", \"ch2\", \"ch3\"]");
63-
64-
$response = $response = $list->deviceId("coolDevice")
65-
->pushType(PNPushType::MPNS)
66-
->sync();
67-
68-
$this->assertInstanceOf(\PubNub\Models\Consumer\Push\PNPushListProvisionsResult::class, $response);
69-
}
70-
7152
public function testIsAuthRequiredSuccess()
7253
{
7354
$config = $this->config->clone();
@@ -79,17 +60,19 @@ public function testIsAuthRequiredSuccess()
7960
$pubnub = new PubNub($config);
8061
$list = new ListPushProvisionsExposed($pubnub);
8162

82-
$list->stubFor("/v1/push/sub-key/demo/devices/coolDevice")
63+
$list->stubFor("/v2/push/sub-key/demo/devices-apns2/coolDevice")
8364
->withQuery([
84-
"type" => "mpns",
65+
"topic" => "coolTopic",
66+
"environment" => "development",
8567
"pnsdk" => $this->encodedSdkName,
8668
"uuid" => $this->pubnub_demo->getConfiguration()->getUuid(),
8769
"auth" => "myKey",
8870
])
8971
->setResponseBody("[\"ch1\", \"ch2\", \"ch3\"]");
9072

9173
$response = $list->deviceId("coolDevice")
92-
->pushType(PNPushType::MPNS)
74+
->pushType(PNPushType::APNS2)
75+
->topic( "coolTopic")
9376
->sync();
9477

9578
$this->assertInstanceOf(\PubNub\Models\Consumer\Push\PNPushListProvisionsResult::class, $response);
@@ -104,7 +87,7 @@ public function testNullSubscribeKey()
10487
$list = new ListPushProvisionsExposed($pubnub);
10588

10689
$list->deviceId("coolDevice")
107-
->pushType(PNPushType::MPNS)
90+
->pushType(PNPushType::FCM)
10891
->sync();
10992
}
11093

@@ -119,7 +102,7 @@ public function testEmptySubscribeKey()
119102
$list = new ListPushProvisionsExposed($pubnub);
120103

121104
$list->deviceId("coolDevice")
122-
->pushType(PNPushType::MPNS)
105+
->pushType(PNPushType::FCM)
123106
->sync();
124107
}
125108

@@ -141,7 +124,7 @@ public function testNullDeviceId()
141124

142125
$list = new ListPushProvisionsExposed($this->pubnub_demo);
143126

144-
$list->pushType(PNPushType::MPNS)
127+
$list->pushType(PNPushType::FCM)
145128
->sync();
146129
}
147130

@@ -153,7 +136,7 @@ public function testEmptyDeviceIdRemoveAll()
153136
$list = new ListPushProvisionsExposed($this->pubnub_demo);
154137

155138
$list->deviceId("")
156-
->pushType(PNPushType::MPNS)
139+
->pushType(PNPushType::APNS2)
157140
->sync();
158141
}
159142
}

0 commit comments

Comments
 (0)