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,7 +0,0 @@
.DS_STORE
.*.un~
composer.lock
composer.phar
vendor/
php-cs-fixer.phar
/.project

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,193 +0,0 @@
# Changelog
All notable changes to this project will be documented in this file, in reverse chronological order by release.
## 1.4.1 - 2019-03-14
### Added
- Nothing.
### Changed
- Nothing.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#66](https://github.com/zendframework/ZendService_Apple_Apns/pull/66) fixes the schemes used for feedback notification URLs, to ensure they
reference `tlsv1.2` specifically.
## 1.4.0 - 2019-03-13
### Added
- Nothing.
### Changed
- [#65](https://github.com/zendframework/ZendService_Apple_Apns/pull/65) changes the URI schemes used to push messages from `tls` to `tlsv1.2` due
to a change in TLS versions supported by the endpoints.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- Nothing.
## 1.3.1 - 2019-02-07
### Added
- [#64](https://github.com/zendframework/ZendService_Apple_Apns/pull/64) adds support for PHP 7.3.
### Changed
- Nothing.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- Nothing.
## 1.3.0 - 2018-05-08
### Added
- [#63](https://github.com/zendframework/ZendService_Apple_Apns/pull/63) adds support for PHP 7.1 and 7.2.
- [#53](https://github.com/zendframework/ZendService_Apple_Apns/pull/53) adds support for the mutable-content Notification field within the `Message` implementation.
- [#48](https://github.com/zendframework/ZendService_Apple_Apns/pull/48) adds two new methods to `ZendService\Apple\Apns\Message\Alert`: `setAction($key)` and `getAction()`.
These allow specifying an action property for notifications.
### Changed
- [#42](https://github.com/zendframework/ZendService_Apple_Apns/pull/42) modifies the allowed character set for tokens to include uppercase A-F.
### Deprecated
- Nothing.
### Removed
- [#63](https://github.com/zendframework/ZendService_Apple_Apns/pull/63) removes support for PHP 5.3, 5.4, and 5.5.
- [#63](https://github.com/zendframework/ZendService_Apple_Apns/pull/63) removes support for HHVM.
### Fixed
- [#49](https://github.com/zendframework/ZendService_Apple_Apns/pull/49) fixes how `Message::getPayload()` and `Message::getPayloadJson()` create a
representation of the `aps` key when it is an empty value. With #18, the value was removed,
which was incorrect; it is not rendered as an empty object.
- [#62](https://github.com/zendframework/ZendService_Apple_Apns/pull/62) modifies the `AbstractClient::connect()` method such that it now
restores the previous error handler after catching a socket-related connection exception.
## 1.2.0 - 2015-12-09
### Added
- [#36](https://github.com/zendframework/ZendService_Apple_Apns/pull/36)
Conection failures now raise a ```RuntimeException``` to allow you to catch
stream_socket_client(): SSL: Connection reset by peer warnings.
- [#39](https://github.com/zendframework/ZendService_Apple_Apns/pull/39) Add
safari push support
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- Nothing.
## 1.1.2 - 2015-12-09
### Added
- Nothing.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#40](https://github.com/zendframework/ZendService_Apple_Apns/pull/40) Add
missing return $this
## 1.1.1 - 2015-10-13
### Added
- Nothing.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#38](https://github.com/zendframework/ZendService_Apple_Apns/pull/38) Fix
apns error response when sending a message.
- [#34](https://github.com/zendframework/ZendService_Apple_Apns/pull/34) Fixed
unit tests execution on travis
## 1.1.0 - 2015-07-29
### Added
- [#27](https://github.com/zendframework/ZendService_Apple_Apns/pull/27) Adds in
ANS category support.
- [#29](https://github.com/zendframework/ZendService_Apple_Apns/pull/29) Add in
ANS title, title-loc-key and title-loc-args.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#26](https://github.com/zendframework/ZendService_Apple_Apns/pull/26) Fixes a
possible infinity fread in certain PHP versions.
- [#28](https://github.com/zendframework/ZendService_Apple_Apns/pull/28) Fixed docblocks
that prevented proper code completion in some editors.
- [#29](https://github.com/zendframework/ZendService_Apple_Apns/pull/29) Force
TLS vs. SSL due to [Apple moving to TLS](https://developer.apple.com/news/?id=10222014a).

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,22 +0,0 @@
ZendService\Apple\Apns [![Build Status](https://travis-ci.org/zendframework/ZendService_Apple_Apns.png?branch=master)](https://travis-ci.org/zendframework/ZendService_Apple_Apns)
================================
Provides support for Apple push notifications.
## Requirements
* PHP >= 5.6
## Getting Started
Install this library using [Composer](http://getcomposer.org/):
```bash
$ composer require zendframework/zendservice-apple-apns
```
## Documentation
The documentation can be found at: http://framework.zend.com/manual/current/en/modules/zendservice.apple.apns.html

View File

@@ -1,47 +0,0 @@
{
"name": "zendframework/zendservice-apple-apns",
"description": "OOP Zend Framework wrapper for Apple Push Notification Service",
"license": "BSD-3-Clause",
"keywords": [
"zf",
"zendframework",
"apns",
"push",
"notification",
"apple"
],
"support": {
"issues": "https://github.com/zendframework/ZendService_Apple_Apns/issues",
"source": "https://github.com/zendframework/ZendService_Apple_Apns",
"rss": "https://github.com/zendframework/ZendService_Apple_Apns/releases.atom",
"chat": "https://zendframework-slack.herokuapp.com",
"forum": "https://discourse.zendframework.com/c/questions/components"
},
"require": {
"php": "^5.6 || ^7.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\\Apple\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"ZendServiceTest\\Apple\\": "test/"
}
},
"config": {
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "1.4.x-dev",
"dev-develop": "1.5.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 Apple Apns Test Suite">
<directory>./test</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>

View File

@@ -1,208 +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
* @package Zend_Service
*/
namespace ZendService\Apple\Apns\Client;
use ZendService\Apple\Exception;
use ZendService\Apple\Exception\StreamSocketClientException;
/**
* Apple Push Notification Abstract Client
*/
abstract class AbstractClient
{
/**
* APNS URI Constants
* @var int
*/
const SANDBOX_URI = 0;
const PRODUCTION_URI = 1;
/**
* APNS URIs
* @var array
*/
protected $uris = [];
/**
* Is Connected
* @var boolean
*/
protected $isConnected = false;
/**
* Stream Socket
* @var Resource
*/
protected $socket;
/**
* Open Connection to APNS Service
*
* @param int $environment
* @param string $certificate
* @param string $passPhrase
* @throws Exception\RuntimeException
* @throws Exception\InvalidArgumentException
* @return AbstractClient
*/
public function open($environment, $certificate, $passPhrase = null)
{
if ($this->isConnected) {
throw new Exception\RuntimeException('Connection has already been opened and must be closed');
}
if (! array_key_exists($environment, $this->uris)) {
throw new Exception\InvalidArgumentException('Environment must be one of PRODUCTION_URI or SANDBOX_URI');
}
if (! is_string($certificate) || ! file_exists($certificate)) {
throw new Exception\InvalidArgumentException('Certificate must be a valid path to a APNS certificate');
}
$sslOptions = [
'local_cert' => $certificate,
];
if ($passPhrase !== null) {
if (! is_scalar($passPhrase)) {
throw new Exception\InvalidArgumentException('SSL passphrase must be a scalar');
}
$sslOptions['passphrase'] = $passPhrase;
}
$this->connect($this->uris[$environment], $sslOptions);
$this->isConnected = true;
return $this;
}
/**
* Connect to Host
*
* @param string $host
* @param array $ssl
* @return AbstractClient
*/
protected function connect($host, array $ssl)
{
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
throw new StreamSocketClientException($errstr, $errno, 1, $errfile, $errline);
});
try {
$this->socket = stream_socket_client(
$host,
$errno,
$errstr,
ini_get('default_socket_timeout'),
STREAM_CLIENT_CONNECT,
stream_context_create(
[
'ssl' => $ssl,
]
)
);
} catch (StreamSocketClientException $e) {
restore_error_handler();
throw new Exception\RuntimeException(sprintf(
'Unable to connect: %s: %d (%s)',
$host,
$e->getCode(),
$e->getMessage()
));
}
restore_error_handler();
if (! $this->socket) {
throw new Exception\RuntimeException(sprintf(
'Unable to connect: %s: %d (%s)',
$host,
$errno,
$errstr
));
}
stream_set_blocking($this->socket, 0);
stream_set_write_buffer($this->socket, 0);
return $this;
}
/**
* Close Connection
*
* @return AbstractClient
*/
public function close()
{
if ($this->isConnected && is_resource($this->socket)) {
fclose($this->socket);
}
$this->isConnected = false;
return $this;
}
/**
* Is Connected
*
* @return boolean
*/
public function isConnected()
{
return $this->isConnected;
}
/**
* Read from the Server
*
* @param int $length
* @return string
*/
protected function read($length = 6)
{
if (! $this->isConnected()) {
throw new Exception\RuntimeException('You must open the connection prior to reading data');
}
$data = false;
$read = [$this->socket];
$null = null;
if (0 < @stream_select($read, $null, $null, 1, 0)) {
$data = @fread($this->socket, (int) $length);
}
return $data;
}
/**
* Write Payload to the Server
*
* @param string $payload
* @return int
*/
protected function write($payload)
{
if (! $this->isConnected()) {
throw new Exception\RuntimeException('You must open the connection prior to writing data');
}
return @fwrite($this->socket, $payload);
}
/**
* Destructor
*
* @return void
*/
public function __destruct()
{
$this->close();
}
}

View File

@@ -1,48 +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
* @package Zend_Service
*/
namespace ZendService\Apple\Apns\Client;
use ZendService\Apple\Exception;
use ZendService\Apple\Apns\Response\Feedback as FeedbackResponse;
/**
* Feedback Client
*/
class Feedback extends AbstractClient
{
/**
* APNS URIs
* @var array
*/
protected $uris = [
'tlsv1.2://feedback.sandbox.push.apple.com:2196',
'tlsv1.2://feedback.push.apple.com:2196'
];
/**
* Get Feedback
*
* @return array of ZendService\Apple\Apns\Response\Feedback
*/
public function feedback()
{
if (! $this->isConnected()) {
throw new Exception\RuntimeException('You must first open the connection by calling open()');
}
$tokens = [];
while ($token = $this->read(38)) {
$tokens[] = new FeedbackResponse($token);
}
return $tokens;
}
}

View File

@@ -1,56 +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
* @package ZendService_Apple
* @subpackage Apns
*/
namespace ZendService\Apple\Apns\Client;
use ZendService\Apple\Exception;
use ZendService\Apple\Apns\Message as ApnsMessage;
use ZendService\Apple\Apns\Response\Message as MessageResponse;
/**
* Message Client
*
* @category ZendService
* @package ZendService_Apple
* @subpackage Apns
*/
class Message extends AbstractClient
{
/**
* APNS URIs
* @var array
*/
protected $uris = [
'tlsv1.2://gateway.sandbox.push.apple.com:2195',
'tlsv1.2://gateway.push.apple.com:2195',
];
/**
* Send Message
*
* @param ApnsMessage $message
* @return MessageResponse
*/
public function send(ApnsMessage $message)
{
if (! $this->isConnected()) {
throw new Exception\RuntimeException('You must first open the connection by calling open()');
}
$ret = $this->write($message->getPayloadJson());
if ($ret === false) {
throw new Exception\RuntimeException('Server is unavailable; please retry later');
}
return new MessageResponse($this->read());
}
}

View File

@@ -1,450 +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
* @package Zend_Service
*/
namespace ZendService\Apple\Apns;
use Zend\Json\Encoder as JsonEncoder;
use ZendService\Apple\Exception;
/**
* APNs Message
*/
class Message
{
/**
* Identifier
* @var string
*/
protected $id;
/**
* APN Token
* @var string
*/
protected $token;
/**
* Expiration
* @var int|null
*/
protected $expire;
/**
* Alert Message
* @var Message\Alert|null
*/
protected $alert;
/**
* Badge
* @var int|null
*/
protected $badge;
/**
* Sound
* @var string|null
*/
protected $sound;
/**
* Mutable Content
* @var int|null
*/
private $mutableContent;
/**
* Content Available
* @var int|null
*/
protected $contentAvailable;
/**
* Category
* @var string|null
*/
protected $category;
/**
* URL Arguments
* @var array|null
*/
protected $urlArgs;
/**
* Custom Attributes
* @var array|null
*/
protected $custom;
/**
* Get Identifier
*
* @return string
*/
public function getId()
{
return $this->id;
}
/**
* Set Identifier
*
* @param string $id
* @return Message
*/
public function setId($id)
{
if (! is_scalar($id)) {
throw new Exception\InvalidArgumentException('Identifier must be a scalar value');
}
$this->id = $id;
return $this;
}
/**
* Get Token
*
* @return string
*/
public function getToken()
{
return $this->token;
}
/**
* Set Token
*
* @param string $token
* @return Message
*/
public function setToken($token)
{
if (! is_string($token)) {
throw new Exception\InvalidArgumentException(sprintf(
'Device token must be a string, "%s" given.',
gettype($token)
));
}
if (preg_match('/[^0-9a-f]/i', $token)) {
throw new Exception\InvalidArgumentException(sprintf(
'Device token must be mask "%s". Token given: "%s"',
'/[^0-9a-f]/',
$token
));
}
if (strlen($token) != 64) {
throw new Exception\InvalidArgumentException(sprintf(
'Device token must be a 64 charsets, Token length given: %d.',
mb_strlen($token)
));
}
$this->token = $token;
return $this;
}
/**
* Get Expiration
*
* @return int
*/
public function getExpire()
{
return $this->expire;
}
/**
* Set Expiration
*
* @param int|DateTime $expire
* @return Message
*/
public function setExpire($expire)
{
if ($expire instanceof \DateTime) {
$expire = $expire->getTimestamp();
} elseif (! is_numeric($expire) || $expire != (int) $expire) {
throw new Exception\InvalidArgumentException('Expiration must be a DateTime object or a unix timestamp');
}
$this->expire = $expire;
return $this;
}
/**
* Get Alert
*
* @return Message\Alert|null
*/
public function getAlert()
{
return $this->alert;
}
/**
* Set Alert
*
* @param string|Message\Alert|null $alert
* @return Message
*/
public function setAlert($alert)
{
if (! $alert instanceof Message\Alert && ! is_null($alert)) {
$alert = new Message\Alert($alert);
}
$this->alert = $alert;
return $this;
}
/**
* Get Badge
*
* @return int|null
*/
public function getBadge()
{
return $this->badge;
}
/**
* Set Badge
*
* @param int|null $badge
* @return Message
*/
public function setBadge($badge)
{
if ($badge !== null && ! $badge == (int) $badge) {
throw new Exception\InvalidArgumentException('Badge must be null or an integer');
}
$this->badge = $badge;
return $this;
}
/**
* Get Sound
*
* @return string|null
*/
public function getSound()
{
return $this->sound;
}
/**
* Set Sound
*
* @param string|null $sound
* @return Message
*/
public function setSound($sound)
{
if ($sound !== null && ! is_string($sound)) {
throw new Exception\InvalidArgumentException('Sound must be null or a string');
}
$this->sound = $sound;
return $this;
}
/**
* Set Mutable Content
*
* @param int|null $value
* @returns Message
*/
public function setMutableContent($value)
{
if ($value !== null && ! is_int($value)) {
throw new Exception\InvalidArgumentException(
'Mutable Content must be null or an integer, received: ' . gettype($value)
);
}
if (is_int($value) && $value !== 1) {
throw new Exception\InvalidArgumentException('Mutable Content supports only 1 as integer value');
}
$this->mutableContent = $value;
return $this;
}
/**
* Get Content Available
*
* @return int|null
*/
public function getContentAvailable()
{
return $this->contentAvailable;
}
/**
* Set Content Available
*
* @param int|null $value
* @return Message
*/
public function setContentAvailable($value)
{
if ($value !== null && ! is_int($value)) {
throw new Exception\InvalidArgumentException('Content Available must be null or an integer');
}
$this->contentAvailable = $value;
return $this;
}
/**
* Get Category
*
* @return string|null
*/
public function getCategory()
{
return $this->category;
}
/**
* Set Category
*
* @param string|null $category
* @return Message
*/
public function setCategory($category)
{
if ($category !== null && ! is_string($category)) {
throw new Exception\InvalidArgumentException('Category must be null or a string');
}
$this->category = $category;
return $this;
}
/**
* Get URL arguments
*
* @return array|null
*/
public function getUrlArgs()
{
return $this->urlArgs;
}
/**
* Set URL arguments
*
* @param array|null $urlArgs
* @return Message
*/
public function setUrlArgs(array $urlArgs)
{
$this->urlArgs = $urlArgs;
return $this;
}
/**
* Get Custom Data
*
* @return array|null
*/
public function getCustom()
{
return $this->custom;
}
/**
* Set Custom Data
*
* @param array $custom
* @throws Exception\RuntimeException
* @return Message
*/
public function setCustom(array $custom)
{
if (array_key_exists('aps', $custom)) {
throw new Exception\RuntimeException('custom data must not contain aps key as it is reserved by apple');
}
$this->custom = $custom;
return $this;
}
/**
* Get Payload
* Generate APN array.
*
* @return array
*/
public function getPayload()
{
$message = [];
$aps = [];
if ($this->alert && ($alert = $this->alert->getPayload())) {
$aps['alert'] = $alert;
}
if (! is_null($this->badge)) {
$aps['badge'] = $this->badge;
}
if (! is_null($this->sound)) {
$aps['sound'] = $this->sound;
}
if (! is_null($this->mutableContent)) {
$aps['mutable-content'] = $this->mutableContent;
}
if (! is_null($this->contentAvailable)) {
$aps['content-available'] = $this->contentAvailable;
}
if (! is_null($this->category)) {
$aps['category'] = $this->category;
}
if (! is_null($this->urlArgs)) {
$aps['url-args'] = $this->urlArgs;
}
if (! empty($this->custom)) {
$message = array_merge($this->custom, $message);
}
$message['aps'] = empty($aps) ? (object) [] : $aps;
return $message;
}
/**
* Get Payload JSON
*
* @return string
*/
public function getPayloadJson()
{
$payload = $this->getPayload();
// don't escape utf8 payloads unless json_encode does not exist.
if (defined('JSON_UNESCAPED_UNICODE')) {
$payload = json_encode($payload, JSON_UNESCAPED_UNICODE);
} else {
$payload = JsonEncoder::encode($payload);
}
$length = strlen($payload);
return pack('CNNnH*', 1, $this->id, $this->expire, 32, $this->token)
. pack('n', $length)
. $payload;
}
}

View File

@@ -1,385 +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
* @package Zend_Service
*/
namespace ZendService\Apple\Apns\Message;
use ZendService\Apple\Exception;
/**
* Message Alert Object
*/
class Alert
{
/**
* Message Body
* @var string|null
*/
protected $body;
/**
* Action
* @var string|null
*/
protected $action;
/**
* Action Locale Key
* @var string|null
*/
protected $actionLocKey;
/**
* Locale Key
* @var string|null
*/
protected $locKey;
/**
* Locale Arguments
* @var array|null
*/
protected $locArgs;
/**
* Launch Image
* @var string|null
*/
protected $launchImage;
/**
* Message Title
* @var string|null
*/
protected $title;
/**
* Title Locale Key
* @var string|null
*/
protected $titleLocKey;
/**
* Title Locale Arguments
* @var array|null
*/
protected $titleLocArgs;
/**
* Constructor
*
* @param string $body
* @param string $actionLocKey
* @param string $locKey
* @param array $locArgs
* @param string $launchImage
* @return Alert
*/
public function __construct(
$body = null,
$actionLocKey = null,
$locKey = null,
$locArgs = null,
$launchImage = null,
$title = null,
$titleLocKey = null,
$titleLocArgs = null
) {
if ($body !== null) {
$this->setBody($body);
}
if ($actionLocKey !== null) {
$this->setActionLocKey($actionLocKey);
}
if ($locKey !== null) {
$this->setLocKey($locKey);
}
if ($locArgs !== null) {
$this->setLocArgs($locArgs);
}
if ($launchImage !== null) {
$this->setLaunchImage($launchImage);
}
if ($title !== null) {
$this->setTitle($title);
}
if ($titleLocKey !== null) {
$this->setTitleLocKey($titleLocKey);
}
if ($titleLocArgs !== null) {
$this->setTitleLocArgs($titleLocArgs);
}
}
/**
* Get Body
*
* @return string|null
*/
public function getBody()
{
return $this->body;
}
/**
* Set Body
*
* @param string|null $body
* @return Alert
*/
public function setBody($body)
{
if (! is_null($body) && ! is_scalar($body)) {
throw new Exception\InvalidArgumentException('Body must be null OR a scalar value');
}
$this->body = $body;
return $this;
}
/**
* Get Action
*
* @return string|null
*/
public function getAction()
{
return $this->action;
}
/**
* Set Action
*
* @param string|null $key
* @return Alert
*/
public function setAction($key)
{
if (! is_null($key) && ! is_scalar($key)) {
throw new Exception\InvalidArgumentException('Action must be null OR a scalar value');
}
$this->action = $key;
return $this;
}
/**
* Get Action Locale Key
*
* @return string|null
*/
public function getActionLocKey()
{
return $this->actionLocKey;
}
/**
* Set Action Locale Key
*
* @param string|null $key
* @return Alert
*/
public function setActionLocKey($key)
{
if (! is_null($key) && ! is_scalar($key)) {
throw new Exception\InvalidArgumentException('ActionLocKey must be null OR a scalar value');
}
$this->actionLocKey = $key;
return $this;
}
/**
* Get Locale Key
*
* @return string|null
*/
public function getLocKey()
{
return $this->locKey;
}
/**
* Set Locale Key
*
* @param string|null $key
* @return Alert
*/
public function setLocKey($key)
{
if (! is_null($key) && ! is_scalar($key)) {
throw new Exception\InvalidArgumentException('LocKey must be null OR a scalar value');
}
$this->locKey = $key;
return $this;
}
/**
* Get Locale Arguments
*
* @return array|null
*/
public function getLocArgs()
{
return $this->locArgs;
}
/**
* Set Locale Arguments
*
* @param array $args
* @return Alert
*/
public function setLocArgs(array $args)
{
foreach ($args as $a) {
if (! is_scalar($a)) {
throw new Exception\InvalidArgumentException('Arguments must only contain scalar values');
}
}
$this->locArgs = $args;
return $this;
}
/**
* Get Launch Image
*
* @return string|null
*/
public function getLaunchImage()
{
return $this->launchImage;
}
/**
* Set Launch Image
*
* @param string|null $image
* @return Alert
*/
public function setLaunchImage($image)
{
if (! is_null($image) && ! is_scalar($image)) {
throw new Exception\InvalidArgumentException('Launch image must be null OR a scalar value');
}
$this->launchImage = $image;
return $this;
}
/**
* Get Title
*
* @return string|null
*/
public function getTitle()
{
return $this->title;
}
/**
* Set Title
*
* @param string|null $title
* @return Alert
*/
public function setTitle($title)
{
if (! is_null($title) && ! is_scalar($title)) {
throw new Exception\InvalidArgumentException('Title must be null OR a scalar value');
}
$this->title = $title;
return $this;
}
/**
* Get Title Locale Key
*
* @return string|null
*/
public function getTitleLocKey()
{
return $this->titleLocKey;
}
/**
* Set Title Locale Key
*
* @param string|null $key
* @return Alert
*/
public function setTitleLocKey($key)
{
if (! is_null($key) && ! is_scalar($key)) {
throw new Exception\InvalidArgumentException('TitleLocKey must be null OR a scalar value');
}
$this->titleLocKey = $key;
return $this;
}
/**
* Get Title Locale Arguments
*
* @return array|null
*/
public function getTitleLocArgs()
{
return $this->titleLocArgs;
}
/**
* Set Title Locale Arguments
*
* @param array $args
* @return Alert
*/
public function setTitleLocArgs(array $args)
{
foreach ($args as $a) {
if (! is_scalar($a)) {
throw new Exception\InvalidArgumentException('Title Arguments must only contain scalar values');
}
}
$this->titleLocArgs = $args;
return $this;
}
/**
* To Payload
* Formats an APS alert.
*
* @return array|string
*/
public function getPayload()
{
$vars = get_object_vars($this);
if (empty($vars)) {
return null;
}
$alert = [];
foreach ($vars as $key => $value) {
if (! is_null($value)) {
$key = strtolower(preg_replace('/([a-z])([A-Z])/', '$1-$2', $key));
$alert[$key] = $value;
}
}
if (count($alert) === 1) {
return $this->getBody();
}
return $alert;
}
}

View File

@@ -1,107 +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
* @package Zend_Service
*/
namespace ZendService\Apple\Apns\Response;
use ZendService\Apple\Exception;
/**
* Feedback Response
*/
class Feedback
{
/**
* APNS Token
* @var string
*/
protected $token;
/**
* Time
* @var int
*/
protected $time;
/**
* Constructor
*
* @param string $rawResponse
* @return Feedback
*/
public function __construct($rawResponse = null)
{
if ($rawResponse !== null) {
$this->parseRawResponse($rawResponse);
}
}
/**
* Get Token
*
* @return string
*/
public function getToken()
{
return $this->token;
}
/**
* Set Token
*
* @return Feedback
*/
public function setToken($token)
{
if (! is_scalar($token)) {
throw new Exception\InvalidArgumentException('Token must be a scalar value');
}
$this->token = $token;
return $this;
}
/**
* Get Time
*
* @return int
*/
public function getTime()
{
return $this->time;
}
/**
* Set Time
*
* @param int $time
* @return Feedback
*/
public function setTime($time)
{
$this->time = (int) $time;
return $this;
}
/**
* Parse Raw Response
*
* @return Feedback
*/
public function parseRawResponse($rawResponse)
{
$rawResponse = trim($rawResponse);
$token = unpack('Ntime/nlength/H*token', $rawResponse);
$this->setTime($token['time']);
$this->setToken(substr($token['token'], 0, $token['length'] * 2));
return $this;
}
}

View File

@@ -1,141 +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
* @package ZendService_Apple
* @subpackage Apns
*/
namespace ZendService\Apple\Apns\Response;
use ZendService\Apple\Exception;
/**
* Message Response
*
* @category ZendService
* @package ZendService_Apple
* @subpackage Apns
*/
class Message
{
/**
* Response Codes
* @var int
*/
const RESULT_OK = 0;
const RESULT_PROCESSING_ERROR = 1;
const RESULT_MISSING_TOKEN = 2;
const RESULT_MISSING_TOPIC = 3;
const RESULT_MISSING_PAYLOAD = 4;
const RESULT_INVALID_TOKEN_SIZE = 5;
const RESULT_INVALID_TOPIC_SIZE = 6;
const RESULT_INVALID_PAYLOAD_SIZE = 7;
const RESULT_INVALID_TOKEN = 8;
const RESULT_UNKNOWN_ERROR = 255;
/**
* Identifier
* @var string
*/
protected $id;
/**
* Result Code
* @var int
*/
protected $code;
/**
* Constructor
*
* @param string $rawResponse
* @return Message
*/
public function __construct($rawResponse = null)
{
if ($rawResponse !== null) {
$this->parseRawResponse($rawResponse);
}
}
/**
* Get Code
*
* @return int
*/
public function getCode()
{
return $this->code;
}
/**
* Set Code
*
* @param int $code
* @return Message
*/
public function setCode($code)
{
if (($code < 0 || $code > 8) && $code != 255) {
throw new Exception\InvalidArgumentException('Code must be between 0-8 OR 255');
}
$this->code = $code;
return $this;
}
/**
* Get Identifier
*
* @return string
*/
public function getId()
{
return $this->id;
}
/**
* Set Identifier
*
* @param string $id
* @return Message
*/
public function setId($id)
{
if (! is_scalar($id)) {
throw new Exception\InvalidArgumentException('Identifier must be a scalar value');
}
$this->id = $id;
return $this;
}
/**
* Parse Raw Response
*
* @param string $rawResponse
* @return Message
*/
public function parseRawResponse($rawResponse)
{
if (! is_scalar($rawResponse)) {
throw new Exception\InvalidArgumentException('Response must be a scalar value');
}
if (strlen($rawResponse) === 0) {
$this->code = self::RESULT_OK;
return $this;
}
$response = unpack('Ccmd/Cerrno/Nid', $rawResponse);
$this->setId($response['id']);
$this->setCode($response['errno']);
return $this;
}
}

View File

@@ -1,18 +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
* @package Zend_Service
*/
namespace ZendService\Apple\Exception;
/**
* Invalid Argument Exception
*/
class InvalidArgumentException extends \InvalidArgumentException
{
}

View File

@@ -1,15 +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
* @package Zend_Service
*/
namespace ZendService\Apple\Exception;
class RuntimeException extends \RuntimeException
{
}

View File

@@ -1,13 +0,0 @@
<?php
/**
* Exception for creating stream_socket_client
* @author Soshnikov Artem <213036@skobka.com>
*/
namespace ZendService\Apple\Exception;
use ErrorException;
class StreamSocketClientException extends ErrorException
{
}

View File

@@ -1,49 +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
* @package Zend_Service
*/
namespace ZendServiceTest\Apple\Apns;
use PHPUnit\Framework\TestCase;
use ZendServiceTest\Apple\Apns\TestAsset\FeedbackClient;
/**
* @category ZendService
* @package ZendService_Apple
* @subpackage UnitTests
* @group ZendService
* @group ZendService_Apple
* @group ZendService_Apple_Apns
*/
class FeedbackClientTest extends TestCase
{
public function setUp()
{
$this->apns = new FeedbackClient();
}
protected function setupValidBase()
{
$this->apns->open(FeedbackClient::SANDBOX_URI, __DIR__ . '/TestAsset/certificate.pem');
}
public function testFeedback()
{
$this->setupValidBase();
$time = time();
$token = 'abc123';
$length = strlen($token) / 2;
$this->apns->setReadResponse(pack('NnH*', $time, $length, $token));
$response = $this->apns->feedback();
$this->assertCount(1, $response);
$feedback = array_shift($response);
$this->assertEquals($time, $feedback->getTime());
$this->assertEquals($token, $feedback->getToken());
}
}

View File

@@ -1,177 +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
* @package ZendService_Apple
* @subpackage UnitTests
*/
namespace ZendServiceTest\Apple\Apns;
use PHPUnit\Framework\TestCase;
use ZendServiceTest\Apple\Apns\TestAsset\MessageClient;
use ZendService\Apple\Apns\Message;
use ZendService\Apple\Apns\Response\Message as MessageResponse;
/**
* @category ZendService
* @package ZendService_Apple
* @subpackage UnitTests
* @group ZendService
* @group ZendService_Apple
* @group ZendService_Apple_Apns
*/
class MessageClientTest extends TestCase
{
public function setUp()
{
$this->apns = new MessageClient();
$this->message = new Message();
}
protected function setupValidBase()
{
$this->apns->open(MessageClient::SANDBOX_URI, __DIR__ . '/TestAsset/certificate.pem');
$this->message->setToken('662cfe5a69ddc65cdd39a1b8f8690647778204b064df7b264e8c4c254f94fdd8');
$this->message->setId(time());
$this->message->setAlert('bar');
}
public function testConnectThrowsExceptionOnInvalidEnvironment()
{
$this->expectException('InvalidArgumentException');
$this->apns->open(5, __DIR__ . '/TestAsset/certificate.pem');
}
public function testSetCertificateThrowsExceptionOnNonString()
{
$this->expectException('InvalidArgumentException');
$this->apns->open(MessageClient::PRODUCTION_URI, ['foo']);
}
public function testSetCertificateThrowsExceptionOnMissingFile()
{
$this->expectException('InvalidArgumentException');
$this->apns->open(MessageClient::PRODUCTION_URI, 'foo');
}
public function testSetCertificatePassphraseThrowsExceptionOnNonString()
{
$this->expectException('InvalidArgumentException');
$this->apns->open(MessageClient::PRODUCTION_URI, __DIR__ . '/TestAsset/certificate.pem', ['foo']);
}
public function testOpen()
{
$ret = $this->apns->open(MessageClient::SANDBOX_URI, __DIR__ . '/TestAsset/certificate.pem');
$this->assertEquals($this->apns, $ret);
$this->assertTrue($this->apns->isConnected());
}
public function testClose()
{
$this->apns->open(MessageClient::SANDBOX_URI, __DIR__ . '/TestAsset/certificate.pem');
$this->apns->close();
$this->assertFalse($this->apns->isConnected());
}
public function testOpenWhenAlreadyOpenThrowsException()
{
$this->expectException('RuntimeException');
$this->apns->open(MessageClient::SANDBOX_URI, __DIR__ . '/TestAsset/certificate.pem');
$this->apns->open(MessageClient::SANDBOX_URI, __DIR__ . '/TestAsset/certificate.pem');
}
public function testSendReturnsTrueOnSuccess()
{
$this->setupValidBase();
$response = $this->apns->send($this->message);
$this->assertEquals(MessageResponse::RESULT_OK, $response->getCode());
$this->assertNull($response->getId());
}
public function testSendResponseOnProcessingError()
{
$this->setupValidBase();
$this->apns->setReadResponse(pack('CCN*', 1, 1, 12345));
$response = $this->apns->send($this->message);
$this->assertEquals(MessageResponse::RESULT_PROCESSING_ERROR, $response->getCode());
$this->assertEquals(12345, $response->getId());
}
public function testSendResponseOnMissingToken()
{
$this->setupValidBase();
$this->apns->setReadResponse(pack('CCN*', 2, 2, 12345));
$response = $this->apns->send($this->message);
$this->assertEquals(MessageResponse::RESULT_MISSING_TOKEN, $response->getCode());
$this->assertEquals(12345, $response->getId());
}
public function testSendResponseOnMissingTopic()
{
$this->setupValidBase();
$this->apns->setReadResponse(pack('CCN*', 3, 3, 12345));
$response = $this->apns->send($this->message);
$this->assertEquals(MessageResponse::RESULT_MISSING_TOPIC, $response->getCode());
$this->assertEquals(12345, $response->getId());
}
public function testSendResponseOnMissingPayload()
{
$this->setupValidBase();
$this->apns->setReadResponse(pack('CCN*', 4, 4, 12345));
$response = $this->apns->send($this->message);
$this->assertEquals(MessageResponse::RESULT_MISSING_PAYLOAD, $response->getCode());
$this->assertEquals(12345, $response->getId());
}
public function testSendResponseOnInvalidTokenSize()
{
$this->setupValidBase();
$this->apns->setReadResponse(pack('CCN*', 5, 5, 12345));
$response = $this->apns->send($this->message);
$this->assertEquals(MessageResponse::RESULT_INVALID_TOKEN_SIZE, $response->getCode());
$this->assertEquals(12345, $response->getId());
}
public function testSendResponseOnInvalidTopicSize()
{
$this->setupValidBase();
$this->apns->setReadResponse(pack('CCN*', 6, 6, 12345));
$response = $this->apns->send($this->message);
$this->assertEquals(MessageResponse::RESULT_INVALID_TOPIC_SIZE, $response->getCode());
$this->assertEquals(12345, $response->getId());
}
public function testSendResponseOnInvalidPayloadSize()
{
$this->setupValidBase();
$this->apns->setReadResponse(pack('CCN*', 7, 7, 12345));
$response = $this->apns->send($this->message);
$this->assertEquals(MessageResponse::RESULT_INVALID_PAYLOAD_SIZE, $response->getCode());
$this->assertEquals(12345, $response->getId());
}
public function testSendResponseOnInvalidToken()
{
$this->setupValidBase();
$this->apns->setReadResponse(pack('CCN*', 8, 8, 12345));
$response = $this->apns->send($this->message);
$this->assertEquals(MessageResponse::RESULT_INVALID_TOKEN, $response->getCode());
$this->assertEquals(12345, $response->getId());
}
public function testSendResponseOnUnknownError()
{
$this->setupValidBase();
$this->apns->setReadResponse(pack('CCN*', 255, 255, 12345));
$response = $this->apns->send($this->message);
$this->assertEquals(MessageResponse::RESULT_UNKNOWN_ERROR, $response->getCode());
$this->assertEquals(12345, $response->getId());
}
}

View File

@@ -1,343 +0,0 @@
<?php
/**
* @see https://github.com/zendframework/ZendService_Apple_Apns for the canonical source repository
* @copyright Copyright (c) 2014-2018 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/ZendService_Apple_Apns/blob/master/LICENSE.md New BSD License
*/
namespace ZendServiceTest\Apple\Apns;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
use stdClass;
use Zend\Json\Encoder as JsonEncoder;
use ZendService\Apple\Apns\Message;
use ZendService\Apple\Apns\Message\Alert;
/**
* @category ZendService
* @package ZendService_Apple
* @subpackage UnitTests
* @group ZendService
* @group ZendService_Apple
* @group ZendService_Apple_Apns
*/
class MessageTest extends TestCase
{
public function setUp()
{
$this->alert = new Alert();
$this->message = new Message();
}
public function testSetAlertTextReturnsCorrectly()
{
$text = 'my alert';
$ret = $this->message->setAlert($text);
$this->assertInstanceOf('ZendService\Apple\Apns\Message', $ret);
$checkText = $this->message->getAlert();
$this->assertInstanceOf('ZendService\Apple\Apns\Message\Alert', $checkText);
$this->assertEquals($text, $checkText->getBody());
}
public function testSetAlertThrowsExceptionOnTextNonString()
{
$this->expectException(InvalidArgumentException::class);
$this->message->setAlert([]);
}
public function testSetAlertThrowsExceptionOnActionLocKeyNonString()
{
$this->expectException(InvalidArgumentException::class);
$this->alert->setActionLocKey([]);
}
public function testSetAlertThrowsExceptionOnLocKeyNonString()
{
$this->expectException(InvalidArgumentException::class);
$this->alert->setLocKey([]);
}
public function testSetAlertThrowsExceptionOnLaunchImageNonString()
{
$this->expectException(InvalidArgumentException::class);
$this->alert->setLaunchImage([]);
}
public function testSetAlertThrowsExceptionOnTitleNonString()
{
$this->expectException(InvalidArgumentException::class);
$this->alert->setTitle([]);
}
public function testSetAlertThrowsExceptionOnTitleLocKeyNonString()
{
$this->expectException(InvalidArgumentException::class);
$this->alert->setTitleLocKey([]);
}
public function testSetBadgeReturnsCorrectNumber()
{
$num = 5;
$this->message->setBadge($num);
$this->assertEquals($num, $this->message->getBadge());
}
public function testSetBadgeNonNumericThrowsException()
{
$this->expectException(InvalidArgumentException::class);
$this->message->setBadge('string!');
}
public function testSetBadgeAllowsNull()
{
$this->message->setBadge(null);
$this->assertNull($this->message->getBadge());
}
public function testSetExpireReturnsInteger()
{
$expire = 100;
$this->message->setExpire($expire);
$this->assertEquals($expire, $this->message->getExpire());
}
public function testSetExpireNonNumericThrowsException()
{
$this->expectException(InvalidArgumentException::class);
$this->message->setExpire('sting!');
}
public function testSetSoundReturnsString()
{
$sound = 'test';
$this->message->setSound($sound);
$this->assertEquals($sound, $this->message->getSound());
}
public function testSetSoundThrowsExceptionOnNonScalar()
{
$this->expectException(InvalidArgumentException::class);
$this->message->setSound([]);
}
public function testSetSoundThrowsExceptionOnNonString()
{
$this->expectException(InvalidArgumentException::class);
$this->message->setSound(12345);
}
/**
* @dataProvider provideSetMutableContentThrowsExceptionOnNonIntegerOneOrNullData
*
* @param mixed $value
*/
public function testSetMutableContentThrowsExceptionOnNonIntegerOneAndNull($value)
{
$this->expectException(InvalidArgumentException::class);
$this->message->setMutableContent($value);
}
/**
* @return array
*/
public function provideSetMutableContentThrowsExceptionOnNonIntegerOneOrNullData()
{
return [
'unsupported positive integer' => ['value' => 2],
'zero integer' => ['value' => 0],
'negative integer' => ['value' => -1],
'boolean' => ['value' => true],
'string' => ['value' => 'any string'],
'float' => ['value' => 123.12],
'array' => ['value' => []],
'object' => ['value' => new stdClass()],
];
}
public function testSetMutableContentResultsInCorrectPayloadWithIntegerValue()
{
$value = 1;
$this->message->setMutableContent($value);
$payload = $this->message->getPayload();
$this->assertEquals($value, $payload['aps']['mutable-content']);
}
public function testSetMutableContentResultsInCorrectPayloadWithNullValue()
{
$this->message->setMutableContent(null);
$json = $this->message->getPayloadJson();
$payload = json_decode($json, true);
$this->assertFalse(isset($payload['aps']['mutable-content']));
}
public function testSetContentAvailableThrowsExceptionOnNonInteger()
{
$this->expectException(InvalidArgumentException::class);
$this->message->setContentAvailable("string");
}
public function testGetContentAvailableReturnsCorrectInteger()
{
$value = 1;
$this->message->setContentAvailable($value);
$this->assertEquals($value, $this->message->getContentAvailable());
}
public function testSetContentAvailableResultsInCorrectPayload()
{
$value = 1;
$this->message->setContentAvailable($value);
$payload = $this->message->getPayload();
$this->assertEquals($value, $payload['aps']['content-available']);
}
public function testSetCategoryReturnsString()
{
$category = 'test';
$this->message->setCategory($category);
$this->assertEquals($category, $this->message->getCategory());
}
public function testSetCategoryThrowsExceptionOnNonScalar()
{
$this->expectException(InvalidArgumentException::class);
$this->message->setCategory([]);
}
public function testSetCategoryThrowsExceptionOnNonString()
{
$this->expectException(InvalidArgumentException::class);
$this->message->setCategory(12345);
}
public function testSetUrlArgsReturnsString()
{
$urlArgs = ['path/to/somewhere'];
$this->message->setUrlArgs($urlArgs);
$this->assertEquals($urlArgs, $this->message->getUrlArgs());
}
public function testSetCustomData()
{
$data = ['key' => 'val', 'key2' => [1, 2, 3, 4, 5]];
$this->message->setCustom($data);
$this->assertEquals($data, $this->message->getCustom());
}
public function testAlertConstructor()
{
$alert = new Alert(
'Foo wants to play Bar!',
'PLAY',
'GAME_PLAY_REQUEST_FORMAT',
['Foo', 'Baz'],
'Default.png',
'Alert',
'ALERT',
['Foo', 'Baz']
);
$this->assertEquals('Foo wants to play Bar!', $alert->getBody());
$this->assertEquals('PLAY', $alert->getActionLocKey());
$this->assertEquals('GAME_PLAY_REQUEST_FORMAT', $alert->getLocKey());
$this->assertEquals(['Foo', 'Baz'], $alert->getLocArgs());
$this->assertEquals('Default.png', $alert->getLaunchImage());
$this->assertEquals('Alert', $alert->getTitle());
$this->assertEquals('ALERT', $alert->getTitleLocKey());
$this->assertEquals(['Foo', 'Baz'], $alert->getTitleLocArgs());
}
public function testAlertJsonPayload()
{
$alert = new Alert(
'Foo wants to play Bar!',
'PLAY',
'GAME_PLAY_REQUEST_FORMAT',
['Foo', 'Baz'],
'Default.png',
'Alert',
'ALERT',
['Foo', 'Baz']
);
$payload = $alert->getPayload();
$this->assertArrayHasKey('body', $payload);
$this->assertArrayHasKey('action-loc-key', $payload);
$this->assertArrayHasKey('loc-key', $payload);
$this->assertArrayHasKey('loc-args', $payload);
$this->assertArrayHasKey('launch-image', $payload);
$this->assertArrayHasKey('title', $payload);
$this->assertArrayHasKey('title-loc-key', $payload);
$this->assertArrayHasKey('title-loc-args', $payload);
}
public function testAlertPayloadSendsOnlyBody()
{
$alert = new Alert('Foo wants Bar');
$payload = $alert->getPayload();
$this->assertEquals('Foo wants Bar', $payload);
}
public function testPayloadJsonFormedCorrectly()
{
$text = 'hi=привет';
$this->message->setAlert($text);
$this->message->setId(1);
$this->message->setExpire(100);
$this->message->setToken('0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef');
$payload = $this->message->getPayload();
$this->assertEquals($payload, ['aps' => ['alert' => 'hi=привет']]);
if (defined('JSON_UNESCAPED_UNICODE')) {
$payloadJson = json_encode($payload, JSON_UNESCAPED_UNICODE);
$this->assertEquals($payloadJson, '{"aps":{"alert":"hi=привет"}}');
$length = 35; // 23 + (2 * 6) because UTF-8 (Russian) "привет" contains 2 bytes per letter
$result =
pack(
'CNNnH*',
1,
$this->message->getId(),
$this->message->getExpire(),
32,
$this->message->getToken()
)
. pack('n', $length)
. $payloadJson;
$this->assertEquals($this->message->getPayloadJson(), $result);
} else {
$payloadJson = JsonEncoder::encode($payload);
$this->assertEquals($payloadJson, '{"aps":{"alert":"hi=\u043f\u0440\u0438\u0432\u0435\u0442"}}');
$length = 59; // (23 + (6 * 6) because UTF-8 (Russian) "привет" converts into 6 bytes/letter
$result =
pack(
'CNNnH*',
1,
$this->message->getId(),
$this->message->getExpire(),
32,
$this->message->getToken()
)
. pack('n', $length)
. $payloadJson;
$this->assertEquals($this->message->getPayloadJson(), $result);
}
}
public function testCustomDataPayloadIncludesEmptyApsObject()
{
$data = ['custom' => 'data'];
$expected = array_merge($data, ['aps' => (object) []]);
$this->message->setCustom($data);
$payload = $this->message->getPayload();
$this->assertEquals($expected, $payload);
}
public function testTokensAllowUpperCaseHex()
{
$token = str_repeat('abc1234defABCDEF', 4);
$this->message->setToken($token);
$this->assertSame($token, $this->message->getToken());
}
}

View File

@@ -1,109 +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
* @package Zend_Service
*/
namespace ZendServiceTest\Apple\Apns\TestAsset;
use ZendService\Apple\Apns\Exception;
use ZendService\Apple\Apns\Client\Feedback as ZfFeedbackClient;
/**
* Feedback Client Proxy
* This class is utilized for unit testing purposes
*
* @category ZendService
* @package ZendService_Apple
* @subpackage Apns
*/
class FeedbackClient extends ZfFeedbackClient
{
/**
* Read Response
*
* @var string
*/
protected $readResponse;
/**
* Write Response
*
* @var mixed
*/
protected $writeResponse;
/**
* Set the Response
*
* @param string $str
* @return FeedbackClient
*/
public function setReadResponse($str)
{
$this->readResponse = $str;
return $this;
}
/**
* Set the write response
*
* @param mixed $resp
* @return FeedbackClient
*/
public function setWriteResponse($resp)
{
$this->writeResponse = $resp;
return $this;
}
/**
* Connect to Host
*
* @return FeedbackClient
*/
protected function connect($host, array $ssl)
{
return $this;
}
/**
* Return Response
*
* @param string $length
* @return string
*/
protected function read($length = 1024)
{
if (! $this->isConnected()) {
throw new Exception\RuntimeException('You must open the connection prior to reading data');
}
$ret = substr($this->readResponse, 0, $length);
$this->readResponse = null;
return $ret;
}
/**
* Write and Return Length
*
* @param string $payload
* @return int
*/
protected function write($payload)
{
if (! $this->isConnected()) {
throw new Exception\RuntimeException('You must open the connection prior to writing data');
}
$ret = $this->writeResponse;
$this->writeResponse = null;
return (null === $ret) ? strlen($payload) : $ret;
}
}

View File

@@ -1,109 +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
* @package Zend_Service
*/
namespace ZendServiceTest\Apple\Apns\TestAsset;
use ZendService\Apple\Apns\Exception;
use ZendService\Apple\Apns\Client\Message as ZfMessageClient;
/**
* Message Client Proxy
* This class is utilized for unit testing purposes
*
* @category ZendService
* @package ZendService_Apple
* @subpackage Apns
*/
class MessageClient extends ZfMessageClient
{
/**
* Read Response
*
* @var string
*/
protected $readResponse;
/**
* Write Response
*
* @var mixed
*/
protected $writeResponse;
/**
* Set the Response
*
* @param string $str
* @return MessageClient
*/
public function setReadResponse($str)
{
$this->readResponse = $str;
return $this;
}
/**
* Set the write response
*
* @param mixed $resp
* @return MessageClient
*/
public function setWriteResponse($resp)
{
$this->writeResponse = $resp;
return $this;
}
/**
* Connect to Host
*
* @return MessageClient
*/
protected function connect($host, array $ssl)
{
return $this;
}
/**
* Return Response
*
* @param string $length
* @return string
*/
protected function read($length = 1024)
{
if (! $this->isConnected()) {
throw new Exception\RuntimeException('You must open the connection prior to reading data');
}
$ret = substr($this->readResponse, 0, $length);
$this->readResponse = null;
return $ret;
}
/**
* Write and Return Length
*
* @param string $payload
* @return int
*/
protected function write($payload)
{
if (! $this->isConnected()) {
throw new Exception\RuntimeException('You must open the connection prior to writing data');
}
$ret = $this->writeResponse;
$this->writeResponse = null;
return (null === $ret) ? strlen($payload) : $ret;
}
}