seeder-migration-issues
This commit is contained in:
4
vendor/zendframework/zendservice-google-gcm/.gitignore
vendored
Normal file
4
vendor/zendframework/zendservice-google-gcm/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
.DS_STORE
|
||||
composer.lock
|
||||
composer.phar
|
||||
vendor/
|
||||
18
vendor/zendframework/zendservice-google-gcm/.travis.yml
vendored
Normal file
18
vendor/zendframework/zendservice-google-gcm/.travis.yml
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.3
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
- hhvm
|
||||
|
||||
before_install:
|
||||
- cp tests/TestConfiguration.php.travis tests/TestConfiguration.php
|
||||
- composer install --dev
|
||||
|
||||
script:
|
||||
- phpunit -c tests/phpunit.xml.dist
|
||||
|
||||
notifications:
|
||||
irc: "irc.freenode.org#zftalk.2"
|
||||
22
vendor/zendframework/zendservice-google-gcm/CHANGELOG.md
vendored
Normal file
22
vendor/zendframework/zendservice-google-gcm/CHANGELOG.md
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file, in reverse chronological order by release.
|
||||
|
||||
## 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.
|
||||
27
vendor/zendframework/zendservice-google-gcm/LICENSE.txt
vendored
Executable file
27
vendor/zendframework/zendservice-google-gcm/LICENSE.txt
vendored
Executable file
@@ -0,0 +1,27 @@
|
||||
Copyright (c) 2005-2014, 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.
|
||||
20
vendor/zendframework/zendservice-google-gcm/README.md
vendored
Executable file
20
vendor/zendframework/zendservice-google-gcm/README.md
vendored
Executable file
@@ -0,0 +1,20 @@
|
||||
ZendService\Google\Gcm [](https://travis-ci.org/zendframework/ZendService_Google_Gcm)
|
||||
================================
|
||||
|
||||
Provides support for Google push notifications.
|
||||
|
||||
## Requirements ##
|
||||
|
||||
* PHP >= 5.3.3
|
||||
|
||||
## 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
|
||||
34
vendor/zendframework/zendservice-google-gcm/composer.json
vendored
Executable file
34
vendor/zendframework/zendservice-google-gcm/composer.json
vendored
Executable file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "zendframework/zendservice-google-gcm",
|
||||
"description": "OOP wrapper for Google Cloud Messaging",
|
||||
"type": "library",
|
||||
"keywords": [
|
||||
"zf2",
|
||||
"gcm",
|
||||
"push",
|
||||
"notification",
|
||||
"google"
|
||||
],
|
||||
"homepage": "http://packages.zendframework.com/",
|
||||
"license": "BSD-3-Clause",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"ZendService\\Google\\Gcm\\": "library/",
|
||||
"ZendService\\Google\\Exception\\": "library/"
|
||||
}
|
||||
},
|
||||
"repositories": [
|
||||
{
|
||||
"type": "composer",
|
||||
"url": "http://packages.zendframework.com/"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.3",
|
||||
"zendframework/zend-http": ">=2.0.0",
|
||||
"zendframework/zend-json": ">=2.0.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/PHPUnit": "3.7.*"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?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
|
||||
* @package ZendService_Google
|
||||
*/
|
||||
|
||||
namespace ZendService\Google\Exception;
|
||||
|
||||
/**
|
||||
* Invalid Argument Exception
|
||||
*
|
||||
* @category ZendService
|
||||
* @package ZendService_Google
|
||||
*/
|
||||
class InvalidArgumentException extends \InvalidArgumentException
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?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
|
||||
* @package ZendService_Google
|
||||
*/
|
||||
|
||||
namespace ZendService\Google\Exception;
|
||||
|
||||
/**
|
||||
* Runtime Exception
|
||||
*
|
||||
* @category ZendService
|
||||
* @package ZendService_Google
|
||||
*/
|
||||
class RuntimeException extends \RuntimeException
|
||||
{
|
||||
}
|
||||
141
vendor/zendframework/zendservice-google-gcm/library/ZendService/Google/Gcm/Client.php
vendored
Normal file
141
vendor/zendframework/zendservice-google-gcm/library/ZendService/Google/Gcm/Client.php
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
<?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
|
||||
* @package ZendService_Google\Gcm
|
||||
*/
|
||||
|
||||
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
|
||||
* @package ZendService_Google
|
||||
* @subpackage Gcm
|
||||
*/
|
||||
class Client
|
||||
{
|
||||
/**
|
||||
* @const string Server URI
|
||||
*/
|
||||
const SERVER_URI = 'https://gcm-http.googleapis.com/gcm/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 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
|
||||
*
|
||||
* @return Zend\Http\Client
|
||||
*/
|
||||
public function getHttpClient()
|
||||
{
|
||||
if (!$this->httpClient) {
|
||||
$this->httpClient = new HttpClient();
|
||||
$this->httpClient->setOptions(array('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 Mesage $message
|
||||
* @return Response
|
||||
* @throws Exception\RuntimeException
|
||||
*/
|
||||
public function send(Message $message)
|
||||
{
|
||||
$client = $this->getHttpClient();
|
||||
$client->setUri(self::SERVER_URI);
|
||||
$headers = $client->getRequest()->getHeaders();
|
||||
$headers->addHeaderLine('Authorization', 'key=' . $this->getApiKey());
|
||||
|
||||
$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);
|
||||
}
|
||||
}
|
||||
325
vendor/zendframework/zendservice-google-gcm/library/ZendService/Google/Gcm/Message.php
vendored
Normal file
325
vendor/zendframework/zendservice-google-gcm/library/ZendService/Google/Gcm/Message.php
vendored
Normal file
@@ -0,0 +1,325 @@
|
||||
<?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
|
||||
* @package ZendService_Google\Gcm
|
||||
*/
|
||||
|
||||
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
|
||||
* @package ZendService_Google
|
||||
* @subpackage Gcm
|
||||
*/
|
||||
class Message
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $registrationIds = array();
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $collapseKey;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $data = array();
|
||||
|
||||
/**
|
||||
* @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
|
||||
* @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 = array();
|
||||
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 (!is_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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Data
|
||||
*
|
||||
* @param array $data
|
||||
* @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
|
||||
* @return Message
|
||||
* @throws Exception\InvalidArgumentException
|
||||
* @throws Exception\RuntimeException
|
||||
*/
|
||||
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 = array();
|
||||
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 (!is_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 = array();
|
||||
if ($this->registrationIds) {
|
||||
$json['registration_ids'] = $this->registrationIds;
|
||||
}
|
||||
if ($this->collapseKey) {
|
||||
$json['collapse_key'] = $this->collapseKey;
|
||||
}
|
||||
if ($this->data) {
|
||||
$json['data'] = $this->data;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
234
vendor/zendframework/zendservice-google-gcm/library/ZendService/Google/Gcm/Response.php
vendored
Normal file
234
vendor/zendframework/zendservice-google-gcm/library/ZendService/Google/Gcm/Response.php
vendored
Normal file
@@ -0,0 +1,234 @@
|
||||
<?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
|
||||
* @package ZendService_Google
|
||||
* @subpackage Gcm
|
||||
*/
|
||||
|
||||
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
|
||||
* @package ZendService_Google
|
||||
* @subpackage Gcm
|
||||
*/
|
||||
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';
|
||||
|
||||
/**
|
||||
* @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 Exception\ServerUnavailable
|
||||
*/
|
||||
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']) ||
|
||||
!isset($response['success']) ||
|
||||
!isset($response['failure']) ||
|
||||
!isset($response['canonical_ids']) ||
|
||||
!isset($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' => array(
|
||||
* '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 = array();
|
||||
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;
|
||||
}
|
||||
}
|
||||
2
vendor/zendframework/zendservice-google-gcm/tests/.gitignore
vendored
Executable file
2
vendor/zendframework/zendservice-google-gcm/tests/.gitignore
vendored
Executable file
@@ -0,0 +1,2 @@
|
||||
phpunit.xml
|
||||
TestConfiguration.php
|
||||
92
vendor/zendframework/zendservice-google-gcm/tests/Bootstrap.php
vendored
Executable file
92
vendor/zendframework/zendservice-google-gcm/tests/Bootstrap.php
vendored
Executable file
@@ -0,0 +1,92 @@
|
||||
<?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
|
||||
* @package Zend
|
||||
*/
|
||||
|
||||
/*
|
||||
* Set error reporting to the level to which Zend Framework code must comply.
|
||||
*/
|
||||
error_reporting(E_ALL | E_STRICT);
|
||||
|
||||
$phpUnitVersion = PHPUnit_Runner_Version::id();
|
||||
if ('@package_version@' !== $phpUnitVersion && version_compare($phpUnitVersion, '3.5.0', '<')) {
|
||||
echo 'This version of PHPUnit (' . PHPUnit_Runner_Version::id() . ') is not supported in Zend Framework 2.x unit tests.' . PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
unset($phpUnitVersion);
|
||||
|
||||
/*
|
||||
* Determine the root, library, and tests directories of the framework
|
||||
* distribution.
|
||||
*/
|
||||
$zfRoot = realpath(dirname(__DIR__));
|
||||
$zfCoreLibrary = "$zfRoot/library";
|
||||
$zfCoreTests = "$zfRoot/tests";
|
||||
|
||||
/*
|
||||
* Prepend the Zend Framework library/ and tests/ directories to the
|
||||
* include_path. This allows the tests to run out of the box and helps prevent
|
||||
* loading other copies of the framework code and tests that would supersede
|
||||
* this copy.
|
||||
*/
|
||||
$path = array(
|
||||
$zfCoreLibrary,
|
||||
$zfCoreTests,
|
||||
get_include_path(),
|
||||
);
|
||||
set_include_path(implode(PATH_SEPARATOR, $path));
|
||||
|
||||
/**
|
||||
* Setup autoloading
|
||||
*/
|
||||
include __DIR__ . '/_autoload.php';
|
||||
|
||||
/*
|
||||
* Load the user-defined test configuration file, if it exists; otherwise, load
|
||||
* the default configuration.
|
||||
*/
|
||||
if (is_readable($zfCoreTests . DIRECTORY_SEPARATOR . 'TestConfiguration.php')) {
|
||||
require_once $zfCoreTests . DIRECTORY_SEPARATOR . 'TestConfiguration.php';
|
||||
} else {
|
||||
require_once $zfCoreTests . DIRECTORY_SEPARATOR . 'TestConfiguration.php.dist';
|
||||
}
|
||||
|
||||
if (defined('TESTS_GENERATE_REPORT') && TESTS_GENERATE_REPORT === true) {
|
||||
$codeCoverageFilter = PHP_CodeCoverage_Filter::getInstance();
|
||||
|
||||
$lastArg = end($_SERVER['argv']);
|
||||
if (is_dir($zfCoreTests . '/' . $lastArg)) {
|
||||
$codeCoverageFilter->addDirectoryToWhitelist($zfCoreLibrary . '/' . $lastArg);
|
||||
} elseif (is_file($zfCoreTests . '/' . $lastArg)) {
|
||||
$codeCoverageFilter->addDirectoryToWhitelist(dirname($zfCoreLibrary . '/' . $lastArg));
|
||||
} else {
|
||||
$codeCoverageFilter->addDirectoryToWhitelist($zfCoreLibrary);
|
||||
}
|
||||
|
||||
/*
|
||||
* Omit from code coverage reports the contents of the tests directory
|
||||
*/
|
||||
$codeCoverageFilter->addDirectoryToBlacklist($zfCoreTests, '');
|
||||
$codeCoverageFilter->addDirectoryToBlacklist(PEAR_INSTALL_DIR, '');
|
||||
$codeCoverageFilter->addDirectoryToBlacklist(PHP_LIBDIR, '');
|
||||
|
||||
unset($codeCoverageFilter);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Start output buffering, if enabled
|
||||
*/
|
||||
if (defined('TESTS_ZEND_OB_ENABLED') && constant('TESTS_ZEND_OB_ENABLED')) {
|
||||
ob_start();
|
||||
}
|
||||
|
||||
/*
|
||||
* Unset global variables that are no longer needed.
|
||||
*/
|
||||
unset($zfRoot, $zfCoreLibrary, $zfCoreTests, $path);
|
||||
45
vendor/zendframework/zendservice-google-gcm/tests/TestConfiguration.php.dist
vendored
Executable file
45
vendor/zendframework/zendservice-google-gcm/tests/TestConfiguration.php.dist
vendored
Executable file
@@ -0,0 +1,45 @@
|
||||
<?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
|
||||
* @package UnitTests
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file defines configuration for running the unit tests for the Zend
|
||||
* Framework. Some tests have dependencies to PHP extensions or databases
|
||||
* which may not necessary installed on the target system. For these cases,
|
||||
* the ability to disable or configure testing is provided below. Tests for
|
||||
* components which should run universally are always run by the master
|
||||
* suite and cannot be disabled.
|
||||
*
|
||||
* Do not edit this file. Instead, copy this file to TestConfiguration.php,
|
||||
* and edit the new file. Never commit passwords to the source code repository.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Use the notation:
|
||||
*
|
||||
* defined(...) || define(...);
|
||||
*
|
||||
* This ensures that, when a test is marked to run in a separate process,
|
||||
* PHP will not complain of a constant already being defined.
|
||||
*/
|
||||
|
||||
/**
|
||||
* GENERAL SETTINGS
|
||||
*
|
||||
* OB_ENABLED should be enabled for some tests to check if all functionality
|
||||
* works as expected. Such tests include those for Zend\Soap and Zend\Session,
|
||||
* which require that headers not be sent in order to work.
|
||||
*/
|
||||
defined('TESTS_ZEND_OB_ENABLED') || define('TESTS_ZEND_OB_ENABLED', false);
|
||||
|
||||
/**
|
||||
* PHPUnit Code Coverage / Test Report
|
||||
*/
|
||||
defined('TESTS_GENERATE_REPORT') || define('TESTS_GENERATE_REPORT', false);
|
||||
defined('TESTS_GENERATE_REPORT_TARGET') || define('TESTS_GENERATE_REPORT_TARGET', '/path/to/target');
|
||||
20
vendor/zendframework/zendservice-google-gcm/tests/TestConfiguration.php.travis
vendored
Executable file
20
vendor/zendframework/zendservice-google-gcm/tests/TestConfiguration.php.travis
vendored
Executable file
@@ -0,0 +1,20 @@
|
||||
<?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
|
||||
* @package UnitTests
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file defines specific configuration that differs from the standard configuration
|
||||
* for running the unit tests with Travis-CI (http://www.travis-ci.org)
|
||||
*
|
||||
* See TestConfiguration.php.dist to get more details.
|
||||
*
|
||||
* Never commit passwords to the source code repository.
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/TestConfiguration.php.dist';
|
||||
217
vendor/zendframework/zendservice-google-gcm/tests/ZendService/Google/Gcm/ClientTest.php
vendored
Normal file
217
vendor/zendframework/zendservice-google-gcm/tests/ZendService/Google/Gcm/ClientTest.php
vendored
Normal file
@@ -0,0 +1,217 @@
|
||||
<?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
|
||||
* @package ZendService_Google
|
||||
* @subpackage UnitTests
|
||||
*/
|
||||
|
||||
namespace ZendServiceTest\Google\Gcm;
|
||||
|
||||
use Zend\Http\Client\Adapter\Test;
|
||||
use Zend\Http\Client as HttpClient;
|
||||
use ZendService\Google\Gcm\Client;
|
||||
use ZendService\Google\Gcm\Message;
|
||||
use ZendService\Google\Gcm\Response;
|
||||
|
||||
/**
|
||||
* @category ZendService
|
||||
* @package ZendService_Google
|
||||
* @subpackage UnitTests
|
||||
* @group ZendService
|
||||
* @group ZendService_Google
|
||||
* @group ZendService_Google_Gcm
|
||||
*/
|
||||
class ClientTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $httpAdapter;
|
||||
protected $httpClient;
|
||||
protected $gcmClient;
|
||||
protected $message;
|
||||
|
||||
protected function _createJSONResponse($id, $success, $failure, $ids, $results)
|
||||
{
|
||||
return json_encode(array(
|
||||
'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->setExpectedException('InvalidArgumentException');
|
||||
$this->gcmClient->setApiKey(array());
|
||||
}
|
||||
|
||||
public function testSetApiKey()
|
||||
{
|
||||
$key = 'a-login-token';
|
||||
$this->gcmClient->setApiKey($key);
|
||||
$this->assertEquals($key, $this->gcmClient->getApiKey());
|
||||
}
|
||||
|
||||
public function testGetHttpClientReturnsDefault()
|
||||
{
|
||||
$gcm = new Client();
|
||||
$this->assertEquals('Zend\Http\Client', get_class($gcm->getHttpClient()));
|
||||
$this->assertTrue($gcm->getHttpClient() instanceof HttpClient);
|
||||
}
|
||||
|
||||
public function testSetHttpClient()
|
||||
{
|
||||
$client = new HttpClient();
|
||||
$this->gcmClient->setHttpClient($client);
|
||||
$this->assertEquals($client, $this->gcmClient->getHttpClient());
|
||||
}
|
||||
|
||||
public function testSendThrowsExceptionWhenServiceUnavailable()
|
||||
{
|
||||
$this->setExpectedException('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->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->httpAdapter->setResponse('HTTP/1.1 401 Unauthorized' . "\r\n\r\n");
|
||||
$this->gcmClient->send($this->message);
|
||||
}
|
||||
|
||||
public function testSendThrowsExceptionWhenInvalidPayload()
|
||||
{
|
||||
$this->setExpectedException('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, array(array('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);
|
||||
$this->assertEquals('InvalidRegistration', $result['error']);
|
||||
$this->assertEquals(0, $response->getSuccessCount());
|
||||
$this->assertEquals(0, $response->getCanonicalCount());
|
||||
$this->assertEquals(1, $response->getFailureCount());
|
||||
}
|
||||
|
||||
public function testSendResultMismatchSenderId()
|
||||
{
|
||||
$body = $this->_createJSONResponse(101, 0, 1, 0, array(array('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);
|
||||
$this->assertEquals('MismatchSenderId', $result['error']);
|
||||
$this->assertEquals(0, $response->getSuccessCount());
|
||||
$this->assertEquals(0, $response->getCanonicalCount());
|
||||
$this->assertEquals(1, $response->getFailureCount());
|
||||
}
|
||||
|
||||
public function testSendResultNotRegistered()
|
||||
{
|
||||
$body = $this->_createJSONResponse(101, 0, 1, 0, array(array('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);
|
||||
$this->assertEquals('NotRegistered', $result['error']);
|
||||
$this->assertEquals(0, $response->getSuccessCount());
|
||||
$this->assertEquals(0, $response->getCanonicalCount());
|
||||
$this->assertEquals(1, $response->getFailureCount());
|
||||
}
|
||||
|
||||
public function testSendResultMessageTooBig()
|
||||
{
|
||||
$body = $this->_createJSONResponse(101, 0, 1, 0, array(array('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);
|
||||
$this->assertEquals('MessageTooBig', $result['error']);
|
||||
$this->assertEquals(0, $response->getSuccessCount());
|
||||
$this->assertEquals(0, $response->getCanonicalCount());
|
||||
$this->assertEquals(1, $response->getFailureCount());
|
||||
}
|
||||
|
||||
public function testSendResultSuccessful()
|
||||
{
|
||||
$body = $this->_createJSONResponse(101, 1, 0, 0, array(array('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);
|
||||
$this->assertEquals('1:2342', $result['message_id']);
|
||||
$this->assertEquals(1, $response->getSuccessCount());
|
||||
$this->assertEquals(0, $response->getCanonicalCount());
|
||||
$this->assertEquals(0, $response->getFailureCount());
|
||||
}
|
||||
|
||||
public function testSendResultSuccessfulWithRegistrationId()
|
||||
{
|
||||
$body = $this->_createJSONResponse(101, 1, 0, 1, array(array('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);
|
||||
$this->assertEquals('1:2342', $result['message_id']);
|
||||
$this->assertEquals('testfoo', $result['registration_id']);
|
||||
$this->assertEquals(1, $response->getSuccessCount());
|
||||
$this->assertEquals(1, $response->getCanonicalCount());
|
||||
$this->assertEquals(0, $response->getFailureCount());
|
||||
}
|
||||
}
|
||||
159
vendor/zendframework/zendservice-google-gcm/tests/ZendService/Google/Gcm/MessageTest.php
vendored
Normal file
159
vendor/zendframework/zendservice-google-gcm/tests/ZendService/Google/Gcm/MessageTest.php
vendored
Normal file
@@ -0,0 +1,159 @@
|
||||
<?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
|
||||
* @package ZendService_Google
|
||||
* @subpackage UnitTests
|
||||
*/
|
||||
|
||||
namespace ZendServiceTest\Google\Gcm;
|
||||
|
||||
use ZendService\Google\Gcm\Message;
|
||||
|
||||
/**
|
||||
* @category ZendService
|
||||
* @package ZendService_Google
|
||||
* @subpackage UnitTests
|
||||
* @group ZendService
|
||||
* @group ZendService_Google
|
||||
* @group ZendService_Google_Gcm
|
||||
*/
|
||||
class MessageTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $validRegistrationIds = array('1234567890', '0987654321');
|
||||
protected $validData = array('key' => 'value', 'key2' => array('value'));
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->m = new Message();
|
||||
}
|
||||
|
||||
public function testExpectedRegistrationIdBehavior()
|
||||
{
|
||||
$this->assertEquals($this->m->getRegistrationIds(), array());
|
||||
$this->assertNotContains('registration_ids', $this->m->toJson());
|
||||
$this->m->setRegistrationIds($this->validRegistrationIds);
|
||||
$this->assertEquals($this->m->getRegistrationIds(), $this->validRegistrationIds);
|
||||
foreach ($this->validRegistrationIds as $id) {
|
||||
$this->m->addRegistrationId($id);
|
||||
}
|
||||
$this->assertEquals($this->m->getRegistrationIds(), $this->validRegistrationIds);
|
||||
$this->assertContains('registration_ids', $this->m->toJson());
|
||||
$this->m->clearRegistrationIds();
|
||||
$this->assertEquals($this->m->getRegistrationIds(), array());
|
||||
$this->assertNotContains('registration_ids', $this->m->toJson());
|
||||
$this->m->addRegistrationId('1029384756');
|
||||
$this->assertEquals($this->m->getRegistrationIds(), array('1029384756'));
|
||||
$this->assertContains('registration_ids', $this->m->toJson());
|
||||
}
|
||||
|
||||
public function testInvalidRegistrationIdThrowsException()
|
||||
{
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
$this->m->addRegistrationId(array('1234'));
|
||||
}
|
||||
|
||||
public function testExpectedCollapseKeyBehavior()
|
||||
{
|
||||
$this->assertEquals($this->m->getCollapseKey(), null);
|
||||
$this->assertNotContains('collapse_key', $this->m->toJson());
|
||||
$this->m->setCollapseKey('my collapse key');
|
||||
$this->assertEquals($this->m->getCollapseKey(), 'my collapse key');
|
||||
$this->assertContains('collapse_key', $this->m->toJson());
|
||||
$this->m->setCollapseKey(null);
|
||||
$this->assertEquals($this->m->getCollapseKey(), null);
|
||||
$this->assertNotContains('collapse_key', $this->m->toJson());
|
||||
}
|
||||
|
||||
public function testInvalidCollapseKeyThrowsException()
|
||||
{
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
$this->m->setCollapseKey(array('1234'));
|
||||
}
|
||||
|
||||
public function testExpectedDataBehavior()
|
||||
{
|
||||
$this->assertEquals($this->m->getData(), array());
|
||||
$this->assertNotContains('data', $this->m->toJson());
|
||||
$this->m->setData($this->validData);
|
||||
$this->assertEquals($this->m->getData(), $this->validData);
|
||||
$this->assertContains('data', $this->m->toJson());
|
||||
$this->m->clearData();
|
||||
$this->assertEquals($this->m->getData(), array());
|
||||
$this->assertNotContains('data', $this->m->toJson());
|
||||
$this->m->addData('mykey', 'myvalue');
|
||||
$this->assertEquals($this->m->getData(), array('mykey' => 'myvalue'));
|
||||
$this->assertContains('data', $this->m->toJson());
|
||||
}
|
||||
|
||||
public function testInvalidDataThrowsException()
|
||||
{
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
$this->m->addData(array('1234'), 'value');
|
||||
}
|
||||
|
||||
public function testDuplicateDataKeyThrowsException()
|
||||
{
|
||||
$this->setExpectedException('RuntimeException');
|
||||
$this->m->setData($this->validData);
|
||||
$this->m->addData('key', 'value');
|
||||
}
|
||||
|
||||
public function testExpectedDelayWhileIdleBehavior()
|
||||
{
|
||||
$this->assertEquals($this->m->getDelayWhileIdle(), false);
|
||||
$this->assertNotContains('delay_while_idle', $this->m->toJson());
|
||||
$this->m->setDelayWhileIdle(true);
|
||||
$this->assertEquals($this->m->getDelayWhileIdle(), true);
|
||||
$this->assertContains('delay_while_idle', $this->m->toJson());
|
||||
$this->m->setDelayWhileIdle(false);
|
||||
$this->assertEquals($this->m->getDelayWhileIdle(), false);
|
||||
$this->assertNotContains('delay_while_idle', $this->m->toJson());
|
||||
}
|
||||
|
||||
public function testExpectedTimeToLiveBehavior()
|
||||
{
|
||||
$this->assertEquals($this->m->getTimeToLive(), 2419200);
|
||||
$this->assertNotContains('time_to_live', $this->m->toJson());
|
||||
$this->m->setTimeToLive(12345);
|
||||
$this->assertEquals($this->m->getTimeToLive(), 12345);
|
||||
$this->assertContains('time_to_live', $this->m->toJson());
|
||||
$this->m->setTimeToLive(2419200);
|
||||
$this->assertEquals($this->m->getTimeToLive(), 2419200);
|
||||
$this->assertNotContains('time_to_live', $this->m->toJson());
|
||||
}
|
||||
|
||||
public function testExpectedRestrictedPackageBehavior()
|
||||
{
|
||||
$this->assertEquals($this->m->getRestrictedPackageName(), null);
|
||||
$this->assertNotContains('restricted_package_name', $this->m->toJson());
|
||||
$this->m->setRestrictedPackageName('my.package.name');
|
||||
$this->assertEquals($this->m->getRestrictedPackageName(), 'my.package.name');
|
||||
$this->assertContains('restricted_package_name', $this->m->toJson());
|
||||
$this->m->setRestrictedPackageName(null);
|
||||
$this->assertEquals($this->m->getRestrictedPackageName(), null);
|
||||
$this->assertNotContains('restricted_package_name', $this->m->toJson());
|
||||
}
|
||||
|
||||
public function testInvalidRestrictedPackageThrowsException()
|
||||
{
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
$this->m->setRestrictedPackageName(array('1234'));
|
||||
}
|
||||
|
||||
public function testExpectedDryRunBehavior()
|
||||
{
|
||||
$this->assertEquals($this->m->getDryRun(), false);
|
||||
$this->assertNotContains('dry_run', $this->m->toJson());
|
||||
$this->m->setDryRun(true);
|
||||
$this->assertEquals($this->m->getDryRun(), true);
|
||||
$this->assertContains('dry_run', $this->m->toJson());
|
||||
$this->m->setDryRun(false);
|
||||
$this->assertEquals($this->m->getDryRun(), false);
|
||||
$this->assertNotContains('dry_run', $this->m->toJson());
|
||||
}
|
||||
}
|
||||
102
vendor/zendframework/zendservice-google-gcm/tests/ZendService/Google/Gcm/ResponseTest.php
vendored
Normal file
102
vendor/zendframework/zendservice-google-gcm/tests/ZendService/Google/Gcm/ResponseTest.php
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
<?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
|
||||
* @package ZendService_Google
|
||||
* @subpackage UnitTests
|
||||
*/
|
||||
|
||||
namespace ZendServiceTest\Google\Gcm;
|
||||
|
||||
use ZendService\Google\Gcm\Message;
|
||||
use ZendService\Google\Gcm\Response;
|
||||
|
||||
/**
|
||||
* @category ZendService
|
||||
* @package ZendService_Google
|
||||
* @subpackage UnitTests
|
||||
* @group ZendService
|
||||
* @group ZendService_Google
|
||||
* @group ZendService_Google_Gcm
|
||||
*/
|
||||
class ResponseTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->m = new Message();
|
||||
}
|
||||
|
||||
public function testConstructorExpectedBehavior()
|
||||
{
|
||||
$response = new Response();
|
||||
$this->assertNull($response->getResponse());
|
||||
$this->assertNull($response->getMessage());
|
||||
|
||||
$message = new Message();
|
||||
$response = new Response(null, $message);
|
||||
$this->assertEquals($message, $response->getMessage());
|
||||
$this->assertNull($response->getResponse());
|
||||
|
||||
$message = new Message();
|
||||
$responseArray = array(
|
||||
'results' => array(
|
||||
array('message_id' => '1:1234'),
|
||||
),
|
||||
'success' => 1,
|
||||
'failure' => 0,
|
||||
'canonical_ids' => 0,
|
||||
'multicast_id' => 1,
|
||||
);
|
||||
$response = new Response($responseArray, $message);
|
||||
$this->assertEquals($responseArray, $response->getResponse());
|
||||
$this->assertEquals($message, $response->getMessage());
|
||||
}
|
||||
|
||||
public function testInvalidConstructorThrowsException()
|
||||
{
|
||||
$this->setExpectedException('PHPUnit_Framework_Error');
|
||||
$response = new Response('{bad');
|
||||
}
|
||||
|
||||
public function testMessageExpectedBehavior()
|
||||
{
|
||||
$message = new Message();
|
||||
$response = new Response();
|
||||
$response->setMessage($message);
|
||||
$this->assertEquals($message, $response->getMessage());
|
||||
}
|
||||
|
||||
public function testResponse()
|
||||
{
|
||||
$responseArr = array(
|
||||
'results' => array(
|
||||
array('message_id' => '1:234'),
|
||||
),
|
||||
'success' => 1,
|
||||
'failure' => 0,
|
||||
'canonical_ids' => 0,
|
||||
'multicast_id' => '123',
|
||||
);
|
||||
$response = new Response();
|
||||
$response->setResponse($responseArr);
|
||||
$this->assertEquals($responseArr, $response->getResponse());
|
||||
$this->assertEquals(1, $response->getSuccessCount());
|
||||
$this->assertEquals(0, $response->getFailureCount());
|
||||
$this->assertEquals(0, $response->getCanonicalCount());
|
||||
// test results non correlated
|
||||
$expected = array(array('message_id' => '1:234'));
|
||||
$this->assertEquals($expected, $response->getResults());
|
||||
$expected = array(0 => '1:234');
|
||||
$this->assertEquals($expected, $response->getResult(Response::RESULT_MESSAGE_ID));
|
||||
|
||||
$message = new Message();
|
||||
$message->setRegistrationIds(array('ABCDEF'));
|
||||
$response->setMessage($message);
|
||||
$expected = array('ABCDEF' => '1:234');
|
||||
$this->assertEquals($expected, $response->getResult(Response::RESULT_MESSAGE_ID));
|
||||
}
|
||||
}
|
||||
28
vendor/zendframework/zendservice-google-gcm/tests/_autoload.php
vendored
Executable file
28
vendor/zendframework/zendservice-google-gcm/tests/_autoload.php
vendored
Executable file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Setup autoloading
|
||||
*/
|
||||
|
||||
if (!file_exists(__DIR__ . '/../vendor/autoload.php')) {
|
||||
throw new RuntimeException('This component has dependencies that are unmet.
|
||||
|
||||
Please install composer (http://getcomposer.org), and run the following
|
||||
command in the root of this project:
|
||||
|
||||
php /path/to/composer.phar install
|
||||
|
||||
After that, you should be able to run tests.');
|
||||
}
|
||||
include_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
spl_autoload_register(function ($class) {
|
||||
if (0 !== strpos($class, 'ZendServiceTest\\')) {
|
||||
return false;
|
||||
}
|
||||
$normalized = str_replace('ZendServiceTest\\', '', $class);
|
||||
$filename = __DIR__ . '/ZendService/' . str_replace(array('\\', '_'), '/', $normalized) . '.php';
|
||||
if (!file_exists($filename)) {
|
||||
return false;
|
||||
}
|
||||
return include_once $filename;
|
||||
});
|
||||
13
vendor/zendframework/zendservice-google-gcm/tests/phpunit.xml.dist
vendored
Executable file
13
vendor/zendframework/zendservice-google-gcm/tests/phpunit.xml.dist
vendored
Executable file
@@ -0,0 +1,13 @@
|
||||
<phpunit bootstrap="./Bootstrap.php" colors="true">
|
||||
<testsuites>
|
||||
<testsuite name="ZendService Google Gcm Test Suite">
|
||||
<directory>./ZendService</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<groups>
|
||||
<exclude>
|
||||
<group>disable</group>
|
||||
</exclude>
|
||||
</groups>
|
||||
</phpunit>
|
||||
Reference in New Issue
Block a user