From 20de5d86bd2c5c7669f980238d3302a351e8a7d1 Mon Sep 17 00:00:00 2001 From: Sebastian Molenda Date: Tue, 11 Jun 2024 12:46:23 +0200 Subject: [PATCH] GCM to FCM migration (#100) * GCM to FCM migration * Add checking if using GCM throws E_DEPRECATION_WARNING * Improve readability and fix error messages * PubNub SDK v6.2.0 release. --------- Co-authored-by: PubNub Release Bot <120067856+pubnub-release-bot@users.noreply.github.com> --- .pubnub.yml | 11 +- CHANGELOG.md | 6 + README.md | 2 +- composer.json | 2 +- .../Endpoints/Push/AddChannelsToPush.php | 136 ++-------------- .../Endpoints/Push/ListPushProvisions.php | 137 +--------------- src/PubNub/Endpoints/Push/PushEndpoint.php | 149 +++++++++++++++++ .../Endpoints/Push/RemoveChannelsFromPush.php | 152 ++---------------- .../Endpoints/Push/RemoveDeviceFromPush.php | 134 +-------------- src/PubNub/Enums/PNPushType.php | 23 ++- src/PubNub/PubNub.php | 2 +- .../functional/push/AddChannelsToPushTest.php | 9 +- .../push/ListPushProvisionsTest.php | 11 +- .../push/RemoveChannelsFromPushTest.php | 10 +- .../push/RemoveDeviceFromPushTest.php | 10 +- .../integrational/ListPushProvisionsTest.php | 11 +- .../ModifyPushChannelsForDeviceTest.php | 29 ++-- .../push/AddChannelsToPushEndpointTest.php | 37 ++++- .../push/ListPushProvisionsEndpointTest.php | 42 ++++- .../RemoveChannelsFromPushEndpointTest.php | 10 +- .../push/RemoveDeviceFromPushEndpointTest.php | 33 +++- 21 files changed, 362 insertions(+), 594 deletions(-) create mode 100644 src/PubNub/Endpoints/Push/PushEndpoint.php diff --git a/.pubnub.yml b/.pubnub.yml index 95b33428..ec4e6bf8 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,8 +1,13 @@ name: php -version: 6.1.3 +version: 6.2.0 schema: 1 scm: github.com/pubnub/php changelog: + - date: 2024-06-11 + version: v6.2.0 + changes: + - type: feature + text: "Replacing GCM with FCM. This is not a breaking change, but using GCM will result in throwing `E_USER_DEPRECATED` warning." - date: 2023-11-27 version: v6.1.3 changes: @@ -407,8 +412,8 @@ sdks: - x86-64 - distribution-type: library distribution-repository: GitHub release - package-name: php-6.1.3.zip - location: https://github.com/pubnub/php/releases/tag/v6.1.3 + package-name: php-6.2.0.zip + location: https://github.com/pubnub/php/releases/tag/v6.2.0 requires: - name: rmccue/requests min-version: 1.0.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index c13e6f2c..f53424c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v6.2.0 +June 11 2024 + +#### Added +- Replacing GCM with FCM. This is not a breaking change, but using GCM will result in throwing `E_USER_DEPRECATED` warning. + ## v6.1.3 November 27 2023 diff --git a/README.md b/README.md index 68653627..1bdcdaf6 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ You will need the publish and subscribe keys to authenticate your app. Get your { "require": { - "pubnub/pubnub": "6.1.3" + "pubnub/pubnub": "6.2.0" } } ``` diff --git a/composer.json b/composer.json index c08bf34f..87f1ff5a 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "keywords": ["api", "real-time", "realtime", "real time", "ajax", "push"], "homepage": "http://www.pubnub.com/", "license": "proprietary", - "version": "6.1.3", + "version": "6.2.0", "authors": [ { "name": "PubNub", diff --git a/src/PubNub/Endpoints/Push/AddChannelsToPush.php b/src/PubNub/Endpoints/Push/AddChannelsToPush.php index e3cadfd8..de62a564 100644 --- a/src/PubNub/Endpoints/Push/AddChannelsToPush.php +++ b/src/PubNub/Endpoints/Push/AddChannelsToPush.php @@ -2,110 +2,40 @@ namespace PubNub\Endpoints\Push; -use PubNub\Endpoints\Endpoint; -use PubNub\Enums\PNHttpMethod; use PubNub\Enums\PNOperationType; use PubNub\Enums\PNPushType; use PubNub\Exceptions\PubNubValidationException; use PubNub\Models\Consumer\Push\PNPushAddChannelResult; use PubNub\PubNubUtil; - -class AddChannelsToPush extends Endpoint +class AddChannelsToPush extends PushEndpoint { - const PATH = "/v1/push/sub-key/%s/devices/%s"; - - const PATH_APNS2 = "/v2/push/sub-key/%s/devices-apns2/%s"; + protected const OPERATION_TYPE = PNOperationType::PNAddPushNotificationsOnChannelsOperation; + protected const OPERATION_NAME = "AddChannelsToPush"; + public const PATH = "/v1/push/sub-key/%s/devices/%s"; + public const PATH_APNS2 = "/v2/push/sub-key/%s/devices-apns2/%s"; /** @var string[]|string */ - protected $channels = []; - - /** @var string */ - protected $deviceId; - - /** @var int */ - protected $pushType; - - /** @var string */ - protected $environment; - - /** @var string */ - protected $topic; + protected string | array $channels = []; /** * @param string[]|string $channels * @return $this */ - public function channels($channels) + public function channels(string | array $channels) { $this->channels = PubNubUtil::extendArray($this->channels, $channels); return $this; } - /** - * @param string $deviceId - * @return $this - */ - public function deviceId($deviceId) - { - $this->deviceId = $deviceId; - - return $this; - } - - /** - * @param int $pushType - * @return $this - */ - public function pushType($pushType) - { - $this->pushType = $pushType; - - return $this; - } - - /** - * @param int $environment - * @return $this - */ - public function environment($environment) - { - $this->environment = $environment; - - return $this; - } - - /** - * @param int $pushType - * @return $this - */ - public function topic($topic) - { - $this->topic = $topic; - - return $this; - } - protected function validateParams() { - $this->validateSubscribeKey(); + parent::validateParams(); if (!is_array($this->channels) || count($this->channels) === 0) { throw new PubNubValidationException("Channel missing"); } - - if (!is_string($this->deviceId) || strlen($this->deviceId) === 0) { - throw new PubNubValidationException("Device ID is missing for push operation"); - } - - if ($this->pushType === null || strlen($this->pushType) === 0) { - throw new PubNubValidationException("Push Type is missing"); - } - - if (($this->pushType == PNPushType::APNS2) && (!is_string($this->topic) || strlen($this->topic) === 0)) { - throw new PubNubValidationException("APNS2 topic is missing"); - } } /** @@ -164,52 +94,4 @@ protected function createResponse($json) { return new PNPushAddChannelResult(); } - - /** - * @return bool - */ - protected function isAuthRequired() - { - return true; - } - - /** - * @return int - */ - protected function getRequestTimeout() - { - return $this->pubnub->getConfiguration()->getNonSubscribeRequestTimeout(); - } - - /** - * @return int - */ - protected function getConnectTimeout() - { - return $this->pubnub->getConfiguration()->getConnectTimeout(); - } - - /** - * @return string PNHttpMethod - */ - protected function httpMethod() - { - return PNHttpMethod::GET; - } - - /** - * @return int - */ - protected function getOperationType() - { - return PNOperationType::PNAddPushNotificationsOnChannelsOperation; - } - - /** - * @return string - */ - protected function getName() - { - return "AddChannelsToPush"; - } -} \ No newline at end of file +} diff --git a/src/PubNub/Endpoints/Push/ListPushProvisions.php b/src/PubNub/Endpoints/Push/ListPushProvisions.php index dbdae96c..33a7209e 100644 --- a/src/PubNub/Endpoints/Push/ListPushProvisions.php +++ b/src/PubNub/Endpoints/Push/ListPushProvisions.php @@ -2,95 +2,18 @@ namespace PubNub\Endpoints\Push; -use PubNub\Endpoints\Endpoint; use PubNub\Enums\PNHttpMethod; use PubNub\Enums\PNOperationType; use PubNub\Enums\PNPushType; use PubNub\Exceptions\PubNubValidationException; use PubNub\Models\Consumer\Push\PNPushListProvisionsResult; - -class ListPushProvisions extends Endpoint +class ListPushProvisions extends PushEndpoint { - const PATH = "/v1/push/sub-key/%s/devices/%s"; - - const PATH_APNS2 = "/v2/push/sub-key/%s/devices-apns2/%s"; - - /** @var string */ - protected $deviceId; - - /** @var int */ - protected $pushType; - - /** @var string */ - protected $environment; - - /** @var string */ - protected $topic; - - /** - * @param string $deviceId - * @return $this - */ - public function deviceId($deviceId) - { - $this->deviceId = $deviceId; - - return $this; - } - - /** - * @param int $pushType - * @return $this - */ - public function pushType($pushType) - { - $this->pushType = $pushType; - - return $this; - } - - /** - * @param int $environment - * @return $this - */ - public function environment($environment) - { - $this->environment = $environment; - - return $this; - } - - /** - * @param int $pushType - * @return $this - */ - public function topic($topic) - { - $this->topic = $topic; - - return $this; - } - - /** - * @throws PubNubValidationException - */ - protected function validateParams() - { - $this->validateSubscribeKey(); - - if (!is_string($this->deviceId) || strlen($this->deviceId) === 0) { - throw new PubNubValidationException("Device ID is missing for push operation"); - } - - if ($this->pushType === null || strlen($this->pushType) === 0) { - throw new PubNubValidationException("Push Type is missing"); - } - - if (($this->pushType == PNPushType::APNS2) && (!is_string($this->topic) || strlen($this->topic) === 0)) { - throw new PubNubValidationException("APNS2 topic is missing"); - } - } + protected const OPERATION_TYPE = PNOperationType::PNPushNotificationEnabledChannelsOperation; + protected const OPERATION_NAME = "ListPushProvisions"; + public const PATH = "/v1/push/sub-key/%s/devices/%s"; + public const PATH_APNS2 = "/v2/push/sub-key/%s/devices-apns2/%s"; /** * @return array @@ -150,52 +73,4 @@ protected function createResponse($json) return new PNPushListProvisionsResult([]); } } - - /** - * @return bool - */ - protected function isAuthRequired() - { - return true; - } - - /** - * @return int - */ - protected function getRequestTimeout() - { - return $this->pubnub->getConfiguration()->getNonSubscribeRequestTimeout(); - } - - /** - * @return int - */ - protected function getConnectTimeout() - { - return $this->pubnub->getConfiguration()->getConnectTimeout(); - } - - /** - * @return string PNHttpMethod - */ - protected function httpMethod() - { - return PNHttpMethod::GET; - } - - /** - * @return int - */ - protected function getOperationType() - { - return PNOperationType::PNPushNotificationEnabledChannelsOperation; - } - - /** - * @return string - */ - protected function getName() - { - return "ListPushProvisions"; - } -} \ No newline at end of file +} diff --git a/src/PubNub/Endpoints/Push/PushEndpoint.php b/src/PubNub/Endpoints/Push/PushEndpoint.php new file mode 100644 index 00000000..44aa85cf --- /dev/null +++ b/src/PubNub/Endpoints/Push/PushEndpoint.php @@ -0,0 +1,149 @@ +deviceId = $deviceId; + return $this; + } + + /** + * @param string $environment + * @return $this + */ + public function environment(string $environment): static + { + $this->environment = $environment; + return $this; + } + + /** + * @param string $topic + * @return $this + */ + public function topic(string $topic): static + { + $this->topic = $topic; + return $this; + } + + /** + * @param string $pushType + * @return $this + */ + public function pushType(string $pushType): static + { + $this->pushType = $pushType; + return $this; + } + + protected function validatePushType() + { + if (!isset($this->pushType) || empty($this->pushType)) { + throw new PubNubValidationException("Push Type is missing"); + } + + if ($this->pushType === PNPushType::GCM) { + trigger_error("GCM is deprecated. Please use FCM instead.", E_USER_DEPRECATED); + } + + if (!in_array($this->pushType, PNPushType::all())) { + throw new PubNubValidationException("Invalid push type"); + } + } + + /** + * @throws PubNubValidationException + */ + protected function validateDeviceId() + { + if (!isset($this->deviceId) || empty($this->deviceId)) { + throw new PubNubValidationException("Device ID is missing for push operation"); + } + } + + protected function validateTopic() + { + if (($this->pushType == PNPushType::APNS2) && (!isset($this->topic) || empty($this->topic))) { + throw new PubNubValidationException("APNS2 topic is missing"); + } + } + + /** + * @throws PubNubValidationException + */ + protected function validateParams() + { + $this->validateSubscribeKey(); + $this->validateDeviceId(); + $this->validatePushType(); + $this->validateTopic(); + } + + /** + * @return bool + */ + protected function isAuthRequired() + { + return true; + } + + /** + * @return int + */ + protected function getRequestTimeout() + { + return $this->pubnub->getConfiguration()->getNonSubscribeRequestTimeout(); + } + + /** + * @return int + */ + protected function getConnectTimeout() + { + return $this->pubnub->getConfiguration()->getConnectTimeout(); + } + + /** + * @return string PNHttpMethod + */ + protected function httpMethod() + { + return PNHttpMethod::GET; + } + + /** + * @return int + */ + protected function getOperationType() + { + return static::OPERATION_TYPE; + } + + /** + * @return string + */ + protected function getName() + { + return static::OPERATION_NAME; + } +} diff --git a/src/PubNub/Endpoints/Push/RemoveChannelsFromPush.php b/src/PubNub/Endpoints/Push/RemoveChannelsFromPush.php index 3ff0e03e..0a793592 100644 --- a/src/PubNub/Endpoints/Push/RemoveChannelsFromPush.php +++ b/src/PubNub/Endpoints/Push/RemoveChannelsFromPush.php @@ -2,88 +2,29 @@ namespace PubNub\Endpoints\Push; -use PubNub\Endpoints\Endpoint; -use PubNub\Enums\PNHttpMethod; use PubNub\Enums\PNOperationType; use PubNub\Enums\PNPushType; use PubNub\Exceptions\PubNubValidationException; use PubNub\Models\Consumer\Push\PNPushRemoveChannelResult; use PubNub\PubNubUtil; - -class RemoveChannelsFromPush extends Endpoint +class RemoveChannelsFromPush extends PushEndpoint { - const PATH = "/v1/push/sub-key/%s/devices/%s"; - - const PATH_APNS2 = "/v2/push/sub-key/%s/devices-apns2/%s"; - - /** @var string[] */ - protected $channels = []; - - /** @var string */ - protected $deviceId; - - /** @var string */ - protected $pushType; + protected const OPERATION_TYPE = PNOperationType::PNRemovePushNotificationsFromChannelsOperation; + protected const OPERATION_NAME = "RemoveChannelsFromPush"; + public const PATH = "/v1/push/sub-key/%s/devices/%s"; + public const PATH_APNS2 = "/v2/push/sub-key/%s/devices-apns2/%s"; - /** @var string */ - protected $environment; - - /** @var string */ - protected $topic; + /** @var string | string[] */ + protected string | array $channels = []; /** * @param string|string[] $channels * @return $this */ - public function channels($channels) + public function channels(string | array $channels): static { $this->channels = PubNubUtil::extendArray($this->channels, $channels); - - return $this; - } - - /** - * @param string $deviceId - * @return $this - */ - public function deviceId($deviceId) - { - $this->deviceId = $deviceId; - - return $this; - } - - /** - * @param int $pushType - * @return $this - */ - public function pushType($pushType) - { - $this->pushType = $pushType; - - return $this; - } - - /** - * @param int $environment - * @return $this - */ - public function environment($environment) - { - $this->environment = $environment; - - return $this; - } - - /** - * @param int $pushType - * @return $this - */ - public function topic($topic) - { - $this->topic = $topic; - return $this; } @@ -93,22 +34,17 @@ public function topic($topic) protected function validateParams() { $this->validateSubscribeKey(); + $this->validateChannel(); + $this->validateDeviceId(); + $this->validatePushType(); + $this->validateTopic(); + } + protected function validateChannel() + { if (!is_array($this->channels) || count($this->channels) === 0) { throw new PubNubValidationException("Channel missing"); } - - if (!is_string($this->deviceId) || strlen($this->deviceId) === 0) { - throw new PubNubValidationException("Device ID is missing for push operation"); - } - - if ($this->pushType === null || strlen($this->pushType) === 0) { - throw new PubNubValidationException("Push Type is missing"); - } - - if (($this->pushType == PNPushType::APNS2) && (!is_string($this->topic) || strlen($this->topic) === 0)) { - throw new PubNubValidationException("APNS2 topic is missing"); - } } /** @@ -126,14 +62,8 @@ protected function customParams() } else { // apns2 push -> add topic and environment $params['topic'] = $this->topic; - - if (is_string($this->environment) && strlen($this->environment) > 0) { - $params['environment'] = $this->environment; - } else { - $params['environment'] = 'development'; - } + $params['environment'] = $this->environment ?? 'development'; } - return $params; } @@ -150,7 +80,7 @@ protected function buildData() */ protected function buildPath() { - $path = $this->pushType == PNPushType::APNS2 ? RemoveChannelsFromPush::PATH_APNS2 : RemoveChannelsFromPush::PATH; + $path = $this->pushType == PNPushType::APNS2 ? static::PATH_APNS2 : static::PATH; return sprintf( $path, @@ -167,52 +97,4 @@ protected function createResponse($json) { return new PNPushRemoveChannelResult(); } - - /** - * @return bool - */ - protected function isAuthRequired() - { - return true; - } - - /** - * @return int - */ - protected function getRequestTimeout() - { - return $this->pubnub->getConfiguration()->getNonSubscribeRequestTimeout(); - } - - /** - * @return int - */ - protected function getConnectTimeout() - { - return $this->pubnub->getConfiguration()->getConnectTimeout(); - } - - /** - * @return string PNHttpMethod - */ - protected function httpMethod() - { - return PNHttpMethod::GET; - } - - /** - * @return int - */ - protected function getOperationType() - { - return PNOperationType::PNRemovePushNotificationsFromChannelsOperation; - } - - /** - * @return string - */ - protected function getName() - { - return "RemoveChannelsFromPush"; - } } diff --git a/src/PubNub/Endpoints/Push/RemoveDeviceFromPush.php b/src/PubNub/Endpoints/Push/RemoveDeviceFromPush.php index e74f6534..1d841f52 100644 --- a/src/PubNub/Endpoints/Push/RemoveDeviceFromPush.php +++ b/src/PubNub/Endpoints/Push/RemoveDeviceFromPush.php @@ -9,88 +9,12 @@ use PubNub\Exceptions\PubNubValidationException; use PubNub\Models\Consumer\Push\PNPushRemoveAllChannelsResult; - -class RemoveDeviceFromPush extends Endpoint +class RemoveDeviceFromPush extends PushEndpoint { - const PATH = "/v1/push/sub-key/%s/devices/%s/remove"; - - const PATH_APNS2 = "/v2/push/sub-key/%s/devices-apns2/%s/remove"; - - /** @var string */ - protected $deviceId; - - /** @var string */ - protected $pushType; - - /** @var string */ - protected $environment; - - /** @var string */ - protected $topic; - - /** - * @param string $deviceId - * @return $this - */ - public function deviceId($deviceId) - { - $this->deviceId = $deviceId; - - return $this; - } - - /** - * @param int $pushType - * @return $this - */ - public function pushType($pushType) - { - $this->pushType = $pushType; - - return $this; - } - - /** - * @param int $environment - * @return $this - */ - public function environment($environment) - { - $this->environment = $environment; - - return $this; - } - - /** - * @param int $pushType - * @return $this - */ - public function topic($topic) - { - $this->topic = $topic; - - return $this; - } - - /** - * @throws PubNubValidationException - */ - protected function validateParams() - { - $this->validateSubscribeKey(); - - if (!is_string($this->deviceId) || strlen($this->deviceId) === 0) { - throw new PubNubValidationException("Device ID is missing for push operation"); - } - - if ($this->pushType === null || strlen($this->pushType) === 0) { - throw new PubNubValidationException("Push Type is missing"); - } - - if (($this->pushType == PNPushType::APNS2) && (!is_string($this->topic) || strlen($this->topic) === 0)) { - throw new PubNubValidationException("APNS2 topic is missing"); - } - } + protected const OPERATION_TYPE = PNOperationType::PNRemoveAllPushNotificationsOperation; + protected const OPERATION_NAME = "RemoveDeviceFromPush"; + public const PATH = "/v1/push/sub-key/%s/devices/%s/remove"; + public const PATH_APNS2 = "/v2/push/sub-key/%s/devices-apns2/%s/remove"; /** * @return array @@ -146,52 +70,4 @@ protected function createResponse($json) { return new PNPushRemoveAllChannelsResult(); } - - /** - * @return bool - */ - protected function isAuthRequired() - { - return true; - } - - /** - * @return int - */ - protected function getRequestTimeout() - { - return $this->pubnub->getConfiguration()->getNonSubscribeRequestTimeout(); - } - - /** - * @return int - */ - protected function getConnectTimeout() - { - return $this->pubnub->getConfiguration()->getConnectTimeout(); - } - - /** - * @return string PNHttpMethod - */ - protected function httpMethod() - { - return PNHttpMethod::GET; - } - - /** - * @return int - */ - protected function getOperationType() - { - return PNOperationType::PNRemoveAllPushNotificationsOperation; - } - - /** - * @return string - */ - protected function getName() - { - return "RemoveDeviceFromPush"; - } } diff --git a/src/PubNub/Enums/PNPushType.php b/src/PubNub/Enums/PNPushType.php index be0450ad..ee981c81 100644 --- a/src/PubNub/Enums/PNPushType.php +++ b/src/PubNub/Enums/PNPushType.php @@ -2,11 +2,22 @@ namespace PubNub\Enums; - class PNPushType { - const APNS = "apns"; - const APNS2 = "apns2"; - const MPNS = "mpns"; - const GCM = "gcm"; -} \ No newline at end of file + public const APNS = "apns"; + public const APNS2 = "apns2"; + public const MPNS = "mpns"; + public const GCM = "gcm"; + public const FCM = "fcm"; + + public static function all() + { + return [ + self::APNS, + self::APNS2, + self::MPNS, + self::GCM, + self::FCM + ]; + } +} diff --git a/src/PubNub/PubNub.php b/src/PubNub/PubNub.php index 4b9ff632..ca38f6a0 100644 --- a/src/PubNub/PubNub.php +++ b/src/PubNub/PubNub.php @@ -55,7 +55,7 @@ class PubNub implements LoggerAwareInterface { - protected const SDK_VERSION = "6.1.3"; + protected const SDK_VERSION = "6.2.0"; protected const SDK_NAME = "PubNub-PHP"; public static $MAX_SEQUENCE = 65535; diff --git a/tests/functional/push/AddChannelsToPushTest.php b/tests/functional/push/AddChannelsToPushTest.php index d05c39e0..fe2669c5 100644 --- a/tests/functional/push/AddChannelsToPushTest.php +++ b/tests/functional/push/AddChannelsToPushTest.php @@ -8,7 +8,6 @@ use PubNub\PubNubUtil; use PubNubTestCase; - class AddChannelsToPushTest extends PubNubTestCase { public function testPushAddSingleChannel() @@ -92,14 +91,14 @@ public function testPushAddApns2() $this->assertEquals(["ch1","ch2"], $add->getChannels()); } - public function testPushAddGoogle() + public function testPushAddFCM() { $this->pubnub->getConfiguration()->setUuid("sampleUUID"); $add = new AddChannelsToPushExposed($this->pubnub); $add->channels(["ch1", "ch2", "ch3"]) - ->pushType(PNPushType::GCM) + ->pushType(PNPushType::FCM) ->deviceId("coolDevice"); $this->assertEquals(sprintf( @@ -111,7 +110,7 @@ public function testPushAddGoogle() $this->assertEquals([ "pnsdk" => PubNubUtil::urlEncode(PubNub::getSdkFullName()), "uuid" => $this->pubnub->getConfiguration()->getUuid(), - "type" => "gcm", + "type" => "fcm", "add" => "ch1,ch2,ch3" ], $add->buildParams()); @@ -119,7 +118,7 @@ public function testPushAddGoogle() } } - +// phpcs:ignore PSR1.Classes.ClassDeclaration class AddChannelsToPushExposed extends AddChannelsToPush { public function buildParams() diff --git a/tests/functional/push/ListPushProvisionsTest.php b/tests/functional/push/ListPushProvisionsTest.php index 0133a331..d42f15a7 100644 --- a/tests/functional/push/ListPushProvisionsTest.php +++ b/tests/functional/push/ListPushProvisionsTest.php @@ -9,7 +9,6 @@ use PubNubTestCase; use Tests\Helpers\StubTransport; - class ListPushProvisionsTest extends PubNubTestCase { public function testListChannelGroupAPNS() @@ -59,13 +58,13 @@ public function testListChannelGroupAPNS2() ], $list->buildParams()); } - public function testListChannelGroupGCM() + public function testListChannelGroupFCM() { $this->pubnub->getConfiguration()->setUuid("sampleUUID"); $list = new ListPushProvisionsExposed($this->pubnub); - $list->pushType(PNPushType::GCM) + $list->pushType(PNPushType::FCM) ->deviceId("coolDevice"); $this->assertEquals(sprintf( @@ -77,7 +76,7 @@ public function testListChannelGroupGCM() $this->assertEquals([ "pnsdk" => PubNubUtil::urlEncode(PubNub::getSdkFullName()), "uuid" => $this->pubnub->getConfiguration()->getUuid(), - "type" => "gcm" + "type" => "fcm" ], $list->buildParams()); } @@ -104,7 +103,7 @@ public function testListChannelGroupMPNS() } } - +// phpcs:ignore PSR1.Classes.ClassDeclaration class ListPushProvisionsExposed extends ListPushProvisions { protected $transport; @@ -137,4 +136,4 @@ public function requestOptions() 'transport' => $this->transport ]; } -} \ No newline at end of file +} diff --git a/tests/functional/push/RemoveChannelsFromPushTest.php b/tests/functional/push/RemoveChannelsFromPushTest.php index 778278a7..486ef96d 100644 --- a/tests/functional/push/RemoveChannelsFromPushTest.php +++ b/tests/functional/push/RemoveChannelsFromPushTest.php @@ -58,14 +58,14 @@ public function testPushRemoveMultipleChannels() ], $remove->buildParams()); } - public function testPushRemoveGoogle() + public function testPushRemoveFCM() { $this->pubnub->getConfiguration()->setUuid("sampleUUID"); $remove = new RemoveChannelsFromPushExposed($this->pubnub); $remove->channels(['ch1', 'ch2', 'ch3']) - ->pushType(PNPushType::GCM) + ->pushType(PNPushType::FCM) ->deviceId('coolDevice'); $this->assertEquals(sprintf( @@ -77,13 +77,13 @@ public function testPushRemoveGoogle() $this->assertEquals([ "pnsdk" => PubNubUtil::urlEncode(PubNub::getSdkFullName()), "uuid" => $this->pubnub->getConfiguration()->getUuid(), - "type" => "gcm", + "type" => "fcm", "remove" => "ch1,ch2,ch3" ], $remove->buildParams()); } } - +// phpcs:ignore PSR1.Classes.ClassDeclaration class RemoveChannelsFromPushExposed extends RemoveChannelsFromPush { public function buildParams() @@ -95,4 +95,4 @@ public function buildPath() { return parent::buildPath(); } -} \ No newline at end of file +} diff --git a/tests/functional/push/RemoveDeviceFromPushTest.php b/tests/functional/push/RemoveDeviceFromPushTest.php index bdc0ed0b..a95938df 100644 --- a/tests/functional/push/RemoveDeviceFromPushTest.php +++ b/tests/functional/push/RemoveDeviceFromPushTest.php @@ -54,13 +54,13 @@ public function testRemovePushMPNS() ], $remove->buildParams()); } - public function testRemovePushGCM() + public function testRemovePushFCM() { $this->pubnub->getConfiguration()->setUuid("sampleUUID"); $remove = new RemoveDeviceFromPushExposed($this->pubnub); - $remove->pushType(PNPushType::GCM) + $remove->pushType(PNPushType::FCM) ->deviceId('coolDevice'); $this->assertEquals(sprintf( @@ -72,12 +72,12 @@ public function testRemovePushGCM() $this->assertEquals([ "pnsdk" => PubNubUtil::urlEncode(PubNub::getSdkFullName()), "uuid" => $this->pubnub->getConfiguration()->getUuid(), - "type" => "gcm", + "type" => "fcm", ], $remove->buildParams()); } } - +// phpcs:ignore PSR1.Classes.ClassDeclaration class RemoveDeviceFromPushExposed extends RemoveDeviceFromPush { public function buildParams() @@ -89,4 +89,4 @@ public function buildPath() { return parent::buildPath(); } -} \ No newline at end of file +} diff --git a/tests/integrational/ListPushProvisionsTest.php b/tests/integrational/ListPushProvisionsTest.php index a30439a9..696b4bfb 100644 --- a/tests/integrational/ListPushProvisionsTest.php +++ b/tests/integrational/ListPushProvisionsTest.php @@ -8,7 +8,6 @@ use PubNub\PubNub; use Tests\Helpers\StubTransport; - class ListPushProvisionsTest extends \PubNubTestCase { public function testAppleSuccess() @@ -32,7 +31,7 @@ public function testAppleSuccess() $this->assertInstanceOf(\PubNub\Models\Consumer\Push\PNPushListProvisionsResult::class, $response); } - public function testGoogleSuccess() + public function testFCMSuccess() { $this->pubnub->getConfiguration()->setUuid("sampleUUID"); @@ -40,14 +39,14 @@ public function testGoogleSuccess() $list->stubFor("/v1/push/sub-key/demo/devices/coolDevice") ->withQuery([ - "type" => "gcm", + "type" => "fcm", "pnsdk" => $this->encodedSdkName, "uuid" => "sampleUUID" ]) ->setResponseBody("[\"ch1\", \"ch2\", \"ch3\"]"); $response = $list->deviceId("coolDevice") - ->pushType(PNPushType::GCM) + ->pushType(PNPushType::FCM) ->sync(); $this->assertInstanceOf(\PubNub\Models\Consumer\Push\PNPushListProvisionsResult::class, $response); @@ -176,7 +175,7 @@ public function superCallTest() } } - +// phpcs:ignore PSR1.Classes.ClassDeclaration class ListPushProvisionsExposed extends ListPushProvisions { protected $transport; @@ -209,4 +208,4 @@ public function requestOptions() 'transport' => $this->transport ]; } -} \ No newline at end of file +} diff --git a/tests/integrational/ModifyPushChannelsForDeviceTest.php b/tests/integrational/ModifyPushChannelsForDeviceTest.php index d61bca4c..59c1eea0 100644 --- a/tests/integrational/ModifyPushChannelsForDeviceTest.php +++ b/tests/integrational/ModifyPushChannelsForDeviceTest.php @@ -10,7 +10,6 @@ use PubNub\PubNub; use Tests\Helpers\StubTransport; - class ModifyPushChannelsForDeviceTest extends \PubNubTestCase { public function testListChannelGroupAPNS() @@ -34,7 +33,7 @@ public function testListChannelGroupAPNS() $this->assertInstanceOf(\PubNub\Models\Consumer\Push\PNPushRemoveAllChannelsResult::class, $response); } - public function testGoogleSuccessRemoveAll() + public function testFCMSuccessRemoveAll() { $this->pubnub->getConfiguration()->setUuid("sampleUUID"); @@ -42,13 +41,13 @@ public function testGoogleSuccessRemoveAll() $listRemove->stubFor("/v1/push/sub-key/demo/devices/coolDevice/remove") ->withQuery([ - "type" => "gcm", + "type" => "fcm", "pnsdk" => $this->encodedSdkName, "uuid" => "sampleUUID" ]) ->setResponseBody("[1, \"Modified Channels\"]"); - $response = $listRemove->pushType(PNPushType::GCM) + $response = $listRemove->pushType(PNPushType::FCM) ->deviceId("coolDevice") ->sync(); @@ -192,7 +191,7 @@ public function testAddAppleSuccess() $this->assertInstanceOf(\PubNub\Models\Consumer\Push\PNPushAddChannelResult::class, $response); } - public function testAddGoogleSuccessSync() + public function testAddFCMSuccessSync() { $this->pubnub->getConfiguration()->setUuid("sampleUUID"); @@ -201,13 +200,13 @@ public function testAddGoogleSuccessSync() $listAdd->stubFor("/v1/push/sub-key/demo/devices/coolDevice") ->withQuery([ "add" => "ch1,ch2,ch3", - "type" => "gcm", + "type" => "fcm", "pnsdk" => $this->encodedSdkName, "uuid" => "sampleUUID" ]) ->setResponseBody("[1, \"Modified Channels\"]"); - $response = $listAdd->pushType(PNPushType::GCM) + $response = $listAdd->pushType(PNPushType::FCM) ->channels(["ch1", "ch2", "ch3"]) ->deviceId("coolDevice") ->sync(); @@ -348,7 +347,7 @@ public function testMissingChannelsAdd() $listAdd = new AddChannelsToPushExposed($this->pubnub); $listAdd->pushType(PNPushType::MPNS) - ->deviceId("") + ->deviceId("Example") ->sync(); } @@ -375,7 +374,7 @@ public function testAppleSuccessRemove() $this->assertInstanceOf(\PubNub\Models\Consumer\Push\PNPushRemoveChannelResult::class, $response); } - public function testGoogleSuccessRemove() + public function testFCMSuccessRemove() { $this->pubnub->getConfiguration()->setUuid("sampleUUID"); @@ -384,13 +383,13 @@ public function testGoogleSuccessRemove() $remove->stubFor("/v1/push/sub-key/demo/devices/coolDevice") ->withQuery([ "remove" => "ch1,ch2,ch3", - "type" => "gcm", + "type" => "fcm", "pnsdk" => $this->encodedSdkName, "uuid" => "sampleUUID" ]) ->setResponseBody("[1, \"Modified Channels\"]"); - $response = $remove->pushType(PNPushType::GCM) + $response = $remove->pushType(PNPushType::FCM) ->channels(["ch1", "ch2", "ch3"]) ->deviceId("coolDevice") ->sync(); @@ -544,7 +543,7 @@ public function superCallTest() } } - +// phpcs:ignore PSR1.Classes.ClassDeclaration class RemoveChannelsFromPushTestExposed extends RemoveDeviceFromPush { protected $transport; @@ -579,7 +578,7 @@ public function requestOptions() } } - +// phpcs:ignore PSR1.Classes.ClassDeclaration class AddChannelsToPushExposed extends AddChannelsToPush { protected $transport; @@ -614,7 +613,7 @@ public function requestOptions() } } - +// phpcs:ignore PSR1.Classes.ClassDeclaration class RemovePushNotificationsFromChannelsExposed extends RemoveChannelsFromPush { protected $transport; @@ -647,4 +646,4 @@ public function requestOptions() 'transport' => $this->transport ]; } -} \ No newline at end of file +} diff --git a/tests/integrational/push/AddChannelsToPushEndpointTest.php b/tests/integrational/push/AddChannelsToPushEndpointTest.php index 92f3e503..78fd16b1 100644 --- a/tests/integrational/push/AddChannelsToPushEndpointTest.php +++ b/tests/integrational/push/AddChannelsToPushEndpointTest.php @@ -82,12 +82,42 @@ public function testPushAddApns2() $this->assertNotEmpty($result); } - public function testPushAddGoogle() + public function testPushAddFCM() { $this->pubnub->getConfiguration()->setUuid("sampleUUID"); $add = new AddChannelsToPushEndpointExposed($this->pubnub); + $add->stubFor("/v1/push/sub-key/demo/devices/coolDevice") + ->withQuery([ + "pnsdk" => $this->encodedSdkName, + "add" => "ch1,ch2,ch3", + "type" => "fcm", + "uuid" => "sampleUUID", + ]) + ->setResponseBody('[1, "Modified Channels"]'); + + $result = $add->channels(["ch1", "ch2", "ch3"]) + ->pushType(PNPushType::FCM) + ->deviceId("coolDevice") + ->sync(); + + $this->assertNotEmpty($result); + } + + public function testWarningWhenUsingDeprecatedGCMType() + { + set_error_handler(static function (int $errno, string $errstr): never { + throw new \Exception($errstr, $errno); + }, E_USER_DEPRECATED); + + $this->expectException(\Exception::class); + $this->expectExceptionMessage('GCM is deprecated. Please use FCM instead.'); + + $this->pubnub->getConfiguration()->setUuid("sampleUUID"); + + $add = new AddChannelsToPushEndpointExposed($this->pubnub); + $add->stubFor("/v1/push/sub-key/demo/devices/coolDevice") ->withQuery([ "pnsdk" => $this->encodedSdkName, @@ -99,13 +129,14 @@ public function testPushAddGoogle() $result = $add->channels(["ch1", "ch2", "ch3"]) ->pushType(PNPushType::GCM) - ->deviceId("coolDevice"); + ->deviceId("coolDevice") + ->sync(); $this->assertNotEmpty($result); } } - +// phpcs:ignore PSR1.Classes.ClassDeclaration class AddChannelsToPushEndpointExposed extends AddChannelsToPush { protected $transport; diff --git a/tests/integrational/push/ListPushProvisionsEndpointTest.php b/tests/integrational/push/ListPushProvisionsEndpointTest.php index 3251f4f1..8b1977cc 100644 --- a/tests/integrational/push/ListPushProvisionsEndpointTest.php +++ b/tests/integrational/push/ListPushProvisionsEndpointTest.php @@ -8,7 +8,6 @@ use PubNubTestCase; use Tests\Helpers\StubTransport; - class ListPushProvisionsEndpointTest extends PubNubTestCase { public function testListChannelGroupAPNS() @@ -31,7 +30,7 @@ public function testListChannelGroupAPNS() $this->assertNotEmpty($result); } - + public function testListChannelGroupAPNS2() { $this->pubnub->getConfiguration()->setUuid("sampleUUID"); @@ -56,7 +55,7 @@ public function testListChannelGroupAPNS2() $this->assertNotEmpty($result); } - public function testListChannelGroupGCM() + public function testListChannelGroupFCM() { $this->pubnub->getConfiguration()->setUuid("sampleUUID"); @@ -65,12 +64,12 @@ public function testListChannelGroupGCM() $list->stubFor("/v1/push/sub-key/demo/devices/coolDevice") ->withQuery([ "pnsdk" => $this->encodedSdkName, - "type" => "gcm", + "type" => "fcm", "uuid" => "sampleUUID", ]) ->setResponseBody('[1, "Modified Channels"]'); - $result = $list->pushType(PNPushType::GCM) + $result = $list->pushType(PNPushType::FCM) ->deviceId("coolDevice") ->sync(); @@ -97,9 +96,37 @@ public function testListChannelGroupMPNS() $this->assertNotEmpty($result); } -} + public function testWarningWhenUsingDeprecatedGCMType() + { + set_error_handler(static function (int $errno, string $errstr): never { + throw new \Exception($errstr, $errno); + }, E_USER_DEPRECATED); + + $this->expectException(\Exception::class); + $this->expectExceptionMessage('GCM is deprecated. Please use FCM instead.'); + + $this->pubnub->getConfiguration()->setUuid("sampleUUID"); + + $list = new ListPushProvisionsEndpointExposed($this->pubnub); + + $list->stubFor("/v1/push/sub-key/demo/devices/coolDevice") + ->withQuery([ + "pnsdk" => $this->encodedSdkName, + "type" => "gcm", + "uuid" => "sampleUUID", + ]) + ->setResponseBody('[1, "Modified Channels"]'); + + $result = $list->pushType(PNPushType::GCM) + ->deviceId("coolDevice") + ->sync(); + + $this->assertNotEmpty($result); + } +} +// phpcs:ignore PSR1.Classes.ClassDeclaration class ListPushProvisionsEndpointExposed extends ListPushProvisions { protected $transport; @@ -132,4 +159,5 @@ public function requestOptions() 'transport' => $this->transport ]; } -} \ No newline at end of file +} +// phpcs:ignore PSR1.Classes.ClassDeclaration diff --git a/tests/integrational/push/RemoveChannelsFromPushEndpointTest.php b/tests/integrational/push/RemoveChannelsFromPushEndpointTest.php index 5649ef2d..698defcd 100644 --- a/tests/integrational/push/RemoveChannelsFromPushEndpointTest.php +++ b/tests/integrational/push/RemoveChannelsFromPushEndpointTest.php @@ -79,7 +79,7 @@ public function testPushRemoveMultipleChannels() $this->assertNotEmpty($result); } - public function testPushRemoveGoogle() + public function testPushRemoveFCM() { $this->pubnub->getConfiguration()->setUuid("sampleUUID"); @@ -88,14 +88,14 @@ public function testPushRemoveGoogle() $remove->stubFor("/v1/push/sub-key/demo/devices/coolDevice") ->withQuery([ "pnsdk" => $this->encodedSdkName, - "type" => "gcm", + "type" => "fcm", "uuid" => "sampleUUID", "remove" => "ch1,ch2,ch3" ]) ->setResponseBody('[1, "Modified Channels"]'); $result = $remove->channels(['ch1', 'ch2', 'ch3']) - ->pushType(PNPushType::GCM) + ->pushType(PNPushType::FCM) ->deviceId('coolDevice') ->sync(); @@ -103,7 +103,7 @@ public function testPushRemoveGoogle() } } - +// phpcs:ignore PSR1.Classes.ClassDeclaration class RemoveChannelsFromPushEndpointExposed extends RemoveChannelsFromPush { protected $transport; @@ -126,4 +126,4 @@ public function requestOptions() 'transport' => $this->transport ]; } -} \ No newline at end of file +} diff --git a/tests/integrational/push/RemoveDeviceFromPushEndpointTest.php b/tests/integrational/push/RemoveDeviceFromPushEndpointTest.php index a69790da..0e94f98f 100644 --- a/tests/integrational/push/RemoveDeviceFromPushEndpointTest.php +++ b/tests/integrational/push/RemoveDeviceFromPushEndpointTest.php @@ -75,12 +75,39 @@ public function testRemovePushMPNS() $this->assertNotEmpty($result); } - public function testRemovePushGCM() + public function testRemovePushFCM() { $this->pubnub->getConfiguration()->setUuid("sampleUUID"); $remove = new RemoveDeviceFromPushEndpointExposed($this->pubnub); + $remove->stubFor("/v1/push/sub-key/demo/devices/coolDevice/remove") + ->withQuery([ + "pnsdk" => $this->encodedSdkName, + "type" => "fcm", + "uuid" => "sampleUUID", + ]) + ->setResponseBody('[1, "Modified Channels"]'); + + $result = $remove->pushType(PNPushType::FCM) + ->deviceId('coolDevice') + ->sync(); + + $this->assertNotEmpty($result); + } + + public function testWarningWhenUsingDeprecatedGCMType() + { + set_error_handler(static function (int $errno, string $errstr): never { + throw new \Exception($errstr, $errno); + }, E_USER_DEPRECATED); + + $this->expectException(\Exception::class); + $this->expectExceptionMessage('GCM is deprecated. Please use FCM instead.'); + $this->pubnub->getConfiguration()->setUuid("sampleUUID"); + + $remove = new RemoveDeviceFromPushEndpointExposed($this->pubnub); + $remove->stubFor("/v1/push/sub-key/demo/devices/coolDevice/remove") ->withQuery([ "pnsdk" => $this->encodedSdkName, @@ -97,7 +124,7 @@ public function testRemovePushGCM() } } - +// phpcs:ignore PSR1.Classes.ClassDeclaration class RemoveDeviceFromPushEndpointExposed extends RemoveDeviceFromPush { protected $transport; @@ -120,4 +147,4 @@ public function requestOptions() 'transport' => $this->transport ]; } -} \ No newline at end of file +}