Laravel version update

Laravel version update
This commit is contained in:
Manish Verma
2018-08-06 18:48:58 +05:30
parent d143048413
commit 126fbb0255
13678 changed files with 1031482 additions and 778530 deletions

View File

@@ -1,18 +1,22 @@
sudo: false
language: php
php:
- 5.3
- 5.4
- 5.5
- 5.6
- hhvm
matrix:
include:
- php: 5.6
- php: 7.0
- php: 7.1
env:
- CS_CHECK=true
- php: 7.2
before_install:
- cp tests/TestConfiguration.php.travis tests/TestConfiguration.php
- composer install --dev
- composer install --no-interaction
script:
- phpunit -c tests/phpunit.xml.dist
- ./vendor/bin/phpunit
- if [[ $CS_CHECK == 'true' ]]; then ./vendor/bin/phpcs ; fi
notifications:
#irc: "irc.freenode.org#zftalk.2"
email: false

View File

@@ -2,6 +2,40 @@
All notable changes to this project will be documented in this file, in reverse chronological order by release.
## 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

View File

@@ -1,19 +1,19 @@
Copyright (c) 2005-2014, Zend Technologies USA, Inc.
Copyright (c) 2005-2018, Zend Technologies USA, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
* Neither the name of Zend Technologies USA, Inc. nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
- Neither the name of Zend Technologies USA, Inc. nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED

View File

@@ -4,11 +4,11 @@ ZendService\Apple\Apns [![Build Status](https://travis-ci.org/zendframework/Zend
Provides support for Apple push notifications.
## Requirements ##
## Requirements
* PHP >= 5.3.3
* PHP >= 5.6
## Getting Started ##
## Getting Started
Install this library using [Composer](http://getcomposer.org/):
@@ -16,7 +16,7 @@ Install this library using [Composer](http://getcomposer.org/):
$ composer require zendframework/zendservice-apple-apns
```
## Documentation ##
## Documentation
The documentation can be found at: http://framework.zend.com/manual/current/en/modules/zendservice.apple.apns.html

View File

@@ -1,33 +1,47 @@
{
"name": "zendframework/zendservice-apple-apns",
"description": "OOP Zend Framework 2 wrapper for Apple Push Notification Service",
"type": "library",
"description": "OOP Zend Framework wrapper for Apple Push Notification Service",
"license": "BSD-3-Clause",
"keywords": [
"zf2",
"zf",
"zendframework",
"apns",
"push",
"notification",
"apple"
],
"homepage": "http://packages.zendframework.com/",
"license": "BSD-3-Clause",
"autoload": {
"psr-0": {
"ZendService\\Apple\\Apns\\": "library/",
"ZendService\\Apple\\Exception\\": "library/"
}
"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"
},
"repositories": [
{
"type": "composer",
"url": "http://packages.zendframework.com/"
}
],
"require": {
"php": ">=5.3.3",
"zendframework/zend-json": "~2.0"
"php": "^5.6 || ^7.0",
"zendframework/zend-json": "^2.0 || ^3.0"
},
"require-dev": {
"phpunit/phpunit": "3.7.*"
"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.3.x-dev",
"dev-develop": "1.4.x-dev"
}
}
}

View File

@@ -0,0 +1,7 @@
<?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

@@ -0,0 +1,17 @@
<?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

@@ -29,7 +29,7 @@ abstract class AbstractClient
* APNS URIs
* @var array
*/
protected $uris = array();
protected $uris = [];
/**
* Is Connected
@@ -59,19 +59,19 @@ abstract class AbstractClient
throw new Exception\RuntimeException('Connection has already been opened and must be closed');
}
if (!array_key_exists($environment, $this->uris)) {
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)) {
if (! is_string($certificate) || ! file_exists($certificate)) {
throw new Exception\InvalidArgumentException('Certificate must be a valid path to a APNS certificate');
}
$sslOptions = array(
$sslOptions = [
'local_cert' => $certificate,
);
];
if ($passPhrase !== null) {
if (!is_scalar($passPhrase)) {
if (! is_scalar($passPhrase)) {
throw new Exception\InvalidArgumentException('SSL passphrase must be a scalar');
}
$sslOptions['passphrase'] = $passPhrase;
@@ -103,12 +103,13 @@ abstract class AbstractClient
ini_get('default_socket_timeout'),
STREAM_CLIENT_CONNECT,
stream_context_create(
array(
[
'ssl' => $ssl,
)
]
)
);
} catch (StreamSocketClientException $e) {
restore_error_handler();
throw new Exception\RuntimeException(sprintf(
'Unable to connect: %s: %d (%s)',
$host,
@@ -119,7 +120,7 @@ abstract class AbstractClient
restore_error_handler();
if (!$this->socket) {
if (! $this->socket) {
throw new Exception\RuntimeException(sprintf(
'Unable to connect: %s: %d (%s)',
$host,
@@ -166,11 +167,11 @@ abstract class AbstractClient
*/
protected function read($length = 6)
{
if (!$this->isConnected()) {
if (! $this->isConnected()) {
throw new Exception\RuntimeException('You must open the connection prior to reading data');
}
$data = false;
$read = array($this->socket);
$read = [$this->socket];
$null = null;
if (0 < @stream_select($read, $null, $null, 1, 0)) {
@@ -188,7 +189,7 @@ abstract class AbstractClient
*/
protected function write($payload)
{
if (!$this->isConnected()) {
if (! $this->isConnected()) {
throw new Exception\RuntimeException('You must open the connection prior to writing data');
}

View File

@@ -22,10 +22,10 @@ class Feedback extends AbstractClient
* APNS URIs
* @var array
*/
protected $uris = array(
protected $uris = [
'tls://feedback.sandbox.push.apple.com:2196',
'tls://feedback.push.apple.com:2196'
);
];
/**
* Get Feedback
@@ -34,11 +34,11 @@ class Feedback extends AbstractClient
*/
public function feedback()
{
if (!$this->isConnected()) {
if (! $this->isConnected()) {
throw new Exception\RuntimeException('You must first open the connection by calling open()');
}
$tokens = array();
$tokens = [];
while ($token = $this->read(38)) {
$tokens[] = new FeedbackResponse($token);
}

View File

@@ -29,10 +29,10 @@ class Message extends AbstractClient
* APNS URIs
* @var array
*/
protected $uris = array(
protected $uris = [
'tls://gateway.sandbox.push.apple.com:2195',
'tls://gateway.push.apple.com:2195',
);
];
/**
* Send Message
@@ -42,7 +42,7 @@ class Message extends AbstractClient
*/
public function send(ApnsMessage $message)
{
if (!$this->isConnected()) {
if (! $this->isConnected()) {
throw new Exception\RuntimeException('You must first open the connection by calling open()');
}

View File

@@ -10,8 +10,8 @@
namespace ZendService\Apple\Apns;
use ZendService\Apple\Exception;
use Zend\Json\Encoder as JsonEncoder;
use ZendService\Apple\Exception;
/**
* APNs Message
@@ -54,6 +54,12 @@ class Message
*/
protected $sound;
/**
* Mutable Content
* @var int|null
*/
private $mutableContent;
/**
* Content Available
* @var int|null
@@ -66,7 +72,7 @@ class Message
*/
protected $category;
/**
/**
* URL Arguments
* @var array|null
*/
@@ -96,7 +102,7 @@ class Message
*/
public function setId($id)
{
if (!is_scalar($id)) {
if (! is_scalar($id)) {
throw new Exception\InvalidArgumentException('Identifier must be a scalar value');
}
$this->id = $id;
@@ -122,25 +128,25 @@ class Message
*/
public function setToken($token)
{
if (!is_string($token)) {
if (! is_string($token)) {
throw new Exception\InvalidArgumentException(sprintf(
'Device token must be a string, "%s" given.',
gettype($token)
'Device token must be a string, "%s" given.',
gettype($token)
));
}
if (preg_match('/[^0-9a-f]/', $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
'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)
'Device token must be a 64 charsets, Token length given: %d.',
mb_strlen($token)
));
}
@@ -169,7 +175,7 @@ class Message
{
if ($expire instanceof \DateTime) {
$expire = $expire->getTimestamp();
} elseif (!is_numeric($expire) || $expire != (int) $expire) {
} elseif (! is_numeric($expire) || $expire != (int) $expire) {
throw new Exception\InvalidArgumentException('Expiration must be a DateTime object or a unix timestamp');
}
$this->expire = $expire;
@@ -195,7 +201,7 @@ class Message
*/
public function setAlert($alert)
{
if (!$alert instanceof Message\Alert && !is_null($alert)) {
if (! $alert instanceof Message\Alert && ! is_null($alert)) {
$alert = new Message\Alert($alert);
}
$this->alert = $alert;
@@ -221,7 +227,7 @@ class Message
*/
public function setBadge($badge)
{
if ($badge !== null && !$badge == (int) $badge) {
if ($badge !== null && ! $badge == (int) $badge) {
throw new Exception\InvalidArgumentException('Badge must be null or an integer');
}
$this->badge = $badge;
@@ -247,7 +253,7 @@ class Message
*/
public function setSound($sound)
{
if ($sound !== null && !is_string($sound)) {
if ($sound !== null && ! is_string($sound)) {
throw new Exception\InvalidArgumentException('Sound must be null or a string');
}
$this->sound = $sound;
@@ -255,6 +261,29 @@ class Message
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
*
@@ -268,12 +297,12 @@ class Message
/**
* Set Content Available
*
* @param int|null $sound
* @param int|null $value
* @return Message
*/
public function setContentAvailable($value)
{
if ($value !== null && !is_int($value)) {
if ($value !== null && ! is_int($value)) {
throw new Exception\InvalidArgumentException('Content Available must be null or an integer');
}
$this->contentAvailable = $value;
@@ -299,7 +328,7 @@ class Message
*/
public function setCategory($category)
{
if ($category !== null && !is_string($category)) {
if ($category !== null && ! is_string($category)) {
throw new Exception\InvalidArgumentException('Category must be null or a string');
}
$this->category = $category;
@@ -366,32 +395,34 @@ class Message
*/
public function getPayload()
{
$message = array();
$aps = array();
$message = [];
$aps = [];
if ($this->alert && ($alert = $this->alert->getPayload())) {
$aps['alert'] = $alert;
}
if (!is_null($this->badge)) {
if (! is_null($this->badge)) {
$aps['badge'] = $this->badge;
}
if (!is_null($this->sound)) {
if (! is_null($this->sound)) {
$aps['sound'] = $this->sound;
}
if (!is_null($this->contentAvailable)) {
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)) {
if (! is_null($this->category)) {
$aps['category'] = $this->category;
}
if (!is_null($this->urlArgs)) {
if (! is_null($this->urlArgs)) {
$aps['url-args'] = $this->urlArgs;
}
if (!empty($this->custom)) {
if (! empty($this->custom)) {
$message = array_merge($this->custom, $message);
}
if (!empty($aps)) {
$message['aps'] = $aps;
}
$message['aps'] = empty($aps) ? (object) [] : $aps;
return $message;
}

View File

@@ -23,6 +23,12 @@ class Alert
*/
protected $body;
/**
* Action
* @var string|null
*/
protected $action;
/**
* Action Locale Key
* @var string|null
@@ -46,19 +52,19 @@ class Alert
* @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
@@ -75,8 +81,16 @@ class Alert
* @param string $launchImage
* @return Alert
*/
public function __construct($body = null, $actionLocKey = null, $locKey = null, $locArgs = null, $launchImage = null, $title = null, $titleLocKey = null, $titleLocArgs = null)
{
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);
}
@@ -121,14 +135,40 @@ class Alert
*/
public function setBody($body)
{
if (!is_null($body) && !is_scalar($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
*
@@ -147,7 +187,7 @@ class Alert
*/
public function setActionLocKey($key)
{
if (!is_null($key) && !is_scalar($key)) {
if (! is_null($key) && ! is_scalar($key)) {
throw new Exception\InvalidArgumentException('ActionLocKey must be null OR a scalar value');
}
$this->actionLocKey = $key;
@@ -173,7 +213,7 @@ class Alert
*/
public function setLocKey($key)
{
if (!is_null($key) && !is_scalar($key)) {
if (! is_null($key) && ! is_scalar($key)) {
throw new Exception\InvalidArgumentException('LocKey must be null OR a scalar value');
}
$this->locKey = $key;
@@ -200,7 +240,7 @@ class Alert
public function setLocArgs(array $args)
{
foreach ($args as $a) {
if (!is_scalar($a)) {
if (! is_scalar($a)) {
throw new Exception\InvalidArgumentException('Arguments must only contain scalar values');
}
}
@@ -227,10 +267,10 @@ class Alert
*/
public function setLaunchImage($image)
{
if (!is_null($image) && !is_scalar($image)) {
if (! is_null($image) && ! is_scalar($image)) {
throw new Exception\InvalidArgumentException('Launch image must be null OR a scalar value');
}
$this->launchImage = $image;
$this->launchImage = $image;
return $this;
}
@@ -253,14 +293,14 @@ class Alert
*/
public function setTitle($title)
{
if (!is_null($title) && !is_scalar($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
*
@@ -279,14 +319,14 @@ class Alert
*/
public function setTitleLocKey($key)
{
if (!is_null($key) && !is_scalar($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
*
@@ -306,7 +346,7 @@ class Alert
public function setTitleLocArgs(array $args)
{
foreach ($args as $a) {
if (!is_scalar($a)) {
if (! is_scalar($a)) {
throw new Exception\InvalidArgumentException('Title Arguments must only contain scalar values');
}
}
@@ -328,9 +368,9 @@ class Alert
return null;
}
$alert = array();
$alert = [];
foreach ($vars as $key => $value) {
if (!is_null($value)) {
if (! is_null($value)) {
$key = strtolower(preg_replace('/([a-z])([A-Z])/', '$1-$2', $key));
$alert[$key] = $value;
}

View File

@@ -59,7 +59,7 @@ class Feedback
*/
public function setToken($token)
{
if (!is_scalar($token)) {
if (! is_scalar($token)) {
throw new Exception\InvalidArgumentException('Token must be a scalar value');
}
$this->token = $token;

View File

@@ -107,7 +107,7 @@ class Message
*/
public function setId($id)
{
if (!is_scalar($id)) {
if (! is_scalar($id)) {
throw new Exception\InvalidArgumentException('Identifier must be a scalar value');
}
$this->id = $id;
@@ -123,7 +123,7 @@ class Message
*/
public function parseRawResponse($rawResponse)
{
if (!is_scalar($rawResponse)) {
if (! is_scalar($rawResponse)) {
throw new Exception\InvalidArgumentException('Response must be a scalar value');
}

View File

@@ -10,6 +10,7 @@
namespace ZendServiceTest\Apple\Apns;
use PHPUnit\Framework\TestCase;
use ZendServiceTest\Apple\Apns\TestAsset\FeedbackClient;
/**
@@ -20,7 +21,7 @@ use ZendServiceTest\Apple\Apns\TestAsset\FeedbackClient;
* @group ZendService_Apple
* @group ZendService_Apple_Apns
*/
class FeedbackClientTest extends \PHPUnit_Framework_TestCase
class FeedbackClientTest extends TestCase
{
public function setUp()
{

View File

@@ -12,6 +12,7 @@
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;
@@ -24,7 +25,7 @@ use ZendService\Apple\Apns\Response\Message as MessageResponse;
* @group ZendService_Apple
* @group ZendService_Apple_Apns
*/
class MessageClientTest extends \PHPUnit_Framework_TestCase
class MessageClientTest extends TestCase
{
public function setUp()
{
@@ -42,26 +43,26 @@ class MessageClientTest extends \PHPUnit_Framework_TestCase
public function testConnectThrowsExceptionOnInvalidEnvironment()
{
$this->setExpectedException('InvalidArgumentException');
$this->expectException('InvalidArgumentException');
$this->apns->open(5, __DIR__ . '/TestAsset/certificate.pem');
}
public function testSetCertificateThrowsExceptionOnNonString()
{
$this->setExpectedException('InvalidArgumentException');
$this->apns->open(MessageClient::PRODUCTION_URI, array('foo'));
$this->expectException('InvalidArgumentException');
$this->apns->open(MessageClient::PRODUCTION_URI, ['foo']);
}
public function testSetCertificateThrowsExceptionOnMissingFile()
{
$this->setExpectedException('InvalidArgumentException');
$this->expectException('InvalidArgumentException');
$this->apns->open(MessageClient::PRODUCTION_URI, 'foo');
}
public function testSetCertificatePassphraseThrowsExceptionOnNonString()
{
$this->setExpectedException('InvalidArgumentException');
$this->apns->open(MessageClient::PRODUCTION_URI, __DIR__ . '/TestAsset/certificate.pem', array('foo'));
$this->expectException('InvalidArgumentException');
$this->apns->open(MessageClient::PRODUCTION_URI, __DIR__ . '/TestAsset/certificate.pem', ['foo']);
}
public function testOpen()
@@ -80,7 +81,7 @@ class MessageClientTest extends \PHPUnit_Framework_TestCase
public function testOpenWhenAlreadyOpenThrowsException()
{
$this->setExpectedException('RuntimeException');
$this->expectException('RuntimeException');
$this->apns->open(MessageClient::SANDBOX_URI, __DIR__ . '/TestAsset/certificate.pem');
$this->apns->open(MessageClient::SANDBOX_URI, __DIR__ . '/TestAsset/certificate.pem');
}

View File

@@ -1,18 +1,18 @@
<?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
* @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\TestAsset;
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;
use Zend\Json\Encoder as JsonEncoder;
/**
* @category ZendService
@@ -22,7 +22,7 @@ use Zend\Json\Encoder as JsonEncoder;
* @group ZendService_Apple
* @group ZendService_Apple_Apns
*/
class MessageTest extends \PHPUnit_Framework_TestCase
class MessageTest extends TestCase
{
public function setUp()
{
@@ -42,38 +42,38 @@ class MessageTest extends \PHPUnit_Framework_TestCase
public function testSetAlertThrowsExceptionOnTextNonString()
{
$this->setExpectedException('InvalidArgumentException');
$this->message->setAlert(array());
$this->expectException(InvalidArgumentException::class);
$this->message->setAlert([]);
}
public function testSetAlertThrowsExceptionOnActionLocKeyNonString()
{
$this->setExpectedException('InvalidArgumentException');
$this->alert->setActionLocKey(array());
$this->expectException(InvalidArgumentException::class);
$this->alert->setActionLocKey([]);
}
public function testSetAlertThrowsExceptionOnLocKeyNonString()
{
$this->setExpectedException('InvalidArgumentException');
$this->alert->setLocKey(array());
$this->expectException(InvalidArgumentException::class);
$this->alert->setLocKey([]);
}
public function testSetAlertThrowsExceptionOnLaunchImageNonString()
{
$this->setExpectedException('InvalidArgumentException');
$this->alert->setLaunchImage(array());
$this->expectException(InvalidArgumentException::class);
$this->alert->setLaunchImage([]);
}
public function testSetAlertThrowsExceptionOnTitleNonString()
{
$this->setExpectedException('InvalidArgumentException');
$this->alert->setTitle(array());
$this->expectException(InvalidArgumentException::class);
$this->alert->setTitle([]);
}
public function testSetAlertThrowsExceptionOnTitleLocKeyNonString()
{
$this->setExpectedException('InvalidArgumentException');
$this->alert->setTitleLocKey(array());
$this->expectException(InvalidArgumentException::class);
$this->alert->setTitleLocKey([]);
}
public function testSetBadgeReturnsCorrectNumber()
@@ -85,7 +85,7 @@ class MessageTest extends \PHPUnit_Framework_TestCase
public function testSetBadgeNonNumericThrowsException()
{
$this->setExpectedException('InvalidArgumentException');
$this->expectException(InvalidArgumentException::class);
$this->message->setBadge('string!');
}
@@ -104,7 +104,7 @@ class MessageTest extends \PHPUnit_Framework_TestCase
public function testSetExpireNonNumericThrowsException()
{
$this->setExpectedException('InvalidArgumentException');
$this->expectException(InvalidArgumentException::class);
$this->message->setExpire('sting!');
}
@@ -117,19 +117,63 @@ class MessageTest extends \PHPUnit_Framework_TestCase
public function testSetSoundThrowsExceptionOnNonScalar()
{
$this->setExpectedException('InvalidArgumentException');
$this->message->setSound(array());
$this->expectException(InvalidArgumentException::class);
$this->message->setSound([]);
}
public function testSetSoundThrowsExceptionOnNonString()
{
$this->setExpectedException('InvalidArgumentException');
$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->setExpectedException('InvalidArgumentException');
$this->expectException(InvalidArgumentException::class);
$this->message->setContentAvailable("string");
}
@@ -157,26 +201,26 @@ class MessageTest extends \PHPUnit_Framework_TestCase
public function testSetCategoryThrowsExceptionOnNonScalar()
{
$this->setExpectedException('InvalidArgumentException');
$this->message->setCategory(array());
$this->expectException(InvalidArgumentException::class);
$this->message->setCategory([]);
}
public function testSetCategoryThrowsExceptionOnNonString()
{
$this->setExpectedException('InvalidArgumentException');
$this->expectException(InvalidArgumentException::class);
$this->message->setCategory(12345);
}
public function testSetUrlArgsReturnsString()
{
$urlArgs = array('path/to/somewhere');
$urlArgs = ['path/to/somewhere'];
$this->message->setUrlArgs($urlArgs);
$this->assertEquals($urlArgs, $this->message->getUrlArgs());
}
public function testSetCustomData()
{
$data = array('key' => 'val', 'key2' => array(1, 2, 3, 4, 5));
$data = ['key' => 'val', 'key2' => [1, 2, 3, 4, 5]];
$this->message->setCustom($data);
$this->assertEquals($data, $this->message->getCustom());
}
@@ -187,21 +231,21 @@ class MessageTest extends \PHPUnit_Framework_TestCase
'Foo wants to play Bar!',
'PLAY',
'GAME_PLAY_REQUEST_FORMAT',
array('Foo', 'Baz'),
['Foo', 'Baz'],
'Default.png',
'Alert',
'ALERT',
array('Foo', 'Baz')
['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(array('Foo', 'Baz'), $alert->getLocArgs());
$this->assertEquals(['Foo', 'Baz'], $alert->getLocArgs());
$this->assertEquals('Default.png', $alert->getLaunchImage());
$this->assertEquals('Alert', $alert->getTitle());
$this->assertEquals('ALERT', $alert->getTitleLocKey());
$this->assertEquals(array('Foo', 'Baz'), $alert->getTitleLocArgs());
$this->assertEquals(['Foo', 'Baz'], $alert->getTitleLocArgs());
}
public function testAlertJsonPayload()
@@ -210,11 +254,11 @@ class MessageTest extends \PHPUnit_Framework_TestCase
'Foo wants to play Bar!',
'PLAY',
'GAME_PLAY_REQUEST_FORMAT',
array('Foo', 'Baz'),
['Foo', 'Baz'],
'Default.png',
'Alert',
'ALERT',
array('Foo', 'Baz')
['Foo', 'Baz']
);
$payload = $alert->getPayload();
@@ -244,32 +288,56 @@ class MessageTest extends \PHPUnit_Framework_TestCase
$this->message->setExpire(100);
$this->message->setToken('0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef');
$payload = $this->message->getPayload();
$this->assertEquals($payload, array('aps' => array('alert' => 'hi=привет')));
$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;
$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 per letter constructions
$result = pack('CNNnH*', 1, $this->message->getId(), $this->message->getExpire(), 32, $this->message->getToken())
. pack('n', $length)
. $payloadJson;
$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 testCustomDataPayloadDoesNotIncludeEmptyApsData()
public function testCustomDataPayloadIncludesEmptyApsObject()
{
$data = array('custom' => 'data');
$data = ['custom' => 'data'];
$expected = array_merge($data, ['aps' => (object) []]);
$this->message->setCustom($data);
$payload = $this->message->getPayload();
$this->assertEquals($payload, array('custom' => 'data'));
$this->assertEquals($expected, $payload);
}
public function testTokensAllowUpperCaseHex()
{
$token = str_repeat('abc1234defABCDEF', 4);
$this->message->setToken($token);
$this->assertSame($token, $this->message->getToken());
}
}

View File

@@ -81,7 +81,7 @@ class FeedbackClient extends ZfFeedbackClient
*/
protected function read($length = 1024)
{
if (!$this->isConnected()) {
if (! $this->isConnected()) {
throw new Exception\RuntimeException('You must open the connection prior to reading data');
}
$ret = substr($this->readResponse, 0, $length);
@@ -98,7 +98,7 @@ class FeedbackClient extends ZfFeedbackClient
*/
protected function write($payload)
{
if (!$this->isConnected()) {
if (! $this->isConnected()) {
throw new Exception\RuntimeException('You must open the connection prior to writing data');
}
$ret = $this->writeResponse;

View File

@@ -81,7 +81,7 @@ class MessageClient extends ZfMessageClient
*/
protected function read($length = 1024)
{
if (!$this->isConnected()) {
if (! $this->isConnected()) {
throw new Exception\RuntimeException('You must open the connection prior to reading data');
}
$ret = substr($this->readResponse, 0, $length);
@@ -98,7 +98,7 @@ class MessageClient extends ZfMessageClient
*/
protected function write($payload)
{
if (!$this->isConnected()) {
if (! $this->isConnected()) {
throw new Exception\RuntimeException('You must open the connection prior to writing data');
}
$ret = $this->writeResponse;

View File

@@ -1,2 +0,0 @@
phpunit.xml
TestConfiguration.php

View File

@@ -1,93 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 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);
if (class_exists('PHPUnit_Runner_Version', true)) {
$phpUnitVersion = PHPUnit_Runner_Version::id();
if ('@package_version@' !== $phpUnitVersion && version_compare($phpUnitVersion, '3.7.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 = new PHP_CodeCoverage_Filter();
$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);

View File

@@ -1,45 +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 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');

View File

@@ -1,20 +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 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';

View File

@@ -1,29 +0,0 @@
<?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;
});

View File

@@ -1,13 +0,0 @@
<phpunit bootstrap="./Bootstrap.php" colors="true">
<testsuites>
<testsuite name="ZendService Apple Apns Test Suite">
<directory>./ZendService</directory>
</testsuite>
</testsuites>
<groups>
<exclude>
<group>disable</group>
</exclude>
</groups>
</phpunit>