diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a30c55f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +vendor/ +composer.lock diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 0000000..17a95c4 --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,36 @@ +checks: + php: + code_rating: true + duplication: true + +filter: + excluded_paths: + - tests/* + +coding_style: + php: + braces: + classes_functions: + class: new-line + function: new-line + closure: end-of-line + if: + opening: end-of-line + for: + opening: end-of-line + while: + opening: end-of-line + do_while: + opening: end-of-line + switch: + opening: end-of-line + try: + opening: end-of-line + upper_lower_casing: + keywords: + general: lower + constants: + true_false_null: lower + +tools: + php_analyzer: true diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..3176c5c --- /dev/null +++ b/.travis.yml @@ -0,0 +1,44 @@ +language: php + +php: + - 5.5 + - 5.6 + - 7.0 + +sudo: false + +env: + global: + - DEFAULT=1 + - secure: j+1g/twymlVnvpQlsdS+82IY3xR8GIBB7m8bEmpYP6J1ketRToJWANDre6Xb/33JHEzekcr5Kt0F2UDkNzR5rNbviHqYH4EyHA7VZTikqSSelY+lZF7qo1xTyGRnCJZV6c2bri/rPVSjw1FYngNFh5FGCh7PmpzzeQZkhyCG3Cs= + +matrix: + allow_failures: + - php: hhvm + + fast_finish: true + + include: + - php: 5.5 + env: PHPCS=1 DEFAULT=0 + - php: 5.5 + env: COVERALLS=1 DEFAULT=0 + +install: + - composer self-update + - composer config -g github-oauth.github.com $GITHUB_COMPOSER_AUTH + - composer install --prefer-dist --no-interaction + +before_script: + - sh -c "if [ '$PHPCS' = '1' ]; then composer require cakephp/cakephp-codesniffer:dev-master; fi" + - sh -c "if [ '$COVERALLS' = '1' ]; then composer require --dev satooshi/php-coveralls:dev-master; fi" + - sh -c "if [ '$COVERALLS' = '1' ]; then mkdir -p build/logs; fi" + +script: + - sh -c "if [ '$COVERALLS' = '1' ]; then phpunit --stderr --coverage-clover build/logs/clover.xml; fi" + - sh -c "if [ '$COVERALLS' = '1' ]; then php vendor/bin/coveralls -c .coveralls.yml -v; fi" + - sh -c "if [ '$DEFAULT' = '1' ]; then phpunit --stderr; fi" + - sh -c "if [ '$PHPCS' = '1' ]; then ./vendor/bin/phpcs -n -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP --ignore=vendor --ignore=tests/bootstrap.php . ; fi" + +notifications: + email: false diff --git a/README.md b/README.md new file mode 100644 index 0000000..f43dacf --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +[![Build Status](https://img.shields.io/travis/ker0x/CakeGCM/cake3.svg?style=flat-square)](https://travis-ci.org/ker0x/CakeGCM) +[![Code Quality](https://img.shields.io/scrutinizer/g/filp/whoops.svg?style=flat-square)](https://scrutinizer-ci.com/g/ker0x/CakeGCM/?branch=cake3) +[![Total Downloads](https://img.shields.io/packagist/dt/ker0x/cake_gcm.svg?style=flat-square)](https://packagist.org/packages/ker0x/cake_gcm) +[![Latest Stable Version](https://img.shields.io/packagist/v/ker0x/cake_gcm.svg?style=flat-square)](https://packagist.org/packages/ker0x/cake_gcm) +[![Documentation Status](https://readthedocs.org/projects/cakegcm/badge/?version=latest&style=flat-square)](http://cakegcm.readthedocs.org/en/latest/?badge=latest) +[![License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://packagist.org/packages/ker0x/cake_gcm) + +# CakeGCM + +CakeGCM is a plugin for CakePHP to send downstream message to an Android or iOS device through Google Cloud Messaging + +## Requirements + +* CakePHP >= 3.* +* PHP >= 5.5 + +## Documentation + +The documentation is available [here](http://cakegcm.readthedocs.org/en/latest/) + +## License + +The MIT License (MIT) + +Copyright (c) 2015 Romain Monteil + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..9aa6581 --- /dev/null +++ b/composer.json @@ -0,0 +1,43 @@ +{ + "name": "ker0x/cake-gcm", + "type": "cakephp-plugin", + "description": "CakeGCM is a plugin for CakePHP to send notification to an Android device through Google Cloud Messaging", + "homepage": "https://github.com/ker0x/CakeGCM", + "keywords": [ + "cakephp", + "google cloud messaging", + "gcm", + "cake3" + ], + "license": "MIT", + "version": "2.0.0", + "authors": [ + { + "name": "Romain Monteil", + "email": "monteil.romain@gmail.com" + } + ], + "support": { + "issues": "https://github.com/ker0x/CakeGCM/issues", + "source": "https://github.com/ker0x/CakeGCM" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "cakephp/cakephp": "~3.0", + "phpunit/phpunit": "*", + "cakephp/cakephp-codesniffer": "dev-master", + "satooshi/php-coveralls": "dev-master" + }, + "autoload": { + "psr-4": { + "ker0x\\CakeGcm\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "ker0x\\CakeGcm\\Test\\": "tests" + } + } +} diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..e2bb58d --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,223 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = _build + +# User-friendly check for sphinx-build +ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) + $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don\'t have Sphinx installed, grab it from http://sphinx-doc.org/) +endif + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help +help: + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " applehelp to make an Apple Help Book" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " epub3 to make an epub3" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " xml to make Docutils-native XML files" + @echo " pseudoxml to make pseudoxml-XML files for display purposes" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + @echo " coverage to run coverage check of the documentation (if enabled)" + +.PHONY: clean +clean: + rm -rf $(BUILDDIR)/* + +.PHONY: html +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +.PHONY: dirhtml +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +.PHONY: singlehtml +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +.PHONY: pickle +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +.PHONY: json +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +.PHONY: htmlhelp +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +.PHONY: qthelp +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/CakeGCM.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/CakeGCM.qhc" + +.PHONY: applehelp +applehelp: + $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp + @echo + @echo "Build finished. The help book is in $(BUILDDIR)/applehelp." + @echo "N.B. You won't be able to view it unless you put it in" \ + "~/Library/Documentation/Help or install it in your application" \ + "bundle." + +.PHONY: devhelp +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/CakeGCM" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/CakeGCM" + @echo "# devhelp" + +.PHONY: epub +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +.PHONY: epub3 +epub3: + $(SPHINXBUILD) -b epub3 $(ALLSPHINXOPTS) $(BUILDDIR)/epub3 + @echo + @echo "Build finished. The epub3 file is in $(BUILDDIR)/epub3." + +.PHONY: latex +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +.PHONY: latexpdf +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +.PHONY: latexpdfja +latexpdfja: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through platex and dvipdfmx..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +.PHONY: text +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +.PHONY: man +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +.PHONY: texinfo +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +.PHONY: info +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +.PHONY: gettext +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +.PHONY: changes +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +.PHONY: linkcheck +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +.PHONY: doctest +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." + +.PHONY: coverage +coverage: + $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage + @echo "Testing of coverage in the sources finished, look at the " \ + "results in $(BUILDDIR)/coverage/python.txt." + +.PHONY: xml +xml: + $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml + @echo + @echo "Build finished. The XML files are in $(BUILDDIR)/xml." + +.PHONY: pseudoxml +pseudoxml: + $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml + @echo + @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..3923a60 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,286 @@ +# -*- coding: utf-8 -*- +# +# CakeGCM documentation build configuration file, created by +# sphinx-quickstart on Mon Apr 11 11:32:39 2016. +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys +import os + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +#sys.path.insert(0, os.path.abspath('.')) + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +#needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# source_suffix = ['.rst', '.md'] +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'CakeGCM' +copyright = u'2016, Romain Monteil' +author = u'Romain Monteil' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = u'2.0' +# The full version, including alpha/beta/rc tags. +release = u'2.0' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This patterns also effect to html_static_path and html_extra_path +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +#keep_warnings = False + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = False + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = 'default' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. +# " v documentation" by default. +#html_title = u'CakeGCM v2.0' + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (relative to this directory) to use as a favicon of +# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +#html_extra_path = [] + +# If not None, a 'Last updated on:' timestamp is inserted at every page +# bottom, using the given strftime format. +# The empty string is equivalent to '%b %d, %Y'. +#html_last_updated_fmt = None + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Language to be used for generating the HTML full-text search index. +# Sphinx supports the following languages: +# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' +# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr', 'zh' +#html_search_language = 'en' + +# A dictionary with options for the search language support, empty by default. +# 'ja' uses this config value. +# 'zh' user can custom change `jieba` dictionary path. +#html_search_options = {'type': 'default'} + +# The name of a javascript file (relative to the configuration directory) that +# implements a search results scorer. If empty, the default will be used. +#html_search_scorer = 'scorer.js' + +# Output file base name for HTML help builder. +htmlhelp_basename = 'CakeGCMdoc' + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { +# The paper size ('letterpaper' or 'a4paper'). +#'papersize': 'letterpaper', + +# The font size ('10pt', '11pt' or '12pt'). +#'pointsize': '10pt', + +# Additional stuff for the LaTeX preamble. +#'preamble': '', + +# Latex figure (float) alignment +#'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + (master_doc, 'CakeGCM.tex', u'CakeGCM Documentation', + u'Romain Monteil', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + (master_doc, 'cakegcm', u'CakeGCM Documentation', + [author], 1) +] + +# If true, show URL addresses after external links. +#man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + (master_doc, 'CakeGCM', u'CakeGCM Documentation', + author, 'CakeGCM', 'One line description of project.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +#texinfo_appendices = [] + +# If false, no module index is generated. +#texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +#texinfo_no_detailmenu = False diff --git a/docs/examples.rst b/docs/examples.rst new file mode 100644 index 0000000..c19d8ee --- /dev/null +++ b/docs/examples.rst @@ -0,0 +1,128 @@ +Examples +======== + +Send notifications +------------------ + +Send an empty notification to a device: + +.. code:: php + + $this->Gcm->send('1'); + +Send a notification to a device: + +.. code:: php + + $this->Gcm->send('1', [ + 'notification' => [ + 'title' => 'Hello World', + 'body' => 'My awesome Hellow World!' + ] + ]); + +or with the shortcut + +.. code:: php + + $this->Gcm->sendNotification('1', [ + 'title' => 'Hello World', + 'body' => 'My awesome Hellow World!' + ]); + +Send a notification to multiples devices: + +.. code:: php + + $this->Gcm->send( + ['1', '2', '3', '4'], + [ + 'notification' => [ + 'title' => 'Hello World', + 'body' => 'My awesome Hellow World!' + ] + ] + ); + +or + +.. code:: php + + $this->Gcm->sendNotification( + ['1', '2', '3', '4'], + [ + 'title' => 'Hello World', + 'body' => 'My awesome Hellow World!' + ] + ); + +Send datas +---------- + +Send datas to a device + +.. code:: php + + $this->Gcm->send('1', [ + 'data' => [ + 'data-1' => 'Lorem ipsum', + 'data-2' => 1234, + 'data-3' => true + ] + ]); + +or with the shortcut + +.. code:: php + + $this->Gcm->sendData('1', [ + 'data-1' => 'Lorem ipsum', + 'data-2' => 1234, + 'data-3' => true + ]); + +Send notifications and datas +---------------------------- + +Send a notification and some datas to multiple devices at the same time: + +.. code:: php + + $this->Gcm->send( + ['1', '2', '3', '4'], + [ + 'notification' => [ + 'title' => 'Hello World', + 'body' => 'My awesome Hellow World!' + ], + 'data' => [ + 'data-1' => 'Lorem ipsum', + 'data-2' => 1234, + 'data-3' => true + ] + ] + ); + +Extra parameters +---------------- + +Send a notification with extra parameters: + +.. code:: php + + $this->Gcm->send( + ['1', '2', '3', '4'], + [ + 'notification' => [ + 'title' => 'Hello World', + 'body' => 'My awesome Hello World!' + ] + ], + [ + 'delay_while_idle' => true, + 'dry_run' => false, + 'time_to_live' => 86400, + 'collapse_key' => 'Gcm', + 'restricted_package_name' => 'my_awesome_package' + ] + ); \ No newline at end of file diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..35b6970 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,17 @@ +.. CakeGCM documentation master file, created by + sphinx-quickstart on Mon Apr 11 11:32:39 2016. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to CakeGCM's documentation! +=================================== + +Contents: + +.. toctree:: + :maxdepth: 2 + + Introduction + Installation + Examples + diff --git a/docs/installation.rst b/docs/installation.rst new file mode 100644 index 0000000..1ec8dbe --- /dev/null +++ b/docs/installation.rst @@ -0,0 +1,66 @@ +Installation +============ + +Using `Composer `__ +-------------------------------------------- + +To install this plugin, run ``composer require ker0x/cake_gcm`` or add this snippet in your project's ``composer.json``. + +.. code:: json + + { + "require": { + "ker0x/cake_gcm": "~2.0" + } + } + +Enable plugin +------------- + +You need to enable the plugin in your ``config/bootstrap.php`` file: + +.. code:: php + + Plugin::load('ker0x/CakeGcm'); + +If you are already using ``Plugin::loadAll();``, then this is not necessary. + +Use the component +----------------- + +In ``src/Controller/AppController.php``, add : + +.. code:: php + + $this->loadComponent('ker0x/CakeGcm.Gcm', [ + 'api' => [ + 'key' => '*****' + ] + ]); + +in your Controller's initialize() method. Replace ``****`` by your API Key. + +To get an API key, go to ``. + +Then, in an action of one of your Controller, add the following code: + +.. code:: php + + if ($this->Gcm->send($ids, $payload, $parameters)) { + // do some stuff + } else { + // do other stuff + } + +where: + + - ``$ids`` is a string or an array of device ids. (required) + - ``$payload`` is an array containing the notification and/or some datas that will be passed to a device. (optional) + - ``$paramaters`` is an array of parameters for the notification. (optional) + +You could have the response of the request by using the function ``response()``: + +.. code:: php + + $response = $this->Gcm->response(); + diff --git a/docs/introduction.rst b/docs/introduction.rst new file mode 100644 index 0000000..931cbda --- /dev/null +++ b/docs/introduction.rst @@ -0,0 +1,14 @@ +Introduction +============ + +CakeGCM +------- + +CakeGCM is a plugin for CakePHP to send downstream message to an Android or iOS device through Google Cloud Messaging. + +Requirements +------------ + +* CakePHP >= 3.* +* PHP >= 5.5 + diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..5cda54c --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,272 @@ +@ECHO OFF + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set BUILDDIR=_build +set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . +set I18NSPHINXOPTS=%SPHINXOPTS% . +if NOT "%PAPER%" == "" ( + set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% + set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% +) + +if "%1" == "" goto help + +if "%1" == "help" ( + :help + echo.Please use `make ^` where ^ is one of + echo. html to make standalone HTML files + echo. dirhtml to make HTML files named index.html in directories + echo. singlehtml to make a single large HTML file + echo. pickle to make pickle files + echo. json to make JSON files + echo. htmlhelp to make HTML files and a HTML help project + echo. qthelp to make HTML files and a qthelp project + echo. devhelp to make HTML files and a Devhelp project + echo. epub to make an epub + echo. epub3 to make an epub3 + echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter + echo. text to make text files + echo. man to make manual pages + echo. texinfo to make Texinfo files + echo. gettext to make PO message catalogs + echo. changes to make an overview over all changed/added/deprecated items + echo. xml to make Docutils-native XML files + echo. pseudoxml to make pseudoxml-XML files for display purposes + echo. linkcheck to check all external links for integrity + echo. doctest to run all doctests embedded in the documentation if enabled + echo. coverage to run coverage check of the documentation if enabled + goto end +) + +if "%1" == "clean" ( + for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i + del /q /s %BUILDDIR%\* + goto end +) + + +REM Check if sphinx-build is available and fallback to Python version if any +%SPHINXBUILD% 1>NUL 2>NUL +if errorlevel 9009 goto sphinx_python +goto sphinx_ok + +:sphinx_python + +set SPHINXBUILD=python -m sphinx.__init__ +%SPHINXBUILD% 2> nul +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +:sphinx_ok + + +if "%1" == "html" ( + %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/html. + goto end +) + +if "%1" == "dirhtml" ( + %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. + goto end +) + +if "%1" == "singlehtml" ( + %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. + goto end +) + +if "%1" == "pickle" ( + %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the pickle files. + goto end +) + +if "%1" == "json" ( + %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the JSON files. + goto end +) + +if "%1" == "htmlhelp" ( + %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run HTML Help Workshop with the ^ +.hhp project file in %BUILDDIR%/htmlhelp. + goto end +) + +if "%1" == "qthelp" ( + %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run "qcollectiongenerator" with the ^ +.qhcp project file in %BUILDDIR%/qthelp, like this: + echo.^> qcollectiongenerator %BUILDDIR%\qthelp\CakeGCM.qhcp + echo.To view the help file: + echo.^> assistant -collectionFile %BUILDDIR%\qthelp\CakeGCM.ghc + goto end +) + +if "%1" == "devhelp" ( + %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. + goto end +) + +if "%1" == "epub" ( + %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The epub file is in %BUILDDIR%/epub. + goto end +) + +if "%1" == "epub3" ( + %SPHINXBUILD% -b epub3 %ALLSPHINXOPTS% %BUILDDIR%/epub3 + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The epub3 file is in %BUILDDIR%/epub3. + goto end +) + +if "%1" == "latex" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "latexpdf" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + cd %BUILDDIR%/latex + make all-pdf + cd %~dp0 + echo. + echo.Build finished; the PDF files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "latexpdfja" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + cd %BUILDDIR%/latex + make all-pdf-ja + cd %~dp0 + echo. + echo.Build finished; the PDF files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "text" ( + %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The text files are in %BUILDDIR%/text. + goto end +) + +if "%1" == "man" ( + %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The manual pages are in %BUILDDIR%/man. + goto end +) + +if "%1" == "texinfo" ( + %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. + goto end +) + +if "%1" == "gettext" ( + %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The message catalogs are in %BUILDDIR%/locale. + goto end +) + +if "%1" == "changes" ( + %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes + if errorlevel 1 exit /b 1 + echo. + echo.The overview file is in %BUILDDIR%/changes. + goto end +) + +if "%1" == "linkcheck" ( + %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck + if errorlevel 1 exit /b 1 + echo. + echo.Link check complete; look for any errors in the above output ^ +or in %BUILDDIR%/linkcheck/output.txt. + goto end +) + +if "%1" == "doctest" ( + %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest + if errorlevel 1 exit /b 1 + echo. + echo.Testing of doctests in the sources finished, look at the ^ +results in %BUILDDIR%/doctest/output.txt. + goto end +) + +if "%1" == "coverage" ( + %SPHINXBUILD% -b coverage %ALLSPHINXOPTS% %BUILDDIR%/coverage + if errorlevel 1 exit /b 1 + echo. + echo.Testing of coverage in the sources finished, look at the ^ +results in %BUILDDIR%/coverage/python.txt. + goto end +) + +if "%1" == "xml" ( + %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The XML files are in %BUILDDIR%/xml. + goto end +) + +if "%1" == "pseudoxml" ( + %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. + goto end +) + +:end diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..64116b5 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,29 @@ + + + + + + + + + + + ./tests/TestCase + + + + + + + ./vendor/ + ./tests/bootstrap.php + + + + diff --git a/src/Controller/Component/GcmComponent.php b/src/Controller/Component/GcmComponent.php new file mode 100644 index 0000000..688b96d --- /dev/null +++ b/src/Controller/Component/GcmComponent.php @@ -0,0 +1,332 @@ + [ + '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 + ], + 'http' => [] + ]; + + /** + * 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 a downstream message to one or more devices + * + * @param mixed $ids Devices'ids + * @param array $payload The notification and/or some datas + * @param array $parameters Parameters for the GCM request + * @throws Exception + * @return bool + */ + public function send($ids = null, array $payload = [], array $parameters = []) + { + $ids = $this->_checkIds($ids); + + if (!is_array($payload)) { + throw new Exception(__('Payload must be an array.')); + } + + if (isset($payload['notification'])) { + $payload['notification'] = $this->_checkNotification($payload['notification']); + } + + if (isset($payload['data'])) { + $payload['data'] = $this->_checkData($payload['data']); + } + + $parameters = $this->_checkParameters($parameters); + + $message = $this->_buildMessage($ids, $payload, $parameters); + + return $this->_executePush($message); + } + + /** + * Shortcut to send notification + * + * @param mixed $ids Devices'ids + * @param array $notification The notification + * @param array $parameters Parameters for the GCM request + * @return bool + */ + public function sendNotification($ids = null, array $notification = [], array $parameters = []) + { + return $this->send($ids, ['notification' => $notification], $parameters); + } + + /** + * Shortcut to send datas + * + * @param mixed $ids Devices'ids + * @param array $data Some datas + * @param array $parameters Parameters for the GCM request + * @return bool + */ + public function sendData($ids = null, array $data = [], array $parameters = []) + { + return $this->send($ids, ['data' => $data], $parameters); + } + + /** + * Return the response of the push + * + * @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); + } + + /** + * Send the message throught a POST request to the GCM servers + * + * @param string $message The message to send + * @throws Exception + * @return bool + */ + protected function _executePush($message) + { + $options = $this->_getHttpOptions(); + + $http = new Client(); + $this->_response = $http->post($this->config('api.url'), $message, $options); + + return ($this->_response->code === '200') ? true : false; + } + + /** + * Build the message from the ids, payload and parameters + * + * @param array|string $ids Devices'ids + * @param array $payload The notification and/or some datas + * @param array $parameters Parameters for the GCM request + * @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); + } + + /** + * Check if the ids are correct + * + * @param mixed $ids Devices'ids + * @throws Exception + * @return array + */ + protected function _checkIds($ids) + { + 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.')); + } + + return $ids; + } + + /** + * Check if the notification array is correctly build + * + * @param array $notification The 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; + } + + /** + * Check if the data array is correctly build + * + * @param array $data Some datas + * @throws Exception + * @return array $data + */ + protected 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; + } + + /** + * Check the parameters for the message + * + * @param array $parameters Parameters for the GCM request + * @throws Exception + * @return array $parameters + */ + protected function _checkParameters(array $parameters = []) + { + if (!is_array($parameters)) { + throw new Exception(__('Parameters must be an array.')); + } + + $parameters = Hash::merge($this->config('parameters'), $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; + } + + /** + * Return options for the HTTP request + * + * @throws Exception + * @return array $options + */ + protected function _getHttpOptions() + { + if ($this->config('api.key') === null) { + throw new Exception(__('No API key set. Push not triggered')); + } + + $options = Hash::merge($this->config('http'), [ + 'type' => 'json', + 'headers' => [ + 'Authorization' => 'key=' . $this->config('api.key'), + 'Content-Type' => 'application/json' + ] + ]); + + return $options; + } +} diff --git a/tests/TestCase/Controller/Component/GcmComponentTest.php b/tests/TestCase/Controller/Component/GcmComponentTest.php new file mode 100644 index 0000000..98d814b --- /dev/null +++ b/tests/TestCase/Controller/Component/GcmComponentTest.php @@ -0,0 +1,114 @@ +controller = $this->getMock( + 'Cake\Controller\Controller', + null, + [$request, $response] + ); + $registry = new ComponentRegistry($this->controller); + $this->component = new GcmComponent($registry, [ + 'api' => [ + 'key' => getenv('GCM_API_KEY') + ], + 'http' => [ + 'ssl_verify_peer' => false, + 'ssl_verify_peer_name' => false, + 'ssl_verify_host' => false + ] + ]); + } + + public function testSendNotification() + { + $tokens = getenv('TOKEN'); + + $result = $this->component->sendNotification( + $tokens, + [ + 'title' => 'Hello World', + 'body' => 'My awesome Hello World!' + ], + [ + 'dry_run' => true + ] + ); + + $this->assertTrue($result); + } + + public function testSendData() + { + $tokens = getenv('TOKEN'); + + $result = $this->component->sendData( + $tokens, + [ + 'data-1' => 'Lorem ipsum', + 'data-2' => 1234, + 'data-3' => true + ], + [ + 'dry_run' => true + ] + ); + + $this->assertTrue($result); + } + + public function testResponse() + { + $tokens = getenv('TOKEN'); + + $this->component->send( + $tokens, + [ + 'notification' => [ + 'title' => 'Hello World', + 'body' => 'My awesome Hello World!' + ], + 'data' => [ + 'data-1' => 'Lorem ipsum', + 'data-2' => 1234, + 'data-3' => true + ] + ], + [ + 'delay_while_idle' => 'true', + 'time_to_live' => '60', + 'dry_run' => 'true' + ] + ); + + $response = $this->component->response(); + + $this->assertEquals(1, $response['success']); + $this->assertEquals(0, $response['failure']); + } + + 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 new file mode 100644 index 0000000..069fcc1 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,104 @@ +register(); + +$loader->addNamespace('Cake\Test\Fixture', ROOT . '/vendor/cakephp/cakephp/tests/Fixture'); + +require_once CORE_PATH . 'config' . DS . 'bootstrap.php'; + +date_default_timezone_set('UTC'); +mb_internal_encoding('UTF-8'); + +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] + ] +]); + +Configure::write('Session', [ + '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 + ] +]); + +// Ensure default test connection is defined +if (!getenv('db_class')) { + 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' +]); + +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', + ] +]); + +Plugin::load('CakeGcm', ['path' => ROOT]);