laravel-6 support

This commit is contained in:
RafficMohammed
2023-01-08 01:17:22 +05:30
parent 1a5c16ae4b
commit 774eed8b0e
4962 changed files with 279380 additions and 297961 deletions

View File

@@ -1,4 +0,0 @@
.DS_STORE
composer.lock
composer.phar
vendor/

View File

@@ -1,21 +0,0 @@
language: php
matrix:
include:
- php: 5.6
- php: 7.0
- php: 7.1
env:
- CS_CHECK=true
- php: 7.2
- php: 7.3
before_install:
- composer install --no-interaction
script:
- ./vendor/bin/phpunit
- if [[ $CS_CHECK == 'true' ]]; then ./vendor/bin/phpcs ; fi
notifications:
email: false

View File

@@ -1,96 +0,0 @@
# Changelog
All notable changes to this project will be documented in this file, in reverse chronological order by release.
## 2.1.1 - 2019-02-07
### Added
- [#37](https://github.com/zendframework/ZendService_Google_Gcm/pull/37) adds support for PHP 7.3.
- [#38](https://github.com/zendframework/ZendService_Google_Gcm/pull/38) adds support for zend-json v3 releases.
### Changed
- Nothing.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- Nothing.
## 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
- Nothing.
### Deprecated
- Nothing.
### Removed
- [#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
- [#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
### Added
- [#27](https://github.com/zendframework/ZendService_Google_Gcm/pull/27) PSR-4 schema
- [#27](https://github.com/zendframework/ZendService_Google_Gcm/pull/27) PHP >= 5.5 & 7
- [#20](https://github.com/zendframework/ZendService_Google_Gcm/pull/25) Notification and priority parameters for FCM
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#27](https://github.com/zendframework/ZendService_Google_Gcm/pull/27) Fix travis CI integration
- [#27](https://github.com/zendframework/ZendService_Google_Gcm/pull/27) Fix coding style (use ::class and short arrays)
- [#27](https://github.com/zendframework/ZendService_Google_Gcm/pull/27) Fix docblocks for IDE integration
- [#20](https://github.com/zendframework/ZendService_Google_Gcm/pull/25) Change endpoint to FCM
## 1.0.3 - 2015-10-13
### Added
- Nothing.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#12](https://github.com/zendframework/ZendService_Google_Gcm/pull/12) -
Updated GCM URL.

View File

@@ -1,27 +0,0 @@
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 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.
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
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@@ -1,20 +0,0 @@
ZendService\Google\Gcm [![Build Status](https://api.travis-ci.org/zendframework/ZendService_Google_Gcm.svg?branch=develop)](https://travis-ci.org/zendframework/ZendService_Google_Gcm)
================================
Provides support for Google push notifications.
## Requirements
* PHP >= 5.6
## Getting Started
Install this library using [Composer](http://getcomposer.org/):
```bash
$ composer require zendframework/zendservice-google-gcm
```
## Documentation
The documentation can be found at: http://framework.zend.com/manual/current/en/modules/zendservice.google.gcm.html

View File

@@ -1,48 +0,0 @@
{
"name": "zendframework/zendservice-google-gcm",
"description": "OOP wrapper for Google Cloud Messaging",
"license": "BSD-3-Clause",
"keywords": [
"zf",
"zendframework",
"gcm",
"push",
"notification",
"google"
],
"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 || ^3.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/"
}
},
"autoload-dev": {
"psr-4": {
"ZendServiceTest\\Google\\": "test/"
}
},
"config": {
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "2.1.x-dev",
"dev-develop": "2.2.x-dev"
}
}
}

View File

@@ -1,7 +0,0 @@
<?xml version="1.0"?>
<ruleset name="Zend Framework Coding Standard">
<rule ref="./vendor/zendframework/zend-coding-standard/ruleset.xml"/>
<file>src</file>
<file>test</file>
</ruleset>

View File

@@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
<testsuite name="ZendService Google Gcm Test Suite">
<directory>./test</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>

View File

@@ -1,21 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/).
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
*
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*
* @category ZendService
*/
namespace ZendService\Google\Exception;
/**
* Invalid Argument Exception.
*
* @category ZendService
*/
class InvalidArgumentException extends \InvalidArgumentException
{
}

View File

@@ -1,21 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/).
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
*
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*
* @category ZendService
*/
namespace ZendService\Google\Exception;
/**
* Runtime Exception.
*
* @category ZendService
*/
class RuntimeException extends \RuntimeException
{
}

View File

@@ -1,156 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/).
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
*
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*
* @category ZendService
*/
namespace ZendService\Google\Gcm;
use ZendService\Google\Exception;
use Zend\Http\Client as HttpClient;
use Zend\Json\Json;
/**
* Google Cloud Messaging Client
* This class allows the ability to send out messages
* through the Google Cloud Messaging API.
*
* @category ZendService
*/
class Client
{
/**
* @const string Server URI
*/
const SERVER_URI = 'https://fcm.googleapis.com/fcm/send';
/**
* @var \Zend\Http\Client
*/
protected $httpClient;
/**
* @var string
*/
protected $apiKey;
/**
* Get API Key.
*
* @return string
*/
public function getApiKey()
{
return $this->apiKey;
}
/**
* Set API Key.
*
* @param string $apiKey
*
* @return Client
*
* @throws Exception\InvalidArgumentException
*/
public function setApiKey($apiKey)
{
if (! is_string($apiKey) || empty($apiKey)) {
throw new Exception\InvalidArgumentException('The api key must be a string and not empty');
}
$this->apiKey = $apiKey;
return $this;
}
/**
* Get HTTP Client.
*
* @throws \Zend\Http\Client\Exception\InvalidArgumentException
*
* @return \Zend\Http\Client
*/
public function getHttpClient()
{
if (! $this->httpClient) {
$this->httpClient = new HttpClient();
$this->httpClient->setOptions(['strictredirects' => true]);
}
return $this->httpClient;
}
/**
* Set HTTP Client.
*
* @param \Zend\Http\Client
*
* @return Client
*/
public function setHttpClient(HttpClient $http)
{
$this->httpClient = $http;
return $this;
}
/**
* Send Message.
*
* @param Message $message
*
* @throws \Zend\Json\Exception\RuntimeException
* @throws \ZendService\Google\Exception\RuntimeException
* @throws \Zend\Http\Exception\RuntimeException
* @throws \Zend\Http\Client\Exception\RuntimeException
* @throws \Zend\Http\Exception\InvalidArgumentException
* @throws \Zend\Http\Client\Exception\InvalidArgumentException
* @throws \ZendService\Google\Exception\InvalidArgumentException
*
* @return Response
*/
public function send(Message $message)
{
$client = $this->getHttpClient();
$client->setUri(self::SERVER_URI);
$headers = $client->getRequest()->getHeaders();
$headers->addHeaderLine('Authorization', 'key=' . $this->getApiKey());
$headers->addHeaderLine('Content-length', mb_strlen($message->toJson()));
$response = $client->setHeaders($headers)
->setMethod('POST')
->setRawBody($message->toJson())
->setEncType('application/json')
->send();
switch ($response->getStatusCode()) {
case 500:
throw new Exception\RuntimeException('500 Internal Server Error');
break;
case 503:
$exceptionMessage = '503 Server Unavailable';
if ($retry = $response->getHeaders()->get('Retry-After')) {
$exceptionMessage .= '; Retry After: '.$retry;
}
throw new Exception\RuntimeException($exceptionMessage);
break;
case 401:
throw new Exception\RuntimeException('401 Forbidden; Authentication Error');
break;
case 400:
throw new Exception\RuntimeException('400 Bad Request; invalid message');
break;
}
if (! $response = Json::decode($response->getBody(), Json::TYPE_ARRAY)) {
throw new Exception\RuntimeException('Response body did not contain a valid JSON response');
}
return new Response($response, $message);
}
}

View File

@@ -1,452 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/).
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
*
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*
* @category ZendService
*/
namespace ZendService\Google\Gcm;
use ZendService\Google\Exception;
use Zend\Json\Json;
/**
* Google Cloud Messaging Message
* This class defines a message to be sent
* through the Google Cloud Messaging API.
*
* @category ZendService
*/
class Message
{
/**
* @var array
*/
protected $registrationIds = [];
/**
* @var string
*/
protected $collapseKey;
/**
* @var string
*/
protected $priority = 'normal';
/**
* @var array
*/
protected $data = [];
/**
* @var array
*/
protected $notification = [];
/**
* @var bool
*/
protected $delayWhileIdle = false;
/**
* @var int
*/
protected $timeToLive = 2419200;
/**
* @var string
*/
protected $restrictedPackageName;
/**
* @var bool
*/
protected $dryRun = false;
/**
* Set Registration Ids.
*
* @param array $ids
*
* @throws \ZendService\Google\Exception\InvalidArgumentException
*
* @return Message
*/
public function setRegistrationIds(array $ids)
{
$this->clearRegistrationIds();
foreach ($ids as $id) {
$this->addRegistrationId($id);
}
return $this;
}
/**
* Get Registration Ids.
*
* @return array
*/
public function getRegistrationIds()
{
return $this->registrationIds;
}
/**
* Add Registration Ids.
*
* @param string $id
*
* @return Message
*
* @throws Exception\InvalidArgumentException
*/
public function addRegistrationId($id)
{
if (! is_string($id) || empty($id)) {
throw new Exception\InvalidArgumentException('$id must be a non-empty string');
}
if (! in_array($id, $this->registrationIds)) {
$this->registrationIds[] = $id;
}
return $this;
}
/**
* Clear Registration Ids.
*
* @return Message
*/
public function clearRegistrationIds()
{
$this->registrationIds = [];
return $this;
}
/**
* Get Collapse Key.
*
* @return string
*/
public function getCollapseKey()
{
return $this->collapseKey;
}
/**
* Set Collapse Key.
*
* @param string $key
*
* @return Message
*
* @throws Exception\InvalidArgumentException
*/
public function setCollapseKey($key)
{
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;
return $this;
}
/**
* Get priority
*
* @return string
*/
public function getPriority()
{
return $this->priority;
}
/**
* Set priority
*
* @param string $priority
* @return Message
* @throws Exception\InvalidArgumentException
*/
public function setPriority($priority)
{
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;
return $this;
}
/**
* Set Data
*
* @param array $data
*
* @throws \ZendService\Google\Exception\InvalidArgumentException
*
* @return Message
*/
public function setData(array $data)
{
$this->clearData();
foreach ($data as $k => $v) {
$this->addData($k, $v);
}
return $this;
}
/**
* Get Data.
*
* @return array
*/
public function getData()
{
return $this->data;
}
/**
* Add Data.
*
* @param string $key
* @param mixed $value
*
* @throws Exception\RuntimeException
* @throws Exception\InvalidArgumentException
*
* @return Message
*/
public function addData($key, $value)
{
if (! is_string($key) || empty($key)) {
throw new Exception\InvalidArgumentException('$key must be a non-empty string');
}
if (array_key_exists($key, $this->data)) {
throw new Exception\RuntimeException('$key conflicts with current set data');
}
$this->data[$key] = $value;
return $this;
}
/**
* Clear Data.
*
* @return Message
*/
public function clearData()
{
$this->data = [];
return $this;
}
/**
* Set notification
*
* @param array $data
* @return Message
*/
public function setNotification(array $data)
{
$this->clearNotification();
foreach ($data as $k => $v) {
$this->addNotification($k, $v);
}
return $this;
}
/**
* Get notification
*
* @return array
*/
public function getNotification()
{
return $this->notification;
}
/**
* Add notification data
*
* @param string $key
* @param mixed $value
* @return Message
* @throws Exception\InvalidArgumentException
* @throws Exception\RuntimeException
*/
public function addNotification($key, $value)
{
if (! is_string($key) || empty($key)) {
throw new Exception\InvalidArgumentException('$key must be a non-empty string');
}
if (array_key_exists($key, $this->notification)) {
throw new Exception\RuntimeException('$key conflicts with current set data');
}
$this->notification[$key] = $value;
return $this;
}
/**
* Clear notification
*
* @return Message
*/
public function clearNotification()
{
$this->notification = [];
return $this;
}
/**
* Set Delay While Idle
*
* @param bool $delay
*
* @return Message
*/
public function setDelayWhileIdle($delay)
{
$this->delayWhileIdle = (bool) $delay;
return $this;
}
/**
* Get Delay While Idle.
*
* @return bool
*/
public function getDelayWhileIdle()
{
return $this->delayWhileIdle;
}
/**
* Set Time to Live.
*
* @param int $ttl
*
* @return Message
*/
public function setTimeToLive($ttl)
{
$this->timeToLive = (int) $ttl;
return $this;
}
/**
* Get Time to Live.
*
* @return int
*/
public function getTimeToLive()
{
return $this->timeToLive;
}
/**
* Set Restricted Package Name.
*
* @param string $name
*
* @return Message
*
* @throws Exception\InvalidArgumentException
*/
public function setRestrictedPackageName($name)
{
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;
return $this;
}
/**
* Get Restricted Package Name.
*
* @return string
*/
public function getRestrictedPackageName()
{
return $this->restrictedPackageName;
}
/**
* Set Dry Run.
*
* @param bool $dryRun
*
* @return Message
*/
public function setDryRun($dryRun)
{
$this->dryRun = (bool) $dryRun;
return $this;
}
/**
* Get Dry Run.
*
* @return bool
*/
public function getDryRun()
{
return $this->dryRun;
}
/**
* To JSON
* Utility method to put the JSON into the
* GCM proper format for sending the message.
*
* @return string
*/
public function toJson()
{
$json = [];
if ($this->registrationIds) {
$json['registration_ids'] = $this->registrationIds;
}
if ($this->collapseKey) {
$json['collapse_key'] = $this->collapseKey;
}
if ($this->priority) {
$json['priority'] = $this->priority;
}
if ($this->data) {
$json['data'] = $this->data;
}
if ($this->notification) {
$json['notification'] = $this->notification;
}
if ($this->delayWhileIdle) {
$json['delay_while_idle'] = $this->delayWhileIdle;
}
if ($this->timeToLive != 2419200) {
$json['time_to_live'] = $this->timeToLive;
}
if ($this->restrictedPackageName) {
$json['restricted_package_name'] = $this->restrictedPackageName;
}
if ($this->dryRun) {
$json['dry_run'] = $this->dryRun;
}
return Json::encode($json);
}
}

View File

@@ -1,262 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/).
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
*
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*
* @category ZendService
*/
namespace ZendService\Google\Gcm;
use ZendService\Google\Exception;
/**
* Google Cloud Messaging Response
* This class parses out the response from
* the Google Cloud Messaging API.
*
* @category ZendService
*/
class Response
{
/**
* @const Message ID field
*/
const RESULT_MESSAGE_ID = 'message_id';
/**
* @const Error field
*/
const RESULT_ERROR = 'error';
/**
* @const Canonical field
*/
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
*/
protected $id;
/**
* @var int
*/
protected $cntSuccess;
/**
* @var int
*/
protected $cntFailure;
/**
* @var int
*/
protected $cntCanonical;
/**
* @var Message
*/
protected $message;
/**
* @var array
*/
protected $results;
/**
* @var array
*/
protected $response;
/**
* Constructor.
*
* @param string $response
* @param Message $message
*
* @return Response
*
* @throws \ZendService\Google\Exception\InvalidArgumentException
*/
public function __construct($response = null, Message $message = null)
{
if ($response) {
$this->setResponse($response);
}
if ($message) {
$this->setMessage($message);
}
}
/**
* Get Message.
*
* @return Message
*/
public function getMessage()
{
return $this->message;
}
/**
* Set Message.
*
* @param Message $message
*
* @return Response
*/
public function setMessage(Message $message)
{
$this->message = $message;
return $this;
}
/**
* Get Response.
*
* @return array
*/
public function getResponse()
{
return $this->response;
}
/**
* Set Response.
*
* @param array $response
*
* @return Response
*
* @throws Exception\InvalidArgumentException
*/
public function setResponse(array $response)
{
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');
}
$this->response = $response;
$this->results = $response['results'];
$this->cntSuccess = (int) $response['success'];
$this->cntFailure = (int) $response['failure'];
$this->cntCanonical = (int) $response['canonical_ids'];
$this->id = (int) $response['multicast_id'];
return $this;
}
/**
* Get Success Count.
*
* @return int
*/
public function getSuccessCount()
{
return $this->cntSuccess;
}
/**
* Get Failure Count.
*
* @return int
*/
public function getFailureCount()
{
return $this->cntFailure;
}
/**
* Get Canonical Count.
*
* @return int
*/
public function getCanonicalCount()
{
return $this->cntCanonical;
}
/**
* Get Results.
*
* @return array multi dimensional array of:
* NOTE: key is registration_id if the message is passed.
* 'registration_id' => [
* 'message_id' => 'id',
* 'error' => 'error',
* 'registration_id' => 'id'
* ]
*/
public function getResults()
{
return $this->correlate();
}
/**
* Get Singular Result.
*
* @param int $flag one of the RESULT_* flags
*
* @return array singular array with keys being registration id
* value is the type of result
*/
public function getResult($flag)
{
$ret = [];
foreach ($this->correlate() as $k => $v) {
if (isset($v[$flag])) {
$ret[$k] = $v[$flag];
}
}
return $ret;
}
/**
* Correlate Message and Result.
*
* @return array
*/
protected function correlate()
{
$results = $this->results;
if ($this->message && $results) {
$ids = $this->message->getRegistrationIds();
while ($id = array_shift($ids)) {
$results[$id] = array_shift($results);
}
}
return $results;
}
}

View File

@@ -1,226 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/).
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
*
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*
* @category ZendService
*/
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;
use ZendService\Google\Gcm\Message;
/**
* @category ZendService
* @group ZendService
* @group ZendService_Google
* @group ZendService_Google_Gcm
*/
class ClientTest extends TestCase
{
/**
* @var Test
*/
protected $httpAdapter;
/**
* @var HttpClient
*/
protected $httpClient;
/**
* @var Client
*/
protected $gcmClient;
/**
* @var Message
*/
protected $message;
protected function createJSONResponse($id, $success, $failure, $ids, $results)
{
return json_encode([
'multicast_id' => $id,
'success' => $success,
'failure' => $failure,
'canonical_ids' => $ids,
'results' => $results,
]);
}
public function setUp()
{
$this->httpClient = new HttpClient();
$this->httpAdapter = new Test();
$this->httpClient->setAdapter($this->httpAdapter);
$this->gcmClient = new Client();
$this->gcmClient->setHttpClient($this->httpClient);
$this->gcmClient->setApiKey('testing');
$this->message = new Message();
$this->message->addRegistrationId('testing');
$this->message->addData('testKey', 'testValue');
}
public function testSetApiKeyThrowsExceptionOnNonString()
{
$this->expectException('InvalidArgumentException');
$this->gcmClient->setApiKey([]);
}
public function testSetApiKey()
{
$key = 'a-login-token';
$this->gcmClient->setApiKey($key);
self::assertEquals($key, $this->gcmClient->getApiKey());
}
public function testGetHttpClientReturnsDefault()
{
self::assertInstanceOf('Zend\Http\Client', (new Client())->getHttpClient());
}
public function testSetHttpClient()
{
$client = new HttpClient();
$this->gcmClient->setHttpClient($client);
self::assertEquals($client, $this->gcmClient->getHttpClient());
}
public function testSendThrowsExceptionWhenServiceUnavailable()
{
$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->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->expectException('RuntimeException');
$this->httpAdapter->setResponse('HTTP/1.1 401 Unauthorized'."\r\n\r\n");
$this->gcmClient->send($this->message);
}
public function testSendThrowsExceptionWhenInvalidPayload()
{
$this->expectException('RuntimeException');
$this->httpAdapter->setResponse('HTTP/1.1 400 Bad Request'."\r\n\r\n");
$this->gcmClient->send($this->message);
}
public function testSendResultInvalidRegistrationId()
{
$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".
$body
);
$response = $this->gcmClient->send($this->message);
$result = $response->getResults();
$result = array_shift($result);
self::assertEquals('InvalidRegistration', $result['error']);
self::assertEquals(0, $response->getSuccessCount());
self::assertEquals(0, $response->getCanonicalCount());
self::assertEquals(1, $response->getFailureCount());
}
public function testSendResultMismatchSenderId()
{
$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".
$body
);
$response = $this->gcmClient->send($this->message);
$result = $response->getResults();
$result = array_shift($result);
self::assertEquals('MismatchSenderId', $result['error']);
self::assertEquals(0, $response->getSuccessCount());
self::assertEquals(0, $response->getCanonicalCount());
self::assertEquals(1, $response->getFailureCount());
}
public function testSendResultNotRegistered()
{
$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".
$body
);
$response = $this->gcmClient->send($this->message);
$result = $response->getResults();
$result = array_shift($result);
self::assertEquals('NotRegistered', $result['error']);
self::assertEquals(0, $response->getSuccessCount());
self::assertEquals(0, $response->getCanonicalCount());
self::assertEquals(1, $response->getFailureCount());
}
public function testSendResultMessageTooBig()
{
$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".
$body
);
$response = $this->gcmClient->send($this->message);
$result = $response->getResults();
$result = array_shift($result);
self::assertEquals('MessageTooBig', $result['error']);
self::assertEquals(0, $response->getSuccessCount());
self::assertEquals(0, $response->getCanonicalCount());
self::assertEquals(1, $response->getFailureCount());
}
public function testSendResultSuccessful()
{
$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".
$body
);
$response = $this->gcmClient->send($this->message);
$result = $response->getResults();
$result = array_shift($result);
self::assertEquals('1:2342', $result['message_id']);
self::assertEquals(1, $response->getSuccessCount());
self::assertEquals(0, $response->getCanonicalCount());
self::assertEquals(0, $response->getFailureCount());
}
public function testSendResultSuccessfulWithRegistrationId()
{
$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".
$body
);
$response = $this->gcmClient->send($this->message);
$result = $response->getResults();
$result = array_shift($result);
self::assertEquals('1:2342', $result['message_id']);
self::assertEquals('testfoo', $result['registration_id']);
self::assertEquals(1, $response->getSuccessCount());
self::assertEquals(1, $response->getCanonicalCount());
self::assertEquals(0, $response->getFailureCount());
}
}

View File

@@ -1,186 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/).
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
*
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*
* @category ZendService
*/
namespace ZendServiceTest\Google\Gcm;
use PHPUnit\Framework\TestCase;
use ZendService\Google\Gcm\Message;
/**
* @category ZendService
* @group ZendService
* @group ZendService_Google
* @group ZendService_Google_Gcm
*/
class MessageTest extends TestCase
{
protected $validRegistrationIds = [
'1234567890',
'0987654321',
];
protected $validData = [
'key' => 'value',
'key2' => [
'value',
],
];
/**
* @var Message
*/
private $m;
public function setUp()
{
$this->m = new Message();
}
public function testExpectedRegistrationIdBehavior()
{
self::assertEquals($this->m->getRegistrationIds(), []);
self::assertNotContains('registration_ids', $this->m->toJson());
$this->m->setRegistrationIds($this->validRegistrationIds);
self::assertEquals($this->m->getRegistrationIds(), $this->validRegistrationIds);
foreach ($this->validRegistrationIds as $id) {
$this->m->addRegistrationId($id);
}
self::assertEquals($this->m->getRegistrationIds(), $this->validRegistrationIds);
self::assertContains('registration_ids', $this->m->toJson());
$this->m->clearRegistrationIds();
self::assertEquals($this->m->getRegistrationIds(), []);
self::assertNotContains('registration_ids', $this->m->toJson());
$this->m->addRegistrationId('1029384756');
self::assertEquals($this->m->getRegistrationIds(), ['1029384756']);
self::assertContains('registration_ids', $this->m->toJson());
}
public function testInvalidRegistrationIdThrowsException()
{
$this->expectException(\InvalidArgumentException::class);
$this->m->addRegistrationId(['1234']);
}
public function testExpectedCollapseKeyBehavior()
{
self::assertEquals($this->m->getCollapseKey(), null);
self::assertNotContains('collapse_key', $this->m->toJson());
$this->m->setCollapseKey('my collapse key');
self::assertEquals($this->m->getCollapseKey(), 'my collapse key');
self::assertContains('collapse_key', $this->m->toJson());
$this->m->setCollapseKey(null);
self::assertEquals($this->m->getCollapseKey(), null);
self::assertNotContains('collapse_key', $this->m->toJson());
}
public function testInvalidCollapseKeyThrowsException()
{
$this->expectException(\InvalidArgumentException::class);
$this->m->setCollapseKey(['1234']);
}
public function testExpectedDataBehavior()
{
self::assertEquals($this->m->getData(), []);
self::assertNotContains('data', $this->m->toJson());
$this->m->setData($this->validData);
self::assertEquals($this->m->getData(), $this->validData);
self::assertContains('data', $this->m->toJson());
$this->m->clearData();
self::assertEquals($this->m->getData(), []);
self::assertNotContains('data', $this->m->toJson());
$this->m->addData('mykey', 'myvalue');
self::assertEquals($this->m->getData(), ['mykey' => 'myvalue']);
self::assertContains('data', $this->m->toJson());
}
public function testExpectedNotificationBehavior()
{
$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(), []);
$this->assertNotContains('notification', $this->m->toJson());
$this->m->addNotification('mykey', 'myvalue');
$this->assertEquals($this->m->getNotification(), ['mykey' => 'myvalue']);
$this->assertContains('notification', $this->m->toJson());
}
public function testInvalidDataThrowsException()
{
$this->expectException(\InvalidArgumentException::class);
$this->m->addData(['1234'], 'value');
}
public function testDuplicateDataKeyThrowsException()
{
$this->expectException(\RuntimeException::class);
$this->m->setData($this->validData);
$this->m->addData('key', 'value');
}
public function testExpectedDelayWhileIdleBehavior()
{
self::assertEquals($this->m->getDelayWhileIdle(), false);
self::assertNotContains('delay_while_idle', $this->m->toJson());
$this->m->setDelayWhileIdle(true);
self::assertEquals($this->m->getDelayWhileIdle(), true);
self::assertContains('delay_while_idle', $this->m->toJson());
$this->m->setDelayWhileIdle(false);
self::assertEquals($this->m->getDelayWhileIdle(), false);
self::assertNotContains('delay_while_idle', $this->m->toJson());
}
public function testExpectedTimeToLiveBehavior()
{
self::assertEquals($this->m->getTimeToLive(), 2419200);
self::assertNotContains('time_to_live', $this->m->toJson());
$this->m->setTimeToLive(12345);
self::assertEquals($this->m->getTimeToLive(), 12345);
self::assertContains('time_to_live', $this->m->toJson());
$this->m->setTimeToLive(2419200);
self::assertEquals($this->m->getTimeToLive(), 2419200);
self::assertNotContains('time_to_live', $this->m->toJson());
}
public function testExpectedRestrictedPackageBehavior()
{
self::assertEquals($this->m->getRestrictedPackageName(), null);
self::assertNotContains('restricted_package_name', $this->m->toJson());
$this->m->setRestrictedPackageName('my.package.name');
self::assertEquals($this->m->getRestrictedPackageName(), 'my.package.name');
self::assertContains('restricted_package_name', $this->m->toJson());
$this->m->setRestrictedPackageName(null);
self::assertEquals($this->m->getRestrictedPackageName(), null);
self::assertNotContains('restricted_package_name', $this->m->toJson());
}
public function testInvalidRestrictedPackageThrowsException()
{
$this->expectException(\InvalidArgumentException::class);
$this->m->setRestrictedPackageName(['1234']);
}
public function testExpectedDryRunBehavior()
{
self::assertEquals($this->m->getDryRun(), false);
self::assertNotContains('dry_run', $this->m->toJson());
$this->m->setDryRun(true);
self::assertEquals($this->m->getDryRun(), true);
self::assertContains('dry_run', $this->m->toJson());
$this->m->setDryRun(false);
self::assertEquals($this->m->getDryRun(), false);
self::assertNotContains('dry_run', $this->m->toJson());
}
}

View File

@@ -1,119 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/).
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
*
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*
* @category ZendService
*/
namespace ZendServiceTest\Google\Gcm;
use PHPUnit\Framework\TestCase;
use ZendService\Google\Gcm\Message;
use ZendService\Google\Gcm\Response;
/**
* @category ZendService
* @group ZendService
* @group ZendService_Google
* @group ZendService_Google_Gcm
*/
class ResponseTest extends TestCase
{
/**
* @var Message
*/
private $m;
public function setUp()
{
$this->m = new Message();
}
public function testConstructorExpectedBehavior()
{
$response = new Response();
self::assertNull($response->getResponse());
self::assertNull($response->getMessage());
$message = new Message();
$response = new Response(null, $message);
self::assertEquals($message, $response->getMessage());
self::assertNull($response->getResponse());
$message = new Message();
$responseArray = [
'results' => [
['message_id' => '1:1234'],
],
'success' => 1,
'failure' => 0,
'canonical_ids' => 0,
'multicast_id' => 1,
];
$response = new Response($responseArray, $message);
self::assertEquals($responseArray, $response->getResponse());
self::assertEquals($message, $response->getMessage());
}
public function testInvalidConstructorThrowsException()
{
if (PHP_VERSION_ID < 70000) {
self::markTestSkipped('PHP 7 required.');
}
$this->expectException(\TypeError::class);
new Response('{bad');
}
public function testInvalidConstructorThrowsExceptionOnPhp7()
{
if (PHP_VERSION_ID >= 70000) {
self::markTestSkipped('PHP >=5.5 required.');
}
$this->expectException(\PHPUnit_Framework_Error::class);
new Response('{bad');
}
public function testMessageExpectedBehavior()
{
$message = new Message();
$response = new Response();
$response->setMessage($message);
self::assertEquals($message, $response->getMessage());
}
public function testResponse()
{
$responseArr = [
'results' => [
['message_id' => '1:234'],
],
'success' => 1,
'failure' => 0,
'canonical_ids' => 0,
'multicast_id' => '123',
];
$response = new Response();
$response->setResponse($responseArr);
self::assertEquals($responseArr, $response->getResponse());
self::assertEquals(1, $response->getSuccessCount());
self::assertEquals(0, $response->getFailureCount());
self::assertEquals(0, $response->getCanonicalCount());
// test results non correlated
$expected = [['message_id' => '1:234']];
self::assertEquals($expected, $response->getResults());
$expected = [0 => '1:234'];
self::assertEquals($expected, $response->getResult(Response::RESULT_MESSAGE_ID));
$message = new Message();
$message->setRegistrationIds(['ABCDEF']);
$response->setMessage($message);
$expected = ['ABCDEF' => '1:234'];
self::assertEquals($expected, $response->getResult(Response::RESULT_MESSAGE_ID));
}
}