From cbb562f1053d77fdc02b68c60f19fa0d88e1ba25 Mon Sep 17 00:00:00 2001 From: Jan Klat Date: Mon, 26 Oct 2015 15:03:23 +0100 Subject: [PATCH 01/14] add constants for error messages --- library/ZendService/Google/Gcm/Response.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/library/ZendService/Google/Gcm/Response.php b/library/ZendService/Google/Gcm/Response.php index e1646a4..f20bc42 100644 --- a/library/ZendService/Google/Gcm/Response.php +++ b/library/ZendService/Google/Gcm/Response.php @@ -40,6 +40,24 @@ class Response */ const RESULT_CANONICAL = 'registration_id'; + /** + * Error field responses + * @link https://developers.google.com/cloud-messaging/http-server-ref#error-codes + * @var string + */ + const ERROR_MISSING_REGISTRATION = 'MissingRegistration'; + const ERROR_INVALID_REGISTRATION = 'InvalidRegistration'; + const ERROR_NOT_REGISTERED = 'NotRegistered'; + const ERROR_INVALID_PACKAGE_NAME = 'InvalidPackageName'; + const ERROR_MISMATCH_SENDER_ID = 'MismatchSenderId'; + const ERROR_MESSAGE_TOO_BIG = 'MessageTooBig'; + const ERROR_INVALID_DATA_KEY = 'InvalidDataKey'; + const ERROR_INVALID_TTL = 'InvalidTtl'; + const ERROR_UNAVAILABLE = 'Unavailable'; + const ERROR_INTERNAL_SERVER_ERROR = 'InternalServerError'; + const ERROR_DEVICE_MESSAGE_RATE_EXCEEDED = 'DeviceMessageRateExceeded'; + const ERROR_TOPICS_MESSAGE_RATE_EXCEEDED = 'TopicsMessageRateExceeded'; + /** * @var int */ From d7f16a9e94e92661c34843c11d296669beba8c99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=B6lsterli=20Stefan?= Date: Wed, 6 Apr 2016 02:00:08 +0200 Subject: [PATCH 02/14] Add content length this is required by google, i got a 411 HTTP error before adding this line --- library/ZendService/Google/Gcm/Client.php | 1 + 1 file changed, 1 insertion(+) diff --git a/library/ZendService/Google/Gcm/Client.php b/library/ZendService/Google/Gcm/Client.php index 244da70..dcd0a2c 100644 --- a/library/ZendService/Google/Gcm/Client.php +++ b/library/ZendService/Google/Gcm/Client.php @@ -106,6 +106,7 @@ public function send(Message $message) $client->setUri(self::SERVER_URI); $headers = $client->getRequest()->getHeaders(); $headers->addHeaderLine('Authorization', 'key=' . $this->getApiKey()); + $headers->addHeaderLine('Content-length', strlen($message->toJson())); $response = $client->setHeaders($headers) ->setMethod('POST') From f69c2b2beca6943b61877c35d7800a339fd685e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=B6lsterli=20Stefan?= Date: Wed, 28 Sep 2016 16:13:12 +0200 Subject: [PATCH 03/14] header content length changed strlen to mb_strlen --- library/ZendService/Google/Gcm/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/ZendService/Google/Gcm/Client.php b/library/ZendService/Google/Gcm/Client.php index dcd0a2c..becbcd3 100644 --- a/library/ZendService/Google/Gcm/Client.php +++ b/library/ZendService/Google/Gcm/Client.php @@ -106,7 +106,7 @@ public function send(Message $message) $client->setUri(self::SERVER_URI); $headers = $client->getRequest()->getHeaders(); $headers->addHeaderLine('Authorization', 'key=' . $this->getApiKey()); - $headers->addHeaderLine('Content-length', strlen($message->toJson())); + $headers->addHeaderLine('Content-length', mb_strlen($message->toJson())); $response = $client->setHeaders($headers) ->setMethod('POST') From cd21402a8b103f43ca6ef62e3cf4fe26be30fa97 Mon Sep 17 00:00:00 2001 From: Jan Klat Date: Mon, 10 Apr 2017 16:45:14 +0200 Subject: [PATCH 04/14] align assignments (CR request) --- library/Gcm/Response.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/library/Gcm/Response.php b/library/Gcm/Response.php index ec8b3c1..3f3197d 100644 --- a/library/Gcm/Response.php +++ b/library/Gcm/Response.php @@ -42,16 +42,16 @@ class Response * @link https://developers.google.com/cloud-messaging/http-server-ref#error-codes * @var string */ - const ERROR_MISSING_REGISTRATION = 'MissingRegistration'; - const ERROR_INVALID_REGISTRATION = 'InvalidRegistration'; - const ERROR_NOT_REGISTERED = 'NotRegistered'; - const ERROR_INVALID_PACKAGE_NAME = 'InvalidPackageName'; - const ERROR_MISMATCH_SENDER_ID = 'MismatchSenderId'; - const ERROR_MESSAGE_TOO_BIG = 'MessageTooBig'; - const ERROR_INVALID_DATA_KEY = 'InvalidDataKey'; - const ERROR_INVALID_TTL = 'InvalidTtl'; - const ERROR_UNAVAILABLE = 'Unavailable'; - const ERROR_INTERNAL_SERVER_ERROR = 'InternalServerError'; + const ERROR_MISSING_REGISTRATION = 'MissingRegistration'; + const ERROR_INVALID_REGISTRATION = 'InvalidRegistration'; + const ERROR_NOT_REGISTERED = 'NotRegistered'; + const ERROR_INVALID_PACKAGE_NAME = 'InvalidPackageName'; + const ERROR_MISMATCH_SENDER_ID = 'MismatchSenderId'; + const ERROR_MESSAGE_TOO_BIG = 'MessageTooBig'; + const ERROR_INVALID_DATA_KEY = 'InvalidDataKey'; + const ERROR_INVALID_TTL = 'InvalidTtl'; + const ERROR_UNAVAILABLE = 'Unavailable'; + const ERROR_INTERNAL_SERVER_ERROR = 'InternalServerError'; const ERROR_DEVICE_MESSAGE_RATE_EXCEEDED = 'DeviceMessageRateExceeded'; const ERROR_TOPICS_MESSAGE_RATE_EXCEEDED = 'TopicsMessageRateExceeded'; From 7a6e2fc326060c290da0761911fd6ea494612903 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 8 May 2018 13:55:36 -0500 Subject: [PATCH 05/14] Adds CHANGELOG entry for #13 --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2789c18..b17fb58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,14 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. -## 2.0.1 - TBD +## 2.1.0 - TBD ### Added +- [#13](https://github.com/zendframework/ZendService_Google_Gcm/pull/13) adds constants mapping to common GCM error codes as `ZendService\Gcm\Response::ERROR_*`. + +### Changed + - Nothing. ### Deprecated From 3abe46537e799d196c34bf87118573fb0f42cb36 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 8 May 2018 13:59:01 -0500 Subject: [PATCH 06/14] Adds CHANGELOG entry for #18 --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b17fb58..fb12d77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,8 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed -- Nothing. +- [#18](https://github.com/zendframework/ZendService_Google_Gcm/pull/18) adds a `Content-Length` header with the message length prior to sending + messages to GCM; this fixes 411 errors previously observed. ## 2.0.0 - 2017-01-17 From 5ac7bf062f9125a2d5bb816591281eb3f7d1d137 Mon Sep 17 00:00:00 2001 From: webimpress Date: Thu, 3 May 2018 17:56:34 +0100 Subject: [PATCH 07/14] Updated Travis CI configuration - added PHP 7.2 builds - removed IRC notifcations - disabled email notications - updated PHPUnit to allow 4, 5, 6 and 7 series - updated tests to work with all wersions of PHPUnit --- .travis.yml | 3 ++- composer.json | 2 +- tests/Gcm/ClientTest.php | 2 +- tests/Gcm/MessageTest.php | 2 +- tests/Gcm/ResponseTest.php | 2 +- tests/Gcm/TestCase.php | 28 ++++++++++++++++++++++++++++ 6 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 tests/Gcm/TestCase.php diff --git a/.travis.yml b/.travis.yml index 3b81e04..7904182 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ php: - 5.6 - 7.0 - 7.1 + - 7.2 - hhvm before_install: @@ -14,4 +15,4 @@ script: - ./vendor/bin/phpunit notifications: - irc: "irc.freenode.org#zftalk.2" + email: false diff --git a/composer.json b/composer.json index ec4282e..feadcff 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,6 @@ "zendframework/zend-json": "^2.0" }, "require-dev": { - "phpunit/PHPUnit": "^4.8" + "phpunit/phpunit": "^4.8.36 || ^5.7 || ^6.5 || ^7.1" } } diff --git a/tests/Gcm/ClientTest.php b/tests/Gcm/ClientTest.php index a34d3de..49a70de 100644 --- a/tests/Gcm/ClientTest.php +++ b/tests/Gcm/ClientTest.php @@ -22,7 +22,7 @@ * @group ZendService_Google * @group ZendService_Google_Gcm */ -class ClientTest extends \PHPUnit_Framework_TestCase +class ClientTest extends TestCase { /** * @var Test diff --git a/tests/Gcm/MessageTest.php b/tests/Gcm/MessageTest.php index f9729a4..f7614e5 100644 --- a/tests/Gcm/MessageTest.php +++ b/tests/Gcm/MessageTest.php @@ -19,7 +19,7 @@ * @group ZendService_Google * @group ZendService_Google_Gcm */ -class MessageTest extends \PHPUnit_Framework_TestCase +class MessageTest extends TestCase { protected $validRegistrationIds = [ '1234567890', diff --git a/tests/Gcm/ResponseTest.php b/tests/Gcm/ResponseTest.php index 47ddc6c..bb08831 100644 --- a/tests/Gcm/ResponseTest.php +++ b/tests/Gcm/ResponseTest.php @@ -20,7 +20,7 @@ * @group ZendService_Google * @group ZendService_Google_Gcm */ -class ResponseTest extends \PHPUnit_Framework_TestCase +class ResponseTest extends TestCase { /** * @var Message diff --git a/tests/Gcm/TestCase.php b/tests/Gcm/TestCase.php new file mode 100644 index 0000000..6ca7aaf --- /dev/null +++ b/tests/Gcm/TestCase.php @@ -0,0 +1,28 @@ +expectException($exceptionName); + if ($exceptionMessage) { + $this->expectExceptionMessage($exceptionMessage); + } + if ($exceptionCode) { + $this->expectExceptionCode($exceptionCode); + } + + return; + } + + parent::setExpectedException($exceptionName, $exceptionMessage, $exceptionCode); + } +} From 6163be94885dfaa4e7f07af86dfb2b571236a82b Mon Sep 17 00:00:00 2001 From: webimpress Date: Thu, 3 May 2018 17:58:29 +0100 Subject: [PATCH 08/14] Updated LICENSE - converted to MD format --- LICENSE.txt => LICENSE.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) rename LICENSE.txt => LICENSE.md (59%) diff --git a/LICENSE.txt b/LICENSE.md similarity index 59% rename from LICENSE.txt rename to LICENSE.md index 5ad81e9..d44ab5d 100644 --- a/LICENSE.txt +++ b/LICENSE.md @@ -1,19 +1,19 @@ -Copyright (c) 2005-2014, Zend Technologies USA, Inc. +Copyright (c) 2005-2018, Zend Technologies USA, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. +- Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. +- Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. - * Neither the name of Zend Technologies USA, Inc. nor the names of its - contributors may be used to endorse or promote products derived from this - software without specific prior written permission. +- Neither the name of Zend Technologies USA, Inc. nor the names of its + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED From 35fd9c2d54931e94b5294a345956ebb1b4020b78 Mon Sep 17 00:00:00 2001 From: webimpress Date: Thu, 3 May 2018 17:59:14 +0100 Subject: [PATCH 09/14] Updated PHPUnit configuration --- phpunit.xml.dist | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0f43c99..87a4ec9 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,13 +1,17 @@ - + + - ./tests + ./test - - - disable - - + + + ./src + + From 751372c7584dfde20c84989895bece95c4fb8f6d Mon Sep 17 00:00:00 2001 From: webimpress Date: Thu, 3 May 2018 18:00:40 +0100 Subject: [PATCH 10/14] Moved sources to src directory and tests to test directory Now we are consistent with other repositories in zendframework org --- composer.json | 4 ++-- {library => src}/Exception/InvalidArgumentException.php | 0 {library => src}/Exception/RuntimeException.php | 0 {library => src}/Gcm/Client.php | 0 {library => src}/Gcm/Message.php | 0 {library => src}/Gcm/Response.php | 0 {tests => test}/Gcm/ClientTest.php | 0 {tests => test}/Gcm/MessageTest.php | 0 {tests => test}/Gcm/ResponseTest.php | 0 {tests => test}/Gcm/TestCase.php | 0 10 files changed, 2 insertions(+), 2 deletions(-) rename {library => src}/Exception/InvalidArgumentException.php (100%) rename {library => src}/Exception/RuntimeException.php (100%) rename {library => src}/Gcm/Client.php (100%) rename {library => src}/Gcm/Message.php (100%) rename {library => src}/Gcm/Response.php (100%) rename {tests => test}/Gcm/ClientTest.php (100%) rename {tests => test}/Gcm/MessageTest.php (100%) rename {tests => test}/Gcm/ResponseTest.php (100%) rename {tests => test}/Gcm/TestCase.php (100%) diff --git a/composer.json b/composer.json index feadcff..dc1096c 100644 --- a/composer.json +++ b/composer.json @@ -13,12 +13,12 @@ "license": "BSD-3-Clause", "autoload": { "psr-4": { - "ZendService\\Google\\": "library/" + "ZendService\\Google\\": "src/" } }, "autoload-dev": { "psr-4": { - "ZendServiceTest\\Google\\": "tests/" + "ZendServiceTest\\Google\\": "test/" } }, "require": { diff --git a/library/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php similarity index 100% rename from library/Exception/InvalidArgumentException.php rename to src/Exception/InvalidArgumentException.php diff --git a/library/Exception/RuntimeException.php b/src/Exception/RuntimeException.php similarity index 100% rename from library/Exception/RuntimeException.php rename to src/Exception/RuntimeException.php diff --git a/library/Gcm/Client.php b/src/Gcm/Client.php similarity index 100% rename from library/Gcm/Client.php rename to src/Gcm/Client.php diff --git a/library/Gcm/Message.php b/src/Gcm/Message.php similarity index 100% rename from library/Gcm/Message.php rename to src/Gcm/Message.php diff --git a/library/Gcm/Response.php b/src/Gcm/Response.php similarity index 100% rename from library/Gcm/Response.php rename to src/Gcm/Response.php diff --git a/tests/Gcm/ClientTest.php b/test/Gcm/ClientTest.php similarity index 100% rename from tests/Gcm/ClientTest.php rename to test/Gcm/ClientTest.php diff --git a/tests/Gcm/MessageTest.php b/test/Gcm/MessageTest.php similarity index 100% rename from tests/Gcm/MessageTest.php rename to test/Gcm/MessageTest.php diff --git a/tests/Gcm/ResponseTest.php b/test/Gcm/ResponseTest.php similarity index 100% rename from tests/Gcm/ResponseTest.php rename to test/Gcm/ResponseTest.php diff --git a/tests/Gcm/TestCase.php b/test/Gcm/TestCase.php similarity index 100% rename from tests/Gcm/TestCase.php rename to test/Gcm/TestCase.php From eeda7d09d24c1c4389b92f9b0408a68af597dc99 Mon Sep 17 00:00:00 2001 From: webimpress Date: Thu, 3 May 2018 18:01:15 +0100 Subject: [PATCH 11/14] Updated README.md as PHP 5.5+ is only supported --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4491bfb..d5249b0 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Provides support for Google push notifications. ## Requirements ## -* PHP >= 5.3.3 +* PHP >= 5.5 ## Getting Started ## From 5e391bc7229eec94ee3398b60f41600b74319810 Mon Sep 17 00:00:00 2001 From: webimpress Date: Fri, 4 May 2018 15:31:47 +0100 Subject: [PATCH 12/14] Dropped PHP 5.5 and HHVM support --- .travis.yml | 6 ++---- README.md | 8 ++++---- composer.json | 2 +- test/Gcm/ClientTest.php | 11 ++++++----- test/Gcm/MessageTest.php | 11 ++++++----- test/Gcm/ResponseTest.php | 5 +++-- test/Gcm/TestCase.php | 28 ---------------------------- 7 files changed, 22 insertions(+), 49 deletions(-) delete mode 100644 test/Gcm/TestCase.php diff --git a/.travis.yml b/.travis.yml index 7904182..4763b4d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,16 @@ language: php php: - - 5.5 - 5.6 - 7.0 - 7.1 - 7.2 - - hhvm before_install: - - composer install + - composer install script: - - ./vendor/bin/phpunit + - ./vendor/bin/phpunit notifications: email: false diff --git a/README.md b/README.md index d5249b0..5c41dbb 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,11 @@ ZendService\Google\Gcm [![Build Status](https://api.travis-ci.org/zendframework/ Provides support for Google push notifications. -## Requirements ## +## Requirements -* PHP >= 5.5 +* PHP >= 5.6 -## Getting Started ## +## Getting Started Install this library using [Composer](http://getcomposer.org/): @@ -15,6 +15,6 @@ Install this library using [Composer](http://getcomposer.org/): $ composer require zendframework/zendservice-google-gcm ``` -## Documentation ## +## Documentation The documentation can be found at: http://framework.zend.com/manual/current/en/modules/zendservice.google.gcm.html diff --git a/composer.json b/composer.json index dc1096c..d5b9cee 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,6 @@ "zendframework/zend-json": "^2.0" }, "require-dev": { - "phpunit/phpunit": "^4.8.36 || ^5.7 || ^6.5 || ^7.1" + "phpunit/phpunit": "^5.7.27 || ^6.5.8 || ^7.1.5" } } diff --git a/test/Gcm/ClientTest.php b/test/Gcm/ClientTest.php index 49a70de..5760542 100644 --- a/test/Gcm/ClientTest.php +++ b/test/Gcm/ClientTest.php @@ -11,6 +11,7 @@ */ namespace ZendServiceTest\Google\Gcm; +use PHPUnit\Framework\TestCase; use Zend\Http\Client\Adapter\Test; use Zend\Http\Client as HttpClient; use ZendService\Google\Gcm\Client; @@ -69,7 +70,7 @@ public function setUp() public function testSetApiKeyThrowsExceptionOnNonString() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException('InvalidArgumentException'); $this->gcmClient->setApiKey([]); } @@ -94,28 +95,28 @@ public function testSetHttpClient() public function testSendThrowsExceptionWhenServiceUnavailable() { - $this->setExpectedException('RuntimeException'); + $this->expectException('RuntimeException'); $this->httpAdapter->setResponse('HTTP/1.1 503 Service Unavailable'."\r\n\r\n"); $this->gcmClient->send($this->message); } public function testSendThrowsExceptionWhenServerUnavailable() { - $this->setExpectedException('RuntimeException'); + $this->expectException('RuntimeException'); $this->httpAdapter->setResponse('HTTP/1.1 500 Internal Server Error'."\r\n\r\n"); $this->gcmClient->send($this->message); } public function testSendThrowsExceptionWhenInvalidAuthToken() { - $this->setExpectedException('RuntimeException'); + $this->expectException('RuntimeException'); $this->httpAdapter->setResponse('HTTP/1.1 401 Unauthorized'."\r\n\r\n"); $this->gcmClient->send($this->message); } public function testSendThrowsExceptionWhenInvalidPayload() { - $this->setExpectedException('RuntimeException'); + $this->expectException('RuntimeException'); $this->httpAdapter->setResponse('HTTP/1.1 400 Bad Request'."\r\n\r\n"); $this->gcmClient->send($this->message); } diff --git a/test/Gcm/MessageTest.php b/test/Gcm/MessageTest.php index f7614e5..d117400 100644 --- a/test/Gcm/MessageTest.php +++ b/test/Gcm/MessageTest.php @@ -11,6 +11,7 @@ */ namespace ZendServiceTest\Google\Gcm; +use PHPUnit\Framework\TestCase; use ZendService\Google\Gcm\Message; /** @@ -64,7 +65,7 @@ public function testExpectedRegistrationIdBehavior() public function testInvalidRegistrationIdThrowsException() { - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $this->m->addRegistrationId(['1234']); } @@ -82,7 +83,7 @@ public function testExpectedCollapseKeyBehavior() public function testInvalidCollapseKeyThrowsException() { - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $this->m->setCollapseKey(['1234']); } @@ -118,13 +119,13 @@ public function testExpectedNotificationBehavior() public function testInvalidDataThrowsException() { - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $this->m->addData(['1234'], 'value'); } public function testDuplicateDataKeyThrowsException() { - $this->setExpectedException(\RuntimeException::class); + $this->expectException(\RuntimeException::class); $this->m->setData($this->validData); $this->m->addData('key', 'value'); } @@ -167,7 +168,7 @@ public function testExpectedRestrictedPackageBehavior() public function testInvalidRestrictedPackageThrowsException() { - $this->setExpectedException(\InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $this->m->setRestrictedPackageName(['1234']); } diff --git a/test/Gcm/ResponseTest.php b/test/Gcm/ResponseTest.php index bb08831..14e1a43 100644 --- a/test/Gcm/ResponseTest.php +++ b/test/Gcm/ResponseTest.php @@ -11,6 +11,7 @@ */ namespace ZendServiceTest\Google\Gcm; +use PHPUnit\Framework\TestCase; use ZendService\Google\Gcm\Message; use ZendService\Google\Gcm\Response; @@ -64,7 +65,7 @@ public function testInvalidConstructorThrowsException() self::markTestSkipped('PHP 7 required.'); } - $this->setExpectedException(\TypeError::class); + $this->expectException(\TypeError::class); new Response('{bad'); } @@ -74,7 +75,7 @@ public function testInvalidConstructorThrowsExceptionOnPhp7() self::markTestSkipped('PHP >=5.5 required.'); } - $this->setExpectedException(\PHPUnit_Framework_Error::class); + $this->expectException(\PHPUnit_Framework_Error::class); new Response('{bad'); } diff --git a/test/Gcm/TestCase.php b/test/Gcm/TestCase.php deleted file mode 100644 index 6ca7aaf..0000000 --- a/test/Gcm/TestCase.php +++ /dev/null @@ -1,28 +0,0 @@ -expectException($exceptionName); - if ($exceptionMessage) { - $this->expectExceptionMessage($exceptionMessage); - } - if ($exceptionCode) { - $this->expectExceptionCode($exceptionCode); - } - - return; - } - - parent::setExpectedException($exceptionName, $exceptionMessage, $exceptionCode); - } -} From 8de032ea7e64768566f350e8a99f6f3e47c6c286 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 8 May 2018 14:12:37 -0500 Subject: [PATCH 13/14] Updates composer definition, and adds zend-coding-standard Updates the composer definition to match that of other packages in structure. In the process, also: - Bumps minimum PHP version to 5.6. - Adds zend-coding-standard as a dev requirement. - Runs phpcbf on the repo, and fixes additional errors reported by phpcs --- .travis.yml | 18 ++++++++++++------ composer.json | 36 ++++++++++++++++++++++++++---------- phpcs.xml | 7 +++++++ src/Gcm/Client.php | 6 +++--- src/Gcm/Message.php | 14 +++++++------- src/Gcm/Response.php | 8 +++++++- test/Gcm/ClientTest.php | 14 +++++++------- test/Gcm/MessageTest.php | 6 +++--- 8 files changed, 72 insertions(+), 37 deletions(-) create mode 100644 phpcs.xml diff --git a/.travis.yml b/.travis.yml index 4763b4d..7f38c26 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,22 @@ +sudo: false + language: php -php: - - 5.6 - - 7.0 - - 7.1 - - 7.2 +matrix: + include: + - php: 5.6 + - php: 7.0 + - php: 7.1 + env: + - CS_CHECK=true + - php: 7.2 before_install: - - composer install + - composer install --no-interaction script: - ./vendor/bin/phpunit + - if [[ $CS_CHECK == 'true' ]]; then ./vendor/bin/phpcs ; fi notifications: email: false diff --git a/composer.json b/composer.json index d5b9cee..0936edb 100644 --- a/composer.json +++ b/composer.json @@ -1,16 +1,31 @@ { "name": "zendframework/zendservice-google-gcm", "description": "OOP wrapper for Google Cloud Messaging", - "type": "library", + "license": "BSD-3-Clause", "keywords": [ - "zf2", + "zf", + "zendframework", "gcm", "push", "notification", "google" ], - "homepage": "https://github.com/zendframework/zendservice-google-gcm", - "license": "BSD-3-Clause", + "support": { + "issues": "https://github.com/zendframework/ZendService_Google_Gcm/issues", + "source": "https://github.com/zendframework/ZendService_Google_Gcm", + "rss": "https://github.com/zendframework/ZendService_Google_Gcm/releases.atom", + "chat": "https://zendframework-slack.herokuapp.com", + "forum": "https://discourse.zendframework.com/c/questions/components" + }, + "require": { + "php": "^5.6 || ^7.0", + "zendframework/zend-http": "^2.0", + "zendframework/zend-json": "^2.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7.27 || ^6.5.8 || ^7.1.5", + "zendframework/zend-coding-standard": "~1.0.0" + }, "autoload": { "psr-4": { "ZendService\\Google\\": "src/" @@ -21,12 +36,13 @@ "ZendServiceTest\\Google\\": "test/" } }, - "require": { - "php": "^5.5 || ^7.0", - "zendframework/zend-http": "^2.0", - "zendframework/zend-json": "^2.0" + "config": { + "sort-packages": true }, - "require-dev": { - "phpunit/phpunit": "^5.7.27 || ^6.5.8 || ^7.1.5" + "extra": { + "branch-alias": { + "dev-master": "2.1.x-dev", + "dev-develop": "2.2.x-dev" + } } } diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..4bfc5d0 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,7 @@ + + + + + src + test + diff --git a/src/Gcm/Client.php b/src/Gcm/Client.php index 7bf2265..45b9ae0 100644 --- a/src/Gcm/Client.php +++ b/src/Gcm/Client.php @@ -60,7 +60,7 @@ public function getApiKey() */ public function setApiKey($apiKey) { - if (!is_string($apiKey) || empty($apiKey)) { + if (! is_string($apiKey) || empty($apiKey)) { throw new Exception\InvalidArgumentException('The api key must be a string and not empty'); } $this->apiKey = $apiKey; @@ -77,7 +77,7 @@ public function setApiKey($apiKey) */ public function getHttpClient() { - if (!$this->httpClient) { + if (! $this->httpClient) { $this->httpClient = new HttpClient(); $this->httpClient->setOptions(['strictredirects' => true]); } @@ -147,7 +147,7 @@ public function send(Message $message) break; } - if (!$response = Json::decode($response->getBody(), Json::TYPE_ARRAY)) { + if (! $response = Json::decode($response->getBody(), Json::TYPE_ARRAY)) { throw new Exception\RuntimeException('Response body did not contain a valid JSON response'); } diff --git a/src/Gcm/Message.php b/src/Gcm/Message.php index c36d6d5..1e55fbe 100644 --- a/src/Gcm/Message.php +++ b/src/Gcm/Message.php @@ -108,10 +108,10 @@ public function getRegistrationIds() */ public function addRegistrationId($id) { - if (!is_string($id) || empty($id)) { + if (! is_string($id) || empty($id)) { throw new Exception\InvalidArgumentException('$id must be a non-empty string'); } - if (!in_array($id, $this->registrationIds)) { + if (! in_array($id, $this->registrationIds)) { $this->registrationIds[] = $id; } @@ -151,7 +151,7 @@ public function getCollapseKey() */ public function setCollapseKey($key) { - if (null !== $key && !(is_string($key) && strlen($key) > 0)) { + if (null !== $key && ! (is_string($key) && strlen($key) > 0)) { throw new Exception\InvalidArgumentException('$key must be null or a non-empty string'); } $this->collapseKey = $key; @@ -178,7 +178,7 @@ public function getPriority() */ public function setPriority($priority) { - if (!is_null($priority) && !(is_string($priority) && strlen($priority) > 0)) { + if (! is_null($priority) && ! (is_string($priority) && strlen($priority) > 0)) { throw new Exception\InvalidArgumentException('$priority must be null or a non-empty string'); } $this->priority = $priority; @@ -227,7 +227,7 @@ public function getData() */ public function addData($key, $value) { - if (!is_string($key) || empty($key)) { + if (! is_string($key) || empty($key)) { throw new Exception\InvalidArgumentException('$key must be a non-empty string'); } if (array_key_exists($key, $this->data)) { @@ -286,7 +286,7 @@ public function getNotification() */ public function addNotification($key, $value) { - if (!is_string($key) || empty($key)) { + if (! is_string($key) || empty($key)) { throw new Exception\InvalidArgumentException('$key must be a non-empty string'); } if (array_key_exists($key, $this->notification)) { @@ -367,7 +367,7 @@ public function getTimeToLive() */ public function setRestrictedPackageName($name) { - if (null !== $name && !(is_string($name) && strlen($name) > 0)) { + if (null !== $name && ! (is_string($name) && strlen($name) > 0)) { throw new Exception\InvalidArgumentException('$name must be null OR a non-empty string'); } $this->restrictedPackageName = $name; diff --git a/src/Gcm/Response.php b/src/Gcm/Response.php index 3f3197d..15f86ee 100644 --- a/src/Gcm/Response.php +++ b/src/Gcm/Response.php @@ -156,7 +156,13 @@ public function getResponse() */ public function setResponse(array $response) { - if (!isset($response['results'], $response['success'], $response['failure'], $response['canonical_ids'], $response['multicast_id'])) { + if (! isset( + $response['results'], + $response['success'], + $response['failure'], + $response['canonical_ids'], + $response['multicast_id'] + )) { throw new Exception\InvalidArgumentException('Response did not contain the proper fields'); } diff --git a/test/Gcm/ClientTest.php b/test/Gcm/ClientTest.php index 5760542..f6ab6cd 100644 --- a/test/Gcm/ClientTest.php +++ b/test/Gcm/ClientTest.php @@ -44,7 +44,7 @@ class ClientTest extends TestCase */ protected $message; - protected function _createJSONResponse($id, $success, $failure, $ids, $results) + protected function createJSONResponse($id, $success, $failure, $ids, $results) { return json_encode([ 'multicast_id' => $id, @@ -123,7 +123,7 @@ public function testSendThrowsExceptionWhenInvalidPayload() public function testSendResultInvalidRegistrationId() { - $body = $this->_createJSONResponse(101, 0, 1, 0, [['error' => 'InvalidRegistration']]); + $body = $this->createJSONResponse(101, 0, 1, 0, [['error' => 'InvalidRegistration']]); $this->httpAdapter->setResponse( 'HTTP/1.1 200 OK'."\r\n". 'Context-Type: text/html'."\r\n\r\n". @@ -140,7 +140,7 @@ public function testSendResultInvalidRegistrationId() public function testSendResultMismatchSenderId() { - $body = $this->_createJSONResponse(101, 0, 1, 0, [['error' => 'MismatchSenderId']]); + $body = $this->createJSONResponse(101, 0, 1, 0, [['error' => 'MismatchSenderId']]); $this->httpAdapter->setResponse( 'HTTP/1.1 200 OK'."\r\n". 'Context-Type: text/html'."\r\n\r\n". @@ -157,7 +157,7 @@ public function testSendResultMismatchSenderId() public function testSendResultNotRegistered() { - $body = $this->_createJSONResponse(101, 0, 1, 0, [['error' => 'NotRegistered']]); + $body = $this->createJSONResponse(101, 0, 1, 0, [['error' => 'NotRegistered']]); $this->httpAdapter->setResponse( 'HTTP/1.1 200 OK'."\r\n". 'Context-Type: text/html'."\r\n\r\n". @@ -174,7 +174,7 @@ public function testSendResultNotRegistered() public function testSendResultMessageTooBig() { - $body = $this->_createJSONResponse(101, 0, 1, 0, [['error' => 'MessageTooBig']]); + $body = $this->createJSONResponse(101, 0, 1, 0, [['error' => 'MessageTooBig']]); $this->httpAdapter->setResponse( 'HTTP/1.1 200 OK'."\r\n". 'Context-Type: text/html'."\r\n\r\n". @@ -191,7 +191,7 @@ public function testSendResultMessageTooBig() public function testSendResultSuccessful() { - $body = $this->_createJSONResponse(101, 1, 0, 0, [['message_id' => '1:2342']]); + $body = $this->createJSONResponse(101, 1, 0, 0, [['message_id' => '1:2342']]); $this->httpAdapter->setResponse( 'HTTP/1.1 200 OK'."\r\n". 'Context-Type: text/html'."\r\n\r\n". @@ -208,7 +208,7 @@ public function testSendResultSuccessful() public function testSendResultSuccessfulWithRegistrationId() { - $body = $this->_createJSONResponse(101, 1, 0, 1, [['message_id' => '1:2342', 'registration_id' => 'testfoo']]); + $body = $this->createJSONResponse(101, 1, 0, 1, [['message_id' => '1:2342', 'registration_id' => 'testfoo']]); $this->httpAdapter->setResponse( 'HTTP/1.1 200 OK'."\r\n". 'Context-Type: text/html'."\r\n\r\n". diff --git a/test/Gcm/MessageTest.php b/test/Gcm/MessageTest.php index d117400..496c5b3 100644 --- a/test/Gcm/MessageTest.php +++ b/test/Gcm/MessageTest.php @@ -104,16 +104,16 @@ public function testExpectedDataBehavior() public function testExpectedNotificationBehavior() { - $this->assertEquals($this->m->getNotification(), array()); + $this->assertEquals($this->m->getNotification(), []); $this->assertNotContains('notification', $this->m->toJson()); $this->m->setNotification($this->validData); $this->assertEquals($this->m->getNotification(), $this->validData); $this->assertContains('notification', $this->m->toJson()); $this->m->clearNotification(); - $this->assertEquals($this->m->getNotification(), array()); + $this->assertEquals($this->m->getNotification(), []); $this->assertNotContains('notification', $this->m->toJson()); $this->m->addNotification('mykey', 'myvalue'); - $this->assertEquals($this->m->getNotification(), array('mykey' => 'myvalue')); + $this->assertEquals($this->m->getNotification(), ['mykey' => 'myvalue']); $this->assertContains('notification', $this->m->toJson()); } From d46ea9d6e13ccdf83e3e07b3aa1a36c614e45f2b Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 8 May 2018 14:15:44 -0500 Subject: [PATCH 14/14] Adds CHANGELOG entry for #35 --- CHANGELOG.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb12d77..e106bb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,12 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. -## 2.1.0 - TBD +## 2.1.0 - 2018-05-08 ### Added +- [#35](https://github.com/zendframework/ZendService_Google_Gcm/pull/35) adds support for PHP 7.1 and 7.2. + - [#13](https://github.com/zendframework/ZendService_Google_Gcm/pull/13) adds constants mapping to common GCM error codes as `ZendService\Gcm\Response::ERROR_*`. ### Changed @@ -18,7 +20,9 @@ All notable changes to this project will be documented in this file, in reverse ### Removed -- Nothing. +- [#35](https://github.com/zendframework/ZendService_Google_Gcm/pull/35) removes support for PHP 5.5. + +- [#35](https://github.com/zendframework/ZendService_Google_Gcm/pull/35) removes support for HHVM. ### Fixed