composer-update-patch

This commit is contained in:
Manish Verma
2016-11-03 05:44:29 +05:30
parent 2dca47f5a4
commit 5d49d384a0
5118 changed files with 51603 additions and 122575 deletions

View File

@@ -1,13 +1,17 @@
language: php
php:
- 5.3
- 5.4
- 5.5
- 5.6
before_script:
- wget http://getcomposer.org/composer.phar
- php composer.phar install --dev --prefer-source
- composer self-update || true
- composer install --dev --prefer-source
- mkdir -p web/code-coverage data
- wget https://scrutinizer-ci.com/ocular.phar
after_script:
- php ocular.phar code-coverage:upload --format=php-clover data/coverage.clover
script:
- bin/atoum
@@ -18,5 +22,3 @@ notifications:
- cedric@dugat.me
on_success: change
on_failure: change
irc:
- "irc.freenode.org#slynett"

View File

@@ -1,17 +1,18 @@
# NotificationPusher
# NotificationPusher [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ph3nol/notificationpusher?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Standalone PHP library for easy devices message notifications push.
[![Latest Stable Version](https://poser.pugx.org/sly/notification-pusher/v/stable.png)](https://packagist.org/packages/sly/notification-pusher)
[![Total Downloads](https://poser.pugx.org/sly/notification-pusher/downloads.png)](https://packagist.org/packages/sly/notification-pusher)
[![Build Status](https://secure.travis-ci.org/Ph3nol/NotificationPusher.png)](http://travis-ci.org/Ph3nol/NotificationPusher)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/4f6f80c4-281a-4903-bf4c-1eb264995dbd/big.png)](https://insight.sensiolabs.com/projects/4f6f80c4-281a-4903-bf4c-1eb264995dbd)
**Feel free to contribute! Thanks.**
## Requirements
* PHP 5.3+
* PHP 5.5+
* PHP Curl and OpenSSL modules
* Specific adapters requirements (like APNS certificate, GCM API key, etc.)

View File

@@ -16,13 +16,14 @@
}
],
"require": {
"php": ">=5.3.2",
"php": ">=5.5",
"symfony/options-resolver": ">=2.3",
"symfony/console": ">=2.3",
"symfony/process": ">=2.3",
"zendframework/zendservice-apple-apns": "1.*",
"zendframework/zendservice-google-gcm": "1.*"
"symfony/options-resolver": "~2.3|~3.0",
"symfony/console": "~2.3|~3.0",
"symfony/process": "~2.3|~3.0",
"zendframework/zendservice-apple-apns": "^1.1.0",
"zendframework/zendservice-google-gcm": "1.*",
"doctrine/inflector": "~1.0"
},
"require-dev": {
"atoum/atoum": "dev-master"
@@ -30,9 +31,10 @@
"config": {
"bin-dir": "bin"
},
"bin": ["np"],
"autoload": {
"psr-0": {
"Sly": ["src/"]
"Sly": "src/"
}
}
}

View File

@@ -22,7 +22,7 @@ use Sly\NotificationPusher\PushManager,
// First, instantiate the manager.
//
// Example for production environment:
// $pushManager = new PushManager(PushManager::ENVIRONMENT_PRODUCTION);
// $pushManager = new PushManager(PushManager::ENVIRONMENT_PROD);
//
// Development one by default (without argument).
$pushManager = new PushManager(PushManager::ENVIRONMENT_DEV);
@@ -65,7 +65,7 @@ use Sly\NotificationPusher\PushManager,
// First, instantiate the manager.
//
// Example for production environment:
// $pushManager = new PushManager(PushManager::ENVIRONMENT_PRODUCTION);
// $pushManager = new PushManager(PushManager::ENVIRONMENT_PROD);
//
// Development one by default (without argument).
$pushManager = new PushManager(PushManager::ENVIRONMENT_DEV);
@@ -124,7 +124,7 @@ use Sly\NotificationPusher\PushManager,
// First, instantiate the manager.
//
// Example for production environment:
// $pushManager = new PushManager(PushManager::ENVIRONMENT_PRODUCTION);
// $pushManager = new PushManager(PushManager::ENVIRONMENT_PROD);
//
// Development one by default (without argument).
$pushManager = new PushManager(PushManager::ENVIRONMENT_DEV);

View File

@@ -2,8 +2,8 @@
## Create an adapter
To create your own adapter, just create a class with taking care to extends `\Sly\NotificationPusher\Adapter\BaseAdapter`
and implements `\Sly\NotificationPusher\Adapter\AdapterInterface` which contains some required methods:
To create your own adapter, just create a class with taking care to extends `\Sly\NotificationPusher\Adapter\BaseAdapter`,
which implicitly implements `\Sly\NotificationPusher\Adapter\AdapterInterface` which contains some required methods:
* `push`: contains the adapter logic to push notifications
* `supports`: return the token condition for using the adapter

View File

@@ -20,10 +20,10 @@ use Sly\NotificationPusher\PushManager,
;
// First, instantiate the manager.
//
//
// Example for production environment:
// $pushManager = new PushManager(PushManager::ENVIRONMENT_PRODUCTION);
//
// $pushManager = new PushManager(PushManager::ENVIRONMENT_PROD);
//
// Development one by default (without argument).
$pushManager = new PushManager(PushManager::ENVIRONMENT_DEV);

View File

@@ -20,22 +20,22 @@ Here is how to translate this with code (just a little not-working example):
<?php
// First, instantiate the manager and declare an adapter.
$pushManager = new PushManager();
$exampleAdapter = new ApnsAdapter();
$pushManager = new Sly\NotificationPusher\PushManager();
$exampleAdapter = new Sly\NotificationPusher\Adapter\Apns();
// Set the device(s) to push the notification to.
$devices = new DeviceCollection(array(
new Device('Token1'),
new Device('Token2'),
new Device('Token3'),
$devices = new Sly\NotificationPusher\Collection\DeviceCollection(array(
new Sly\NotificationPusher\Model\Device('Token1'),
new Sly\NotificationPusher\Model\Device('Token2'),
new Sly\NotificationPusher\Model\Device('Token3'),
// ...
));
// Then, create the push skel.
$message = new Message('This is an example.');
$message = new Sly\NotificationPusher\Model\Message('This is an example.');
// Finally, create and add the push to the manager, and push it!
$push = new Push($exampleAdapter, $devices, $message);
$push = new Sly\NotificationPusher\Model\Push($exampleAdapter, $devices, $message);
$pushManager->add($push);
$pushManager->push();
```
@@ -49,7 +49,7 @@ instance constructor second argument:
``` php
<?php
$message = new Message('This is an example.', array(
$message = new Sly\NotificationPusher\Model\Message('This is an example.', array(
'badge' => 1,
'sound' => 'example.aiff',
// ...
@@ -66,13 +66,13 @@ Here is an example of this:
``` php
<?php
$message = new Message('This is an example.', array(
$message = new Sly\NotificationPusher\Model\Message('This is an example.', array(
'badge' => 1,
// ...
));
$devices = new DeviceCollection(array(
new Device('Token1', array('badge' => 5)),
$devices = new Sly\NotificationPusher\Collection\DeviceCollection(array(
new Sly\NotificationPusher\Model\Device('Token1', array('badge' => 5)),
// ...
));
```

View File

@@ -4,13 +4,7 @@
Use [Composer](http://getcomposer.org) to install this library.
Into your `composer.json` file, just include this library with adding:
```
"sly/notification-pusher": "2.x"
```
Then, run `composer update sly/notification-pusher` and enjoy.
Run `composer require sly/notification-pusher` to install the latest version.
## Documentation index
@@ -20,4 +14,3 @@ Then, run `composer update sly/notification-pusher` and enjoy.
* [GCM adapter](https://github.com/Ph3nol/NotificationPusher/blob/master/doc/gcm-adapter.md)
* [Create an adapter](https://github.com/Ph3nol/NotificationPusher/blob/master/doc/create-an-adapter.md)
* [Push from CLI](https://github.com/Ph3nol/NotificationPusher/blob/master/doc/push-from-cli.md)
* [Push from CLI](https://github.com/Ph3nol/NotificationPusher/blob/master/doc/push-from-cli.md)

View File

@@ -38,6 +38,13 @@ interface AdapterInterface
*/
public function supports($token);
/**
* Get defined parameters.
*
* @return array
*/
public function getDefinedParameters();
/**
* Get default parameters.
*

View File

@@ -11,8 +11,8 @@
namespace Sly\NotificationPusher\Adapter;
use Sly\NotificationPusher\Model\BaseOptionedModel;
use Sly\NotificationPusher\Model\PushInterface;
use Sly\NotificationPusher\Model\MessageInterface;
use Sly\NotificationPusher\Model\DeviceInterface;
use Sly\NotificationPusher\Exception\AdapterException;
use Sly\NotificationPusher\Exception\PushException;
@@ -30,18 +30,24 @@ use ZendService\Apple\Apns\Client\Feedback as ServiceFeedbackClient;
* APNS adapter.
*
* @uses \Sly\NotificationPusher\Adapter\BaseAdapter
* @uses \Sly\NotificationPusher\Adapter\AdapterInterface
*
* @author Cédric Dugat <cedric@dugat.me>
*/
class Apns extends BaseAdapter implements AdapterInterface
class Apns extends BaseAdapter
{
/** @var ServiceClient */
private $openedClient;
/** @var ServiceFeedbackClient */
private $feedbackClient;
/**
* {@inheritdoc}
*
* @throws \Sly\NotificationPusher\Exception\AdapterException
*/
public function __construct(array $parameters = array())
public function __construct(array $parameters = [])
{
parent::__construct($parameters);
@@ -59,7 +65,7 @@ class Apns extends BaseAdapter implements AdapterInterface
*/
public function push(PushInterface $push)
{
$client = $this->getOpenedClient(new ServiceClient());
$client = $this->getOpenedServiceClient();
$pushedDevices = new DeviceCollection();
@@ -77,8 +83,6 @@ class Apns extends BaseAdapter implements AdapterInterface
}
}
$client->close();
return $pushedDevices;
}
@@ -89,13 +93,12 @@ class Apns extends BaseAdapter implements AdapterInterface
*/
public function getFeedback()
{
$client = $this->getOpenedClient(new ServiceFeedbackClient());
$responses = array();
$client = $this->getOpenedFeedbackClient();
$responses = [];
$serviceResponses = $client->feedback();
$client->close();
foreach ($serviceResponses as $response) {
$responses[$response->getToken()] = new \DateTime(date("c", $response->getTime()));
$responses[$response->getToken()] = new \DateTime(date('c', $response->getTime()));
}
return $responses;
@@ -119,29 +122,62 @@ class Apns extends BaseAdapter implements AdapterInterface
return $client;
}
/**
* Get opened ServiceClient
*
* @return ServiceAbstractClient
*/
private function getOpenedServiceClient()
{
if (!isset($this->openedClient)) {
$this->openedClient = $this->getOpenedClient(new ServiceClient());
}
return $this->openedClient;
}
/**
* Get opened ServiceFeedbackClient
*
* @return ServiceAbstractClient
*/
private function getOpenedFeedbackClient()
{
if (!isset($this->feedbackClient)) {
$this->feedbackClient = $this->getOpenedClient(new ServiceFeedbackClient());
}
return $this->feedbackClient;
}
/**
* Get service message from origin.
*
* @param \Sly\NotificationPusher\Model\DeviceInterface $device Device
* @param \Sly\NotificationPusher\Model\MessageInterface $message Message
* @param \Sly\NotificationPusher\Model\DeviceInterface $device Device
* @param BaseOptionedModel|\Sly\NotificationPusher\Model\MessageInterface $message Message
*
* @return \ZendService\Apple\Apns\Message
*/
public function getServiceMessageFromOrigin(DeviceInterface $device, MessageInterface $message)
public function getServiceMessageFromOrigin(DeviceInterface $device, BaseOptionedModel $message)
{
$badge = ($message->hasOption('badge'))
? (int) ($message->getOption('badge') + $device->getParameter('badge', 0))
: 0
: false
;
$sound = $message->getOption('sound', 'bingbong.aiff');
$contentAvailable = $message->getOption('content-available');
$category = $message->getOption('category');
$alert = new ServiceAlert(
$message->getText(),
$message->getOption('actionLocKey'),
$message->getOption('locKey'),
$message->getOption('locArgs'),
$message->getOption('launchImage')
$message->getOption('launchImage'),
$message->getOption('title'),
$message->getOption('titleLocKey'),
$message->getOption('titleLocArgs')
);
if ($actionLocKey = $message->getOption('actionLocKey')) {
$alert->setActionLocKey($actionLocKey);
@@ -155,18 +191,37 @@ class Apns extends BaseAdapter implements AdapterInterface
if ($launchImage = $message->getOption('launchImage')) {
$alert->setLaunchImage($launchImage);
}
if ($title = $message->getOption('title')) {
$alert->setTitle($title);
}
if ($titleLocKey = $message->getOption('titleLocKey')) {
$alert->setTitleLocKey($titleLocKey);
}
if ($titleLocArgs = $message->getOption('titleLocArgs')) {
$alert->setTitleLocArgs($titleLocArgs);
}
$serviceMessage = new ServiceMessage();
$serviceMessage->setId(sha1($device->getToken().$message->getText()));
$serviceMessage->setAlert($alert);
$serviceMessage->setToken($device->getToken());
$serviceMessage->setBadge($badge);
$serviceMessage->setCustom($message->getOption('custom', array()));
if (false !== $badge) {
$serviceMessage->setBadge($badge);
}
$serviceMessage->setCustom($message->getOption('custom', []));
if (null !== $sound) {
$serviceMessage->setSound($sound);
}
if (null !== $contentAvailable) {
$serviceMessage->setContentAvailable($contentAvailable);
}
if (null !== $category) {
$serviceMessage->setCategory($category);
}
return $serviceMessage;
}
@@ -178,12 +233,20 @@ class Apns extends BaseAdapter implements AdapterInterface
return (ctype_xdigit($token) && 64 == strlen($token));
}
/**
* {@inheritdoc}
*/
public function getDefinedParameters()
{
return [];
}
/**
* {@inheritdoc}
*/
public function getDefaultParameters()
{
return array('passPhrase' => null);
return ['passPhrase' => null];
}
/**
@@ -191,6 +254,6 @@ class Apns extends BaseAdapter implements AdapterInterface
*/
public function getRequiredParameters()
{
return array('certificate');
return ['certificate'];
}
}

View File

@@ -21,7 +21,7 @@ use Sly\NotificationPusher\PushManager;
*
* @author Cédric Dugat <cedric@dugat.me>
*/
abstract class BaseAdapter extends BaseParameteredModel
abstract class BaseAdapter extends BaseParameteredModel implements AdapterInterface
{
/**
* @var string
@@ -43,9 +43,10 @@ abstract class BaseAdapter extends BaseParameteredModel
*
* @param array $parameters Adapter specific parameters
*/
public function __construct(array $parameters = array())
public function __construct(array $parameters = [])
{
$resolver = new OptionsResolver();
$resolver->setDefined($this->getDefinedParameters());
$resolver->setDefaults($this->getDefaultParameters());
$resolver->setRequired($this->getRequiredParameters());
@@ -66,7 +67,7 @@ abstract class BaseAdapter extends BaseParameteredModel
/**
* Return the original response.
*
*
* @return mixed
*/
public function getResponse()

View File

@@ -11,8 +11,8 @@
namespace Sly\NotificationPusher\Adapter;
use Sly\NotificationPusher\Model\BaseOptionedModel;
use Sly\NotificationPusher\Model\PushInterface;
use Sly\NotificationPusher\Model\MessageInterface;
use Sly\NotificationPusher\Collection\DeviceCollection;
use Sly\NotificationPusher\Exception\PushException;
@@ -29,23 +29,27 @@ use InvalidArgumentException;
* GCM adapter.
*
* @uses \Sly\NotificationPusher\Adapter\BaseAdapter
* @uses \Sly\NotificationPusher\Adapter\AdapterInterface
*
* @author Cédric Dugat <cedric@dugat.me>
*/
class Gcm extends BaseAdapter implements AdapterInterface
class Gcm extends BaseAdapter
{
/**
* @var \Zend\Http\Client
*/
private $httpClient;
/**
* @var ServiceClient
*/
private $openedClient;
/**
* {@inheritdoc}
*/
public function supports($token)
{
return (bool) preg_match('/[0-9a-zA-Z\-\_]/i', $token);
return is_string($token) && $token != '';
}
/**
@@ -55,7 +59,7 @@ class Gcm extends BaseAdapter implements AdapterInterface
*/
public function push(PushInterface $push)
{
$client = $this->getOpenedClient(new ServiceClient());
$client = $this->getOpenedClient();
$pushedDevices = new DeviceCollection();
$tokens = array_chunk($push->getDevices()->getTokens(), 100);
@@ -81,30 +85,37 @@ class Gcm extends BaseAdapter implements AdapterInterface
/**
* Get opened client.
*
* @param \ZendService\Google\Gcm\Client $client Client
*
* @return \ZendService\Google\Gcm\Client
*/
public function getOpenedClient(ServiceClient $client)
public function getOpenedClient()
{
$client->setApiKey($this->getParameter('apiKey'));
if ($this->httpClient !== null) {
$client->setHttpClient($this->httpClient);
if (!isset($this->openedClient)) {
$this->openedClient = new ServiceClient();
$this->openedClient->setApiKey($this->getParameter('apiKey'));
$newClient = new \Zend\Http\Client(
null,
[
'adapter' => 'Zend\Http\Client\Adapter\Socket',
'sslverifypeer' => false
]
);
$this->openedClient->setHttpClient($newClient);
}
return $client;
return $this->openedClient;
}
/**
* Get service message from origin.
*
* @param array $tokens Tokens
* @param \Sly\NotificationPusher\Model\MessageInterface $message Message
* @param array $tokens Tokens
* @param BaseOptionedModel|\Sly\NotificationPusher\Model\MessageInterface $message Message
*
* @return \ZendService\Google\Gcm\Message
*/
public function getServiceMessageFromOrigin(array $tokens, MessageInterface $message)
public function getServiceMessageFromOrigin(array $tokens, BaseOptionedModel $message)
{
$data = $message->getOptions();
$data['message'] = $message->getText();
@@ -121,12 +132,26 @@ class Gcm extends BaseAdapter implements AdapterInterface
return $serviceMessage;
}
/**
* {@inheritdoc}
*/
public function getDefinedParameters()
{
return [
'collapse_key',
'delay_while_idle',
'time_to_live',
'restricted_package_name',
'dry_run'
];
}
/**
* {@inheritdoc}
*/
public function getDefaultParameters()
{
return array();
return [];
}
/**
@@ -134,10 +159,9 @@ class Gcm extends BaseAdapter implements AdapterInterface
*/
public function getRequiredParameters()
{
return array('apiKey');
return ['apiKey'];
}
/**
* Get the current Zend Http Client instance.
*
@@ -150,7 +174,7 @@ class Gcm extends BaseAdapter implements AdapterInterface
/**
* Overrides the default Http Client.
*
*
* @param HttpClient $client
*/
public function setHttpClient(HttpClient $client)
@@ -160,12 +184,12 @@ class Gcm extends BaseAdapter implements AdapterInterface
/**
* Send custom parameters to the Http Adapter without overriding the Http Client.
*
*
* @param array $config
*
* @throws \InvalidArgumentException
*/
public function setAdapterParameters(array $config = array())
public function setAdapterParameters(array $config = [])
{
if (!is_array($config) || empty($config)) {
throw new InvalidArgumentException('$config must be an associative array with at least 1 item.');

View File

@@ -23,7 +23,7 @@ abstract class AbstractCollection
* @var \ArrayIterator
*/
protected $coll;
/**
* Get.
*
@@ -53,7 +53,7 @@ abstract class AbstractCollection
*/
public function isEmpty()
{
return (bool) $this->count();
return $this->count() === 0;
}
/**

View File

@@ -27,7 +27,7 @@ class DeviceCollection extends AbstractCollection implements \IteratorAggregate
*
* @param array $devices Devices
*/
public function __construct(array $devices = array())
public function __construct(array $devices = [])
{
$this->coll = new \ArrayIterator();
@@ -59,10 +59,10 @@ class DeviceCollection extends AbstractCollection implements \IteratorAggregate
*/
public function getTokens()
{
$tokens = array();
$tokens = [];
foreach ($this as $token => $device) {
$tokens[] = $token;
foreach ($this as $device) {
$tokens[] = $device->getToken();
}
return array_unique(array_filter($tokens));

View File

@@ -23,7 +23,7 @@ use Sly\NotificationPusher\Model\Message;
use Sly\NotificationPusher\Model\Push;
use Sly\NotificationPusher\Exception\AdapterException;
use Doctrine\Common\Util\Inflector;
use Doctrine\Common\Inflector\Inflector;
/**
* PushCommand.
@@ -89,7 +89,7 @@ class PushCommand extends Command
{
$adapter = $this->getReadyAdapter($input, $output);
$pushManager = new PushManager($input->getOption('env'));
$message = new Message('This is an example.');
$message = new Message($input->getArgument('message'));
$push = new Push($adapter, new Device($input->getArgument('token')), $message);
$pushManager->add($push);
@@ -132,7 +132,7 @@ class PushCommand extends Command
try {
$adapter = new $adapterClass();
} catch (\Exception $e) {
$adapterData = array();
$adapterData = [];
preg_match_all('/"(.*)"/i', $e->getMessage(), $matches);
foreach ($matches[1] as $match) {

View File

@@ -11,8 +11,6 @@
namespace Sly\NotificationPusher\Exception;
use Sly\NotificationPusher\Exception\ExceptionInterface;
/**
* AdapterException.
*

View File

@@ -11,8 +11,6 @@
namespace Sly\NotificationPusher\Exception;
use Sly\NotificationPusher\Exception\ExceptionInterface;
/**
* InvalidException.
*

View File

@@ -11,8 +11,6 @@
namespace Sly\NotificationPusher\Exception;
use Sly\NotificationPusher\Exception\ExceptionInterface;
/**
* PushException.
*

View File

@@ -11,8 +11,6 @@
namespace Sly\NotificationPusher\Exception;
use Sly\NotificationPusher\Exception\ExceptionInterface;
/**
* RuntimeException.
*

View File

@@ -21,7 +21,7 @@ abstract class BaseOptionedModel
/**
* @var array
*/
protected $options = array();
protected $options = [];
/**
* Get options.

View File

@@ -21,7 +21,7 @@ abstract class BaseParameteredModel
/**
* @var array
*/
protected $parameters = array();
protected $parameters = [];
/**
* Get parameters.

View File

@@ -29,7 +29,7 @@ class Device extends BaseParameteredModel implements DeviceInterface
* @param string $token Token
* @param array $parameters Parameters
*/
public function __construct($token, array $parameters = array())
public function __construct($token, array $parameters = [])
{
$this->token = $token;
$this->parameters = $parameters;

View File

@@ -29,7 +29,7 @@ class Message extends BaseOptionedModel implements MessageInterface
* @param string $text Text
* @param array $options Options
*/
public function __construct($text, array $options = array())
public function __construct($text, array $options = [])
{
$this->text = $text;
$this->options = $options;

View File

@@ -13,8 +13,6 @@ namespace Sly\NotificationPusher\Model;
use Sly\NotificationPusher\Collection\DeviceCollection;
use Sly\NotificationPusher\Adapter\AdapterInterface;
use Sly\NotificationPusher\Model\DeviceInterface;
use Sly\NotificationPusher\Model\MessageInterface;
use Sly\NotificationPusher\Exception\AdapterException;
/**
@@ -53,20 +51,20 @@ class Push extends BaseOptionedModel implements PushInterface
/**
* Constructor.
*
* @param \Sly\NotificationPusher\Adapter\AdapterInterface $adapter Adapter
* @param DeviceInterface|DeviceCollection $devices Device(s)
* @param \Sly\NotificationPusher\Model\MessageInterface $message Message
* @param array $options Options
* @param \Sly\NotificationPusher\Adapter\AdapterInterface $adapter Adapter
* @param DeviceInterface|DeviceCollection $devices Device(s)
* @param \Sly\NotificationPusher\Model\MessageInterface $message Message
* @param array $options Options
*
* Options are adapters specific ones, like Apns "badge" or "sound" option for example.
* Of course, they can be more general.
*
* @throws \Sly\NotificationPusher\Exception\AdapterException
*/
public function __construct(AdapterInterface $adapter, $devices, MessageInterface $message, array $options = array())
public function __construct(AdapterInterface $adapter, $devices, MessageInterface $message, array $options = [])
{
if ($devices instanceof DeviceInterface) {
$devices = new DeviceCollection(array($devices));
$devices = new DeviceCollection([$devices]);
}
$this->adapter = $adapter;
@@ -90,7 +88,7 @@ class Push extends BaseOptionedModel implements PushInterface
if (false === $adapter->supports($device->getToken())) {
throw new AdapterException(
sprintf(
'Adapter %s does not supports %s token\'s device',
'Adapter %s does not support %s token\'s device',
(string) $adapter,
$device->getToken()
)

View File

@@ -25,7 +25,7 @@ interface PushInterface
*/
const STATUS_PENDING = 'pending';
const STATUS_PUSHED = 'sent';
/**
* Get Status.
*

View File

@@ -91,6 +91,7 @@ class PushManager extends PushCollection
)
);
}
$adapter->setEnvironment($this->getEnvironment());
return $adapter->getFeedback();
}

View File

@@ -32,7 +32,7 @@ class Apns extends Units\Test
->message
->contains('certificate')
->exception(function() {
$object = new TestedModel(array('certificate' => 'absent.pem'));
$object = new TestedModel(['certificate' => 'absent.pem']);
})
->isInstanceOf('\Sly\NotificationPusher\Exception\AdapterException')
->message
@@ -41,7 +41,7 @@ class Apns extends Units\Test
->when($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))
->and($object = new \Mock\Apns())
->and($object->setParameters(array('certificate' => 'test.pem', 'passPhrase' => 'test')))
->and($object->setParameters(['certificate' => 'test.pem', 'passPhrase' => 'test']))
->array($object->getParameters())
->isNotEmpty()
->hasSize(2)
@@ -62,6 +62,16 @@ class Apns extends Units\Test
;
}
public function testDefinedParameters()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))
->and($object = new \Mock\Apns())
->array($defaultParameters = $object->getDefinedParameters())
->isEmpty()
;
}
public function testDefaultParameters()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
@@ -95,7 +105,7 @@ class Apns extends Units\Test
->and($this->mockGenerator()->orphanize('open'))
->and($this->mockClass('\ZendService\Apple\Apns\Client\Message', '\Mock\ZendService'))
->and($serviceClient = new \Mock\ZendService\Message())
->and($object->getMockController()->getParameters = array())
->and($object->getMockController()->getParameters = [])
->exception(function() use($object) {
$object->getOpenedClient(new BaseServiceClient());
})
@@ -103,7 +113,7 @@ class Apns extends Units\Test
->message
->contains('Certificate must be a valid path to a APNS certificate')
->when($object = new TestedModel(array('certificate' => __DIR__.'/../Resources/apns-certificate.pem')))
->when($object = new TestedModel(['certificate' => __DIR__.'/../Resources/apns-certificate.pem']))
->and($object->getOpenedClient($serviceClient))
;
}
@@ -149,7 +159,9 @@ class Apns extends Units\Test
->and($this->mockClass('\Sly\NotificationPusher\Model\Push', '\Mock'))
->and($push = new \Mock\Push())
->and($push->getMockController()->getMessage = new BaseMessage('Test'))
->and($push->getMockController()->getDevices = new BaseDeviceCollection(array(new BaseDevice(self::APNS_TOKEN_EXAMPLE))))
->and($push->getMockController()->getDevices = new BaseDeviceCollection(
[new BaseDevice(self::APNS_TOKEN_EXAMPLE)]
))
->and($object->getMockController()->getServiceMessageFromOrigin = new BaseServiceMessage())
->and($object->getMockController()->getOpenedClient = $serviceClient)

View File

@@ -21,6 +21,8 @@ use ZendService\Google\Gcm\Message as BaseServiceMessage;
class Gcm extends Units\Test
{
const GCM_TOKEN_EXAMPLE = 'AAA91bG9ISdL94D55C69NplFlxicy0iFUFTyWh3AAdMfP9npH5r_JQFTo27xpX1jfqGf-aSe6xZAsfWRefjazJpqFt03Isanv-Fi97020EKLye0ApTkHsw_0tJJzgA2Js0NsG1jLWsiJf63YSF8ropAcRp4BSxVBBB';
// The format of GCM tokens apparently have changed, this string looks similar to new format:
const ALT_GCM_TOKEN_EXAMPLE = 'AAA91bG9ISd:L94D55C69NplFlxicy0iFUFTyWh3AAdMfP9npH5r_JQFTo27xpX1jfqGf-aSe6xZAsfWRefjazJpqFt03Isanv-Fi97020EKLye0ApTkHsw_0tJJzgA2Js0NsG1jLWsiJf63YSF8ropA';
public function testConstruct()
{
@@ -35,7 +37,7 @@ class Gcm extends Units\Test
->when($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Gcm', '\Mock'))
->and($object = new \Mock\Gcm())
->and($object->setParameters(array('apiKey' => 'test')))
->and($object->setParameters(['apiKey' => 'test']))
->array($object->getParameters())
->isNotEmpty()
->hasSize(1)
@@ -49,13 +51,37 @@ class Gcm extends Units\Test
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Gcm', '\Mock'))
->and($object = new \Mock\Gcm())
->boolean($object->supports('*()*'))
->boolean($object->supports('')) // Test empty string
->isFalse()
->boolean($object->supports(2)) // Test a number
->isFalse()
->boolean($object->supports([])) // Test an array
->isFalse()
->boolean($object->supports(json_decode('{}'))) // Tests an object
->isFalse()
->boolean($object->supports(self::GCM_TOKEN_EXAMPLE))
->isTrue()
->boolean($object->supports(self::ALT_GCM_TOKEN_EXAMPLE))
->isTrue()
;
}
public function testDefinedParameters()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Gcm', '\Mock'))
->and($object = new \Mock\Gcm())
->array($definedParameters = $object->getDefinedParameters())
->isNotEmpty()
->containsValues([
'collapse_key',
'delay_while_idle',
'time_to_live',
'restricted_package_name',
'dry_run'
]);
}
public function testDefaultParameters()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
@@ -86,7 +112,7 @@ class Gcm extends Units\Test
->and($this->mockGenerator()->orphanize('open'))
->and($this->mockClass('\ZendService\Google\Gcm\Client', '\Mock\ZendService'))
->and($serviceClient = new \Mock\ZendService\Client())
->and($object->getMockController()->getParameters = array())
->and($object->getMockController()->getParameters = [])
->exception(function() use($object) {
$object->getOpenedClient(new BaseServiceClient());
})
@@ -94,7 +120,7 @@ class Gcm extends Units\Test
->message
->contains('The api key must be a string and not empty')
->when($object = new TestedModel(array('apiKey' => 'test')))
->when($object = new TestedModel(['apiKey' => 'test']))
->and($object->getOpenedClient($serviceClient))
;
}
@@ -110,7 +136,7 @@ class Gcm extends Units\Test
->and($message = new \Mock\Message())
->and($message->getMockController()->getText = 'Test')
->object($object->getServiceMessageFromOrigin(array(self::GCM_TOKEN_EXAMPLE), $message))
->object($object->getServiceMessageFromOrigin([self::GCM_TOKEN_EXAMPLE], $message))
->isInstanceOf('\ZendService\Google\Gcm\Message')
;
}
@@ -135,7 +161,7 @@ class Gcm extends Units\Test
->and($this->mockClass('\Sly\NotificationPusher\Model\Push', '\Mock'))
->and($push = new \Mock\Push())
->and($push->getMockController()->getMessage = new BaseMessage('Test'))
->and($push->getMockController()->getDevices = new BaseDeviceCollection(array(new BaseDevice(self::GCM_TOKEN_EXAMPLE))))
->and($push->getMockController()->getDevices = new BaseDeviceCollection([new BaseDevice(self::GCM_TOKEN_EXAMPLE)]))
->and($object->getMockController()->getServiceMessageFromOrigin = new BaseServiceMessage())
->and($object->getMockController()->getOpenedClient = $serviceClient)

View File

@@ -15,7 +15,7 @@ class BaseOptionedModel extends Units\Test
{
public function testMethods()
{
$this->if($object = new Message('Test', array('param' => 'test')))
$this->if($object = new Message('Test', ['param' => 'test']))
->boolean($object->hasOption('param'))
->isTrue()
->string($object->getOption('param'))
@@ -28,7 +28,7 @@ class BaseOptionedModel extends Units\Test
->string($object->getOption('renotExist', '12345'))
->isEqualTo('12345')
->when($object->setOptions(array('chuck' => 'norris')))
->when($object->setOptions(['chuck' => 'norris']))
->boolean($object->hasOption('chuck'))
->isTrue()
->string($object->getOption('chuck'))

View File

@@ -15,7 +15,7 @@ class BaseParameteredModel extends Units\Test
{
public function testMethods()
{
$this->if($object = new Device('Test', array('param' => 'test')))
$this->if($object = new Device('Test', ['param' => 'test']))
->boolean($object->hasParameter('param'))
->isTrue()
->string($object->getParameter('param'))
@@ -28,7 +28,7 @@ class BaseParameteredModel extends Units\Test
->string($object->getParameter('renotExist', '12345'))
->isEqualTo('12345')
->when($object->setParameters(array('chuck' => 'norris')))
->when($object->setParameters(['chuck' => 'norris']))
->boolean($object->hasParameter('chuck'))
->isTrue()
->string($object->getParameter('chuck'))

View File

@@ -20,7 +20,7 @@ class Device extends Units\Test
->array($object->getParameters())->isEmpty()
;
$this->if($object = new TestedModel('t0k3n', array('param' => 'test')))
$this->if($object = new TestedModel('t0k3n', ['param' => 'test']))
->string($object->getToken())->isEqualTo('t0k3n')
->when($object->setToken('t0k3ns3tt3d'))
->string($object->getToken())->isEqualTo('t0k3ns3tt3d')

View File

@@ -20,7 +20,7 @@ class Message extends Units\Test
->array($object->getOptions())->isEmpty()
;
$this->if($object = new TestedModel('Test', array('param' => 'test')))
$this->if($object = new TestedModel('Test', ['param' => 'test']))
->string($object->getText())->isEqualTo('Test')
->when($object->setText('Test 2'))
->string($object->getText())->isEqualTo('Test 2')

View File

@@ -43,10 +43,10 @@ class Push extends Units\Test
{
$this->if($this->mockClass('\Sly\NotificationPusher\Adapter\AdapterInterface', '\Mock'))
->and($adapter = new \Mock\AdapterInterface())
->and($devices = new BaseDeviceCollection(array(new BaseDevice('Token1'), new BaseDevice('Token2'), new BaseDevice('Token3'))))
->and($devices = new BaseDeviceCollection([new BaseDevice('Token1'), new BaseDevice('Token2'), new BaseDevice('Token3')]))
->and($message = new BaseMessage('Test'))
->and($object = new TestedModel($adapter, $devices, $message, array('param' => 'test')))
->and($object = new TestedModel($adapter, $devices, $message, ['param' => 'test']))
->object($object->getDevices())
->isInstanceOf('\Sly\NotificationPusher\Collection\DeviceCollection')
@@ -64,7 +64,7 @@ class Push extends Units\Test
{
$this->if($this->mockClass('\Sly\NotificationPusher\Adapter\AdapterInterface', '\Mock'))
->and($adapter = new \Mock\AdapterInterface())
->and($devices = new BaseDeviceCollection(array(new BaseDevice('Token1'), new BaseDevice('Token2'), new BaseDevice('Token3'))))
->and($devices = new BaseDeviceCollection([new BaseDevice('Token1'), new BaseDevice('Token2'), new BaseDevice('Token3')]))
->and($message = new BaseMessage('Test'))
->and($object = new TestedModel($adapter, $devices, $message))
@@ -136,7 +136,7 @@ class Push extends Units\Test
->isInstanceOf('\Sly\NotificationPusher\Adapter\Apns')
->when($object->setAdapter($gcmAdapter))
->and($object->setDevices(new BaseDeviceCollection(array(new BaseDevice(self::GCM_TOKEN_EXAMPLE)))))
->and($object->setDevices(new BaseDeviceCollection([new BaseDevice(self::GCM_TOKEN_EXAMPLE)])))
->object($object->getAdapter())
->isInstanceOf('\Sly\NotificationPusher\Adapter\Gcm')
;
@@ -146,7 +146,7 @@ class Push extends Units\Test
{
$this->if($this->mockClass('\Sly\NotificationPusher\Adapter\AdapterInterface', '\Mock'))
->and($adapter = new \Mock\AdapterInterface())
->and($devices = new BaseDeviceCollection(array(new BaseDevice('Token1'), new BaseDevice('Token2'), new BaseDevice('Token3'))))
->and($devices = new BaseDeviceCollection([new BaseDevice('Token1'), new BaseDevice('Token2'), new BaseDevice('Token3')]))
->and($message = new BaseMessage('Test'))
->and($object = new TestedModel($adapter, $devices, $message))

View File

@@ -37,7 +37,7 @@ class PushManager extends Units\Test
->and($this->mockClass('\Sly\NotificationPusher\Model\Push', '\Mock'))
->and($push = new \Mock\Push())
->and($push->getMockController()->getMessage = new BaseMessage('Test'))
->and($push->getMockController()->getDevices = new BaseDeviceCollection(array(new BaseDevice(self::APNS_TOKEN_EXAMPLE))))
->and($push->getMockController()->getDevices = new BaseDeviceCollection([new BaseDevice(self::APNS_TOKEN_EXAMPLE)]))
->and($object = new TestedModel())
@@ -59,7 +59,7 @@ class PushManager extends Units\Test
->and($this->mockClass('\Sly\NotificationPusher\Model\Push', '\Mock'))
->and($push = new \Mock\Push())
->and($push->getMockController()->getMessage = new BaseMessage('Test'))
->and($push->getMockController()->getDevices = new BaseDeviceCollection(array(new BaseDevice(self::APNS_TOKEN_EXAMPLE))))
->and($push->getMockController()->getDevices = new BaseDeviceCollection([new BaseDevice(self::APNS_TOKEN_EXAMPLE)]))
->and($push->getMockController()->getAdapter = $apnsAdapter)
->and($object = new TestedModel())