From 410e9aa03f7511a0cda6c00b49f651a483f373a0 Mon Sep 17 00:00:00 2001 From: Romain Date: Mon, 21 Mar 2016 19:28:20 +0100 Subject: [PATCH 1/4] Spring update - Using "to" instead of "registration_ids" when only one token is provided - Improve PHPDoc block - Using Exception instead of \LogicException or \ErrorException - Remove some unnecessary check - Fix an error in README.md - Add some new one instead --- README.md | 4 +- composer.json | 6 +- src/Controller/Component/GcmComponent.php | 111 ++++++++++++---------- 3 files changed, 67 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index 8371d7e..cf55c41 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Or add it in your `composer.json`: ### Enable plugin In `config/bootstrap.php` file add : ```php -Plugin::load('CakeGcm', ['autoload' => true]); +Plugin::load('CakeGcm'); ``` or uncomment : ```php @@ -44,7 +44,7 @@ To get an API key, follow the instructions in this link: http://developer.androi Then, in an action of your Controller, add the following code: ```php -if ($this->Gcm->send($ids, $data, $parameters)) { +if ($this->Gcm->send($ids, $payload, $parameters)) { // do some stuff } else { // do other stuff diff --git a/composer.json b/composer.json index 55e89df..53415e8 100644 --- a/composer.json +++ b/composer.json @@ -7,10 +7,12 @@ "cakephp", "google", "cloud", - "messaging" + "messaging", + "plugin", + "cake3" ], "license": "MIT", - "version": "1.0.0", + "version": "2.0.0", "authors": [ { "name": "Romain Monteil", diff --git a/src/Controller/Component/GcmComponent.php b/src/Controller/Component/GcmComponent.php index b8d212a..77ca7c4 100644 --- a/src/Controller/Component/GcmComponent.php +++ b/src/Controller/Component/GcmComponent.php @@ -45,6 +45,26 @@ class GcmComponent extends Component ] ]; + /** + * List of parameters available to use in notification messages. + * + * @var array + */ + protected $_allowedNotificationParameters = [ + 'title', + 'body', + 'icon', + 'sound', + 'badge', + 'tag', + 'color', + 'click_action', + 'body_loc_key', + 'body_loc_args', + 'title_loc_key', + 'title_loc_args' + ]; + /** * Error code and message. * @@ -82,49 +102,51 @@ public function __construct(ComponentRegistry $registry, array $config = []) * @param string|array $ids * @param array $payload * @param array $parameters + * @throws Exception * @return boolean */ - public function send($ids = false, array $payload = [], array $parameters = []) + public function send($ids = null, array $payload = [], array $parameters = []) { + if (!is_string($ids) || !is_array($ids) || empty($ids)) { + throw new Exception(__('Ids must be a string or an array with at least 1 token.')); + } + if (is_string($ids)) { $ids = (array)$ids; } - if ($ids === false || !is_array($ids) || empty($ids)) { - throw new \LogicException(__('Ids must be a string or an array.')); + if (is_array($ids) && count($ids) > 1000) { + throw new Exception(__('Ids must contain at least 1 and at most 1000 registration tokens.')); } if (!is_array($payload)) { - throw new \LogicException(__('Payload must be an array.')); + throw new Exception(__('Payload must be an array.')); } if (!is_array($parameters)) { - throw new \LogicException(__('Parameters must be an array.')); + throw new Exception(__('Parameters must be an array.')); } if (isset($payload['notification'])) { $payload['notification'] = $this->_checkNotification($payload['notification']); if (!$payload['notification']) { - throw new \LogicException(__("Unable to check notification.")); + throw new Exception(__("Unable to check notification.")); } } if (isset($payload['data'])) { $payload['data'] = $this->_checkData($payload['data']); if (!$payload['data']) { - throw new \LogicException(__("Unable to check data.")); + throw new Exception(__("Unable to check data.")); } } $parameters = $this->_checkParameters($parameters); if (!$parameters) { - throw new \ErrorException(__('Unable to check parameters.')); + throw new Exception(__('Unable to check parameters.')); } $message = $this->_buildMessage($ids, $payload, $parameters); - if ($message === false) { - throw new \ErrorException(__('Unable to build the message.')); - } return $this->_executePush($message); } @@ -137,7 +159,7 @@ public function send($ids = false, array $payload = [], array $parameters = []) * @param array $parameters * @return boolean */ - public function sendNotification($ids = false, array $notification = [], array $parameters = []) + public function sendNotification($ids = null, array $notification = [], array $parameters = []) { return $this->send($ids, ['notification' => $notification], $parameters); } @@ -150,7 +172,7 @@ public function sendNotification($ids = false, array $notification = [], array $ * @param array $parameters * @return boolean */ - public function sendData($ids = false, array $data = [], array $parameters = []) + public function sendData($ids = null, array $data = [], array $parameters = []) { return $this->send($ids, ['data' => $data], $parameters); } @@ -158,7 +180,7 @@ public function sendData($ids = false, array $data = [], array $parameters = []) /** * response method * - * @return void + * @return string */ public function response() { @@ -173,16 +195,13 @@ public function response() * _executePush method * * @param string $message + * @throws Exception * @return boolean */ - protected function _executePush($message = false) + protected function _executePush($message) { - if ($message === false) { - return false; - } - if ($this->config('api.key') === null) { - throw new \ErrorException(__('No API key set. Push not triggered')); + throw new Exception(__('No API key set. Push not triggered')); } $http = new Client(); @@ -204,18 +223,14 @@ protected function _executePush($message = false) /** * _buildMessage method * - * @param array $ids + * @param array|string $ids * @param array $payload * @param array $parameters - * @return false|string + * @return string */ - protected function _buildMessage($ids = false, $payload = false, $parameters = false) + protected function _buildMessage($ids, $payload, $parameters) { - if ($ids === false) { - return false; - } - - $message = ['registration_ids' => $ids]; + $message = (count($ids) > 1) ? ['registration_ids' => $ids] : ['to' => current($ids)]; if (!empty($payload)) { $message += $payload; @@ -232,26 +247,29 @@ protected function _buildMessage($ids = false, $payload = false, $parameters = f * _checkNotification method * * @param array $notification - * @return false|array $notification + * @throws Exception + * @return array $notification */ - protected function _checkNotification($notification = false) + protected function _checkNotification(array $notification = []) { - if ($notification === false) { - return false; - } - if (!is_array($notification)) { - throw new \LogicException("Notification must be an array."); + throw new Exception('Notification must be an array.'); } if (empty($notification) || !isset($notification['title'])) { - throw new \LogicException("Notification's array must contain at least a key title."); + throw new Exception('Notification\'s array must contain at least a key title.'); } if (!isset($notification['icon'])) { $notification['icon'] = 'myicon'; } + foreach ($notification as $key => $value) { + if (!in_array($key, $this->_allowedNotificationParameters)) { + throw new Exception("The key {$key} is not allowed in notifications."); + } + } + return $notification; } @@ -259,20 +277,17 @@ protected function _checkNotification($notification = false) * _checkData method * * @param array $data - * @return false|array $data + * @throws Exception + * @return array $data */ - public function _checkData($data = false) + public function _checkData(array $data = []) { - if ($data === false) { - return false; - } - if (!is_array($data)) { - throw new \LogicException("Data must ba an array."); + throw new Exception('Data must ba an array.'); } if (empty($data)) { - throw new \LogicException("Data's array can't be empty."); + throw new Exception('Data\'s array can\'t be empty.'); } // Convert all data into string @@ -287,14 +302,10 @@ public function _checkData($data = false) * _checkParameters method * * @param array $parameters - * @return false|array $parameters + * @return array $parameters */ - protected function _checkParameters($parameters = false) + protected function _checkParameters(array $parameters = []) { - if ($parameters === false) { - return false; - } - $parameters = Hash::merge($this->config('parameters'), $parameters); $parameters = array_filter($parameters); From fb7732cda3fd341a7c979a3462b64ea392e1996b Mon Sep 17 00:00:00 2001 From: Romain Date: Mon, 21 Mar 2016 19:41:06 +0100 Subject: [PATCH 2/4] Remove unnecessary check on $parameters --- src/Controller/Component/GcmComponent.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Controller/Component/GcmComponent.php b/src/Controller/Component/GcmComponent.php index 77ca7c4..995cab5 100644 --- a/src/Controller/Component/GcmComponent.php +++ b/src/Controller/Component/GcmComponent.php @@ -142,10 +142,6 @@ public function send($ids = null, array $payload = [], array $parameters = []) } $parameters = $this->_checkParameters($parameters); - if (!$parameters) { - throw new Exception(__('Unable to check parameters.')); - } - $message = $this->_buildMessage($ids, $payload, $parameters); return $this->_executePush($message); From ae71f23d529c291fa50c7edaf9bdf9bf6853ca2e Mon Sep 17 00:00:00 2001 From: Romain Date: Mon, 21 Mar 2016 20:41:05 +0100 Subject: [PATCH 3/4] Correct some mistake --- src/Controller/Component/GcmComponent.php | 9 +++++---- .../Controller/Component/GcmComponentTest.php | 14 +++++++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Controller/Component/GcmComponent.php b/src/Controller/Component/GcmComponent.php index 995cab5..fee61ae 100644 --- a/src/Controller/Component/GcmComponent.php +++ b/src/Controller/Component/GcmComponent.php @@ -17,6 +17,7 @@ use Cake\Controller\ComponentRegistry; use Cake\Network\Http\Client; use Cake\Utility\Hash; +use \Exception; /** * Gcm Component @@ -107,14 +108,14 @@ public function __construct(ComponentRegistry $registry, array $config = []) */ public function send($ids = null, array $payload = [], array $parameters = []) { - if (!is_string($ids) || !is_array($ids) || empty($ids)) { - throw new Exception(__('Ids must be a string or an array with at least 1 token.')); - } - if (is_string($ids)) { $ids = (array)$ids; } + if (is_null($ids) || !is_array($ids) || empty($ids)) { + throw new Exception(__('Ids must be a string or an array with at least 1 token.')); + } + if (is_array($ids) && count($ids) > 1000) { throw new Exception(__('Ids must contain at least 1 and at most 1000 registration tokens.')); } diff --git a/tests/TestCase/Controller/Component/GcmComponentTest.php b/tests/TestCase/Controller/Component/GcmComponentTest.php index 3965594..c25bccc 100644 --- a/tests/TestCase/Controller/Component/GcmComponentTest.php +++ b/tests/TestCase/Controller/Component/GcmComponentTest.php @@ -6,13 +6,18 @@ use Cake\Network\Request; use Cake\Network\Response; use Cake\TestSuite\TestCase; +use \Exception; use ker0x\CakeGcm\Controller\Component\GcmComponent; class GcmComponentTest extends TestCase { public $component = null; + public $controller = null; + public $ids = []; + + public function setUp() { parent::setUp(); @@ -21,18 +26,17 @@ public function setUp() $response = new Response(); $this->controller = $this->getMock( 'Cake\Controller\Controller', - [], + null, [$request, $response] ); $registry = new ComponentRegistry($this->controller); $this->component = new GcmComponent($registry); } - public function testSend() + public function testSendError() { - $this->component->send(); - $response = $this->component->response(); - $this->assertEquals(1, $response['success']); + $isSend = $this->component->send($this->ids); + $this->assertEquals(new Exception(), $isSend); } public function tearDown() From 61d9d8be424192c60c276f48be8e46179f21d79e Mon Sep 17 00:00:00 2001 From: Scrutinizer Auto-Fixer Date: Mon, 21 Mar 2016 19:55:38 +0000 Subject: [PATCH 4/4] Scrutinizer Auto-Fixes This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com --- src/Controller/Component/GcmComponent.php | 588 +++++++++--------- .../Controller/Component/GcmComponentTest.php | 68 +- tests/bootstrap.php | 100 +-- 3 files changed, 378 insertions(+), 378 deletions(-) diff --git a/src/Controller/Component/GcmComponent.php b/src/Controller/Component/GcmComponent.php index fee61ae..f7fded4 100644 --- a/src/Controller/Component/GcmComponent.php +++ b/src/Controller/Component/GcmComponent.php @@ -26,298 +26,298 @@ class GcmComponent extends Component { - /** - * Default config - * - * @var array - */ - protected $_defaultConfig = [ - 'api' => [ - 'key' => null, - 'url' => 'https://gcm-http.googleapis.com/gcm/send' - ], - 'parameters' => [ - 'collapse_key' => null, - 'priority' => 'normal', - 'delay_while_idle' => false, - 'dry_run' => false, - 'time_to_live' => 0, - 'restricted_package_name' => null - ] - ]; - - /** - * List of parameters available to use in notification messages. - * - * @var array - */ - protected $_allowedNotificationParameters = [ - 'title', - 'body', - 'icon', - 'sound', - 'badge', - 'tag', - 'color', - 'click_action', - 'body_loc_key', - 'body_loc_args', - 'title_loc_key', - 'title_loc_args' - ]; - - /** - * Error code and message. - * - * @var array - */ - protected $_errorMessages = []; - - /** - * Response of the request - * - * @var object - */ - protected $_response = null; - - /** - * Constructor - * - * @param ComponentRegistry $registry A ComponentRegistry - * @param array $config Array of configuration settings - */ - public function __construct(ComponentRegistry $registry, array $config = []) - { - parent::__construct($registry, $config); - $this->_errorMessages = [ - '400' => __('Error 400. The request could not be parsed as JSON.'), - '401' => __('Error 401. Unable to authenticating the sender account.'), - '500' => __('Error 500. Internal Server Error.'), - '503' => __('Error 503. Service Unavailable.') - ]; - } - - /** - * send method - * - * @param string|array $ids - * @param array $payload - * @param array $parameters - * @throws Exception - * @return boolean - */ - public function send($ids = null, array $payload = [], array $parameters = []) - { - if (is_string($ids)) { - $ids = (array)$ids; - } - - if (is_null($ids) || !is_array($ids) || empty($ids)) { - throw new Exception(__('Ids must be a string or an array with at least 1 token.')); - } - - if (is_array($ids) && count($ids) > 1000) { - throw new Exception(__('Ids must contain at least 1 and at most 1000 registration tokens.')); - } - - if (!is_array($payload)) { - throw new Exception(__('Payload must be an array.')); - } - - if (!is_array($parameters)) { - throw new Exception(__('Parameters must be an array.')); - } - - if (isset($payload['notification'])) { - $payload['notification'] = $this->_checkNotification($payload['notification']); - if (!$payload['notification']) { - throw new Exception(__("Unable to check notification.")); - } - } - - if (isset($payload['data'])) { - $payload['data'] = $this->_checkData($payload['data']); - if (!$payload['data']) { - throw new Exception(__("Unable to check data.")); - } - } - - $parameters = $this->_checkParameters($parameters); - $message = $this->_buildMessage($ids, $payload, $parameters); - - return $this->_executePush($message); - } - - /** - * sendNotification method - * - * @param string|array $ids - * @param array $notification - * @param array $parameters - * @return boolean - */ - public function sendNotification($ids = null, array $notification = [], array $parameters = []) - { - return $this->send($ids, ['notification' => $notification], $parameters); - } - - /** - * sendData method - * - * @param string|array $ids - * @param array $data - * @param array $parameters - * @return boolean - */ - public function sendData($ids = null, array $data = [], array $parameters = []) - { - return $this->send($ids, ['data' => $data], $parameters); - } - - /** - * response method - * - * @return string - */ - public function response() - { - if (array_key_exists($this->_response->code, $this->_errorMessages)) { - return $this->_errorMessages[$this->_response->code]; - } - - return json_decode($this->_response->body, true); - } - - /** - * _executePush method - * - * @param string $message - * @throws Exception - * @return boolean - */ - protected function _executePush($message) - { - if ($this->config('api.key') === null) { - throw new Exception(__('No API key set. Push not triggered')); - } - - $http = new Client(); - $this->_response = $http->post($this->config('api.url'), $message, [ - 'type' => 'json', - 'headers' => [ - 'Authorization' => 'key=' . $this->config('api.key'), - 'Content-Type' => 'application/json' - ] - ]); - - if ($this->_response->code === '200') { - return true; - } - - return false; - } - - /** - * _buildMessage method - * - * @param array|string $ids - * @param array $payload - * @param array $parameters - * @return string - */ - protected function _buildMessage($ids, $payload, $parameters) - { - $message = (count($ids) > 1) ? ['registration_ids' => $ids] : ['to' => current($ids)]; - - if (!empty($payload)) { - $message += $payload; - } - - if (!empty($parameters)) { - $message += $parameters; - } - - return json_encode($message); - } - - /** - * _checkNotification method - * - * @param array $notification - * @throws Exception - * @return array $notification - */ - protected function _checkNotification(array $notification = []) - { - if (!is_array($notification)) { - throw new Exception('Notification must be an array.'); - } - - if (empty($notification) || !isset($notification['title'])) { - throw new Exception('Notification\'s array must contain at least a key title.'); - } - - if (!isset($notification['icon'])) { - $notification['icon'] = 'myicon'; - } - - foreach ($notification as $key => $value) { - if (!in_array($key, $this->_allowedNotificationParameters)) { - throw new Exception("The key {$key} is not allowed in notifications."); - } - } - - return $notification; - } - - /** - * _checkData method - * - * @param array $data - * @throws Exception - * @return array $data - */ - public function _checkData(array $data = []) - { - if (!is_array($data)) { - throw new Exception('Data must ba an array.'); - } - - if (empty($data)) { - throw new Exception('Data\'s array can\'t be empty.'); - } - - // Convert all data into string - foreach ($data as $key => $value) { - $data[$key] = (string)$value; - } - - return $data; - } - - /** - * _checkParameters method - * - * @param array $parameters - * @return array $parameters - */ - protected function _checkParameters(array $parameters = []) - { - $parameters = Hash::merge($this->config('parameters'), $parameters); - $parameters = array_filter($parameters); - - if (isset($parameters['time_to_live']) && !is_int($parameters['time_to_live'])) { - $parameters['time_to_live'] = (int)$parameters['time_to_live']; - } - - if (isset($parameters['delay_while_idle']) && !is_bool($parameters['delay_while_idle'])) { - $parameters['delay_while_idle'] = (bool)$parameters['delay_while_idle']; - } - - if (isset($parameters['dry_run']) && !is_bool($parameters['dry_run'])) { - $parameters['dry_run'] = (bool)$parameters['dry_run']; - } - - return $parameters; - } + /** + * Default config + * + * @var array + */ + protected $_defaultConfig = [ + 'api' => [ + 'key' => null, + 'url' => 'https://gcm-http.googleapis.com/gcm/send' + ], + 'parameters' => [ + 'collapse_key' => null, + 'priority' => 'normal', + 'delay_while_idle' => false, + 'dry_run' => false, + 'time_to_live' => 0, + 'restricted_package_name' => null + ] + ]; + + /** + * List of parameters available to use in notification messages. + * + * @var array + */ + protected $_allowedNotificationParameters = [ + 'title', + 'body', + 'icon', + 'sound', + 'badge', + 'tag', + 'color', + 'click_action', + 'body_loc_key', + 'body_loc_args', + 'title_loc_key', + 'title_loc_args' + ]; + + /** + * Error code and message. + * + * @var array + */ + protected $_errorMessages = []; + + /** + * Response of the request + * + * @var object + */ + protected $_response = null; + + /** + * Constructor + * + * @param ComponentRegistry $registry A ComponentRegistry + * @param array $config Array of configuration settings + */ + public function __construct(ComponentRegistry $registry, array $config = []) + { + parent::__construct($registry, $config); + $this->_errorMessages = [ + '400' => __('Error 400. The request could not be parsed as JSON.'), + '401' => __('Error 401. Unable to authenticating the sender account.'), + '500' => __('Error 500. Internal Server Error.'), + '503' => __('Error 503. Service Unavailable.') + ]; + } + + /** + * send method + * + * @param string|array $ids + * @param array $payload + * @param array $parameters + * @throws Exception + * @return boolean + */ + public function send($ids = null, array $payload = [], array $parameters = []) + { + if (is_string($ids)) { + $ids = (array)$ids; + } + + if (is_null($ids) || !is_array($ids) || empty($ids)) { + throw new Exception(__('Ids must be a string or an array with at least 1 token.')); + } + + if (is_array($ids) && count($ids) > 1000) { + throw new Exception(__('Ids must contain at least 1 and at most 1000 registration tokens.')); + } + + if (!is_array($payload)) { + throw new Exception(__('Payload must be an array.')); + } + + if (!is_array($parameters)) { + throw new Exception(__('Parameters must be an array.')); + } + + if (isset($payload['notification'])) { + $payload['notification'] = $this->_checkNotification($payload['notification']); + if (!$payload['notification']) { + throw new Exception(__("Unable to check notification.")); + } + } + + if (isset($payload['data'])) { + $payload['data'] = $this->_checkData($payload['data']); + if (!$payload['data']) { + throw new Exception(__("Unable to check data.")); + } + } + + $parameters = $this->_checkParameters($parameters); + $message = $this->_buildMessage($ids, $payload, $parameters); + + return $this->_executePush($message); + } + + /** + * sendNotification method + * + * @param string|array $ids + * @param array $notification + * @param array $parameters + * @return boolean + */ + public function sendNotification($ids = null, array $notification = [], array $parameters = []) + { + return $this->send($ids, ['notification' => $notification], $parameters); + } + + /** + * sendData method + * + * @param string|array $ids + * @param array $data + * @param array $parameters + * @return boolean + */ + public function sendData($ids = null, array $data = [], array $parameters = []) + { + return $this->send($ids, ['data' => $data], $parameters); + } + + /** + * response method + * + * @return string + */ + public function response() + { + if (array_key_exists($this->_response->code, $this->_errorMessages)) { + return $this->_errorMessages[$this->_response->code]; + } + + return json_decode($this->_response->body, true); + } + + /** + * _executePush method + * + * @param string $message + * @throws Exception + * @return boolean + */ + protected function _executePush($message) + { + if ($this->config('api.key') === null) { + throw new Exception(__('No API key set. Push not triggered')); + } + + $http = new Client(); + $this->_response = $http->post($this->config('api.url'), $message, [ + 'type' => 'json', + 'headers' => [ + 'Authorization' => 'key=' . $this->config('api.key'), + 'Content-Type' => 'application/json' + ] + ]); + + if ($this->_response->code === '200') { + return true; + } + + return false; + } + + /** + * _buildMessage method + * + * @param array|string $ids + * @param array $payload + * @param array $parameters + * @return string + */ + protected function _buildMessage($ids, $payload, $parameters) + { + $message = (count($ids) > 1) ? ['registration_ids' => $ids] : ['to' => current($ids)]; + + if (!empty($payload)) { + $message += $payload; + } + + if (!empty($parameters)) { + $message += $parameters; + } + + return json_encode($message); + } + + /** + * _checkNotification method + * + * @param array $notification + * @throws Exception + * @return array $notification + */ + protected function _checkNotification(array $notification = []) + { + if (!is_array($notification)) { + throw new Exception('Notification must be an array.'); + } + + if (empty($notification) || !isset($notification['title'])) { + throw new Exception('Notification\'s array must contain at least a key title.'); + } + + if (!isset($notification['icon'])) { + $notification['icon'] = 'myicon'; + } + + foreach ($notification as $key => $value) { + if (!in_array($key, $this->_allowedNotificationParameters)) { + throw new Exception("The key {$key} is not allowed in notifications."); + } + } + + return $notification; + } + + /** + * _checkData method + * + * @param array $data + * @throws Exception + * @return array $data + */ + public function _checkData(array $data = []) + { + if (!is_array($data)) { + throw new Exception('Data must ba an array.'); + } + + if (empty($data)) { + throw new Exception('Data\'s array can\'t be empty.'); + } + + // Convert all data into string + foreach ($data as $key => $value) { + $data[$key] = (string)$value; + } + + return $data; + } + + /** + * _checkParameters method + * + * @param array $parameters + * @return array $parameters + */ + protected function _checkParameters(array $parameters = []) + { + $parameters = Hash::merge($this->config('parameters'), $parameters); + $parameters = array_filter($parameters); + + if (isset($parameters['time_to_live']) && !is_int($parameters['time_to_live'])) { + $parameters['time_to_live'] = (int)$parameters['time_to_live']; + } + + if (isset($parameters['delay_while_idle']) && !is_bool($parameters['delay_while_idle'])) { + $parameters['delay_while_idle'] = (bool)$parameters['delay_while_idle']; + } + + if (isset($parameters['dry_run']) && !is_bool($parameters['dry_run'])) { + $parameters['dry_run'] = (bool)$parameters['dry_run']; + } + + return $parameters; + } } diff --git a/tests/TestCase/Controller/Component/GcmComponentTest.php b/tests/TestCase/Controller/Component/GcmComponentTest.php index c25bccc..f02c0a4 100644 --- a/tests/TestCase/Controller/Component/GcmComponentTest.php +++ b/tests/TestCase/Controller/Component/GcmComponentTest.php @@ -11,38 +11,38 @@ class GcmComponentTest extends TestCase { - public $component = null; - - public $controller = null; - - public $ids = []; - - - public function setUp() - { - parent::setUp(); - // Setup our component and fake test controller - $request = new Request(); - $response = new Response(); - $this->controller = $this->getMock( - 'Cake\Controller\Controller', - null, - [$request, $response] - ); - $registry = new ComponentRegistry($this->controller); - $this->component = new GcmComponent($registry); - } - - public function testSendError() - { - $isSend = $this->component->send($this->ids); - $this->assertEquals(new Exception(), $isSend); - } - - public function tearDown() - { - parent::tearDown(); - // Clean up after we're done - unset($this->component, $this->controller); - } + public $component = null; + + public $controller = null; + + public $ids = []; + + + public function setUp() + { + parent::setUp(); + // Setup our component and fake test controller + $request = new Request(); + $response = new Response(); + $this->controller = $this->getMock( + 'Cake\Controller\Controller', + null, + [$request, $response] + ); + $registry = new ComponentRegistry($this->controller); + $this->component = new GcmComponent($registry); + } + + public function testSendError() + { + $isSend = $this->component->send($this->ids); + $this->assertEquals(new Exception(), $isSend); + } + + public function tearDown() + { + parent::tearDown(); + // Clean up after we're done + unset($this->component, $this->controller); + } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 28dae6c..069fcc1 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -33,72 +33,72 @@ Configure::write('debug', true); Configure::write('App', [ - 'namespace' => 'App', - 'encoding' => 'UTF-8', - 'base' => false, - 'baseUrl' => false, - 'dir' => 'src', - 'webroot' => 'webroot', - 'wwwRoot' => APP . 'webroot', - 'fullBaseUrl' => 'http://localhost', - 'imageBaseUrl' => 'img/', - 'jsBaseUrl' => 'js/', - 'cssBaseUrl' => 'css/', - 'paths' => [ - 'plugins' => [APP . 'Plugin' . DS], - 'templates' => [APP . 'Template' . DS] - ] + 'namespace' => 'App', + 'encoding' => 'UTF-8', + 'base' => false, + 'baseUrl' => false, + 'dir' => 'src', + 'webroot' => 'webroot', + 'wwwRoot' => APP . 'webroot', + 'fullBaseUrl' => 'http://localhost', + 'imageBaseUrl' => 'img/', + 'jsBaseUrl' => 'js/', + 'cssBaseUrl' => 'css/', + 'paths' => [ + 'plugins' => [APP . 'Plugin' . DS], + 'templates' => [APP . 'Template' . DS] + ] ]); Configure::write('Session', [ - 'defaults' => 'php' + 'defaults' => 'php' ]); Cache::config([ - '_cake_core_' => [ - 'engine' => 'File', - 'prefix' => 'cake_core_', - 'serialize' => true - ], - '_cake_model_' => [ - 'engine' => 'File', - 'prefix' => 'cake_model_', - 'serialize' => true - ], - 'default' => [ - 'engine' => 'File', - 'prefix' => 'default_', - 'serialize' => true - ] + '_cake_core_' => [ + 'engine' => 'File', + 'prefix' => 'cake_core_', + 'serialize' => true + ], + '_cake_model_' => [ + 'engine' => 'File', + 'prefix' => 'cake_model_', + 'serialize' => true + ], + 'default' => [ + 'engine' => 'File', + 'prefix' => 'default_', + 'serialize' => true + ] ]); // Ensure default test connection is defined if (!getenv('db_class')) { - putenv('db_class=Cake\Database\Driver\Sqlite'); - putenv('db_dsn=sqlite::memory:'); + putenv('db_class=Cake\Database\Driver\Sqlite'); + putenv('db_dsn=sqlite::memory:'); } ConnectionManager::config('test', [ - 'className' => 'Cake\Database\Connection', - 'driver' => getenv('db_class'), - 'dsn' => getenv('db_dsn'), - 'database' => getenv('db_database'), - 'username' => getenv('db_login'), - 'password' => getenv('db_password'), - 'timezone' => 'UTC' + 'className' => 'Cake\Database\Connection', + 'driver' => getenv('db_class'), + 'dsn' => getenv('db_dsn'), + 'database' => getenv('db_database'), + 'username' => getenv('db_login'), + 'password' => getenv('db_password'), + 'timezone' => 'UTC' ]); Log::config([ - 'debug' => [ - 'engine' => 'Cake\Log\Engine\FileLog', - 'levels' => ['notice', 'info', 'debug'], - 'file' => 'debug', - ], - 'error' => [ - 'engine' => 'Cake\Log\Engine\FileLog', - 'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'], - 'file' => 'error', - ] + 'debug' => [ + 'engine' => 'Cake\Log\Engine\FileLog', + 'levels' => ['notice', 'info', 'debug'], + 'file' => 'debug', + ], + 'error' => [ + 'engine' => 'Cake\Log\Engine\FileLog', + 'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'], + 'file' => 'error', + ] ]); Plugin::load('CakeGcm', ['path' => ROOT]);