From 91e0f6770ab741aeff06913af86b09a5465946fb Mon Sep 17 00:00:00 2001 From: Alymosul Date: Sun, 9 Jul 2017 00:52:27 +0300 Subject: [PATCH 01/95] Initial Commit --- .editorconfig | 15 ++ .gitattributes | 10 ++ .gitignore | 5 + .scrutinizer.yml | 21 +++ .styleci.yml | 3 + .travis.yml | 21 +++ CHANGELOG.md | 7 + CONTRIBUTING.md | 55 ++++++ LICENSE.md | 21 +++ README.md | 107 ++++++++++- composer.json | 45 +++++ phpunit.xml.dist | 29 +++ src/Exceptions/CouldNotSendNotification.php | 7 + src/ExpoChannel.php | 77 ++++++++ src/ExpoMessage.php | 136 ++++++++++++++ src/ExpoPushNotificationsServiceProvider.php | 35 ++++ src/Http/ExpoController.php | 94 ++++++++++ src/Http/routes.php | 13 ++ tests/ChannelTest.php | 111 ++++++++++++ tests/ExpoControllerTest.php | 176 +++++++++++++++++++ tests/MessageTest.php | 93 ++++++++++ 21 files changed, 1078 insertions(+), 3 deletions(-) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .scrutinizer.yml create mode 100644 .styleci.yml create mode 100644 .travis.yml create mode 100755 CHANGELOG.md create mode 100755 CONTRIBUTING.md create mode 100644 LICENSE.md create mode 100644 composer.json create mode 100644 phpunit.xml.dist create mode 100644 src/Exceptions/CouldNotSendNotification.php create mode 100644 src/ExpoChannel.php create mode 100644 src/ExpoMessage.php create mode 100644 src/ExpoPushNotificationsServiceProvider.php create mode 100644 src/Http/ExpoController.php create mode 100644 src/Http/routes.php create mode 100644 tests/ChannelTest.php create mode 100644 tests/ExpoControllerTest.php create mode 100644 tests/MessageTest.php diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..cd8eb86e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +; This file is for unifying the coding style for different editors and IDEs. +; More information at http://editorconfig.org + +root = true + +[*] +charset = utf-8 +indent_size = 4 +indent_style = space +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..b2638710 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,10 @@ +# Path-based git attributes +# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html + +# Ignore all test and documentation with "export-ignore". +/.gitattributes export-ignore +/.gitignore export-ignore +/.travis.yml export-ignore +/phpunit.xml.dist export-ignore +/.scrutinizer.yml export-ignore +/tests export-ignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..d13e72b1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/vendor +build +composer.phar +composer.lock +.idea \ No newline at end of file diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 00000000..6fad5be9 --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,21 @@ +filter: + excluded_paths: [tests/*] + +checks: + php: + remove_extra_empty_lines: true + remove_php_closing_tag: true + remove_trailing_whitespace: true + fix_use_statements: + remove_unused: true + preserve_multiple: false + preserve_blanklines: true + order_alphabetically: true + fix_php_opening_tag: true + fix_linefeed: true + fix_line_ending: true + fix_identation_4spaces: true + fix_doc_comments: true + +tools: + external_code_coverage: true diff --git a/.styleci.yml b/.styleci.yml new file mode 100644 index 00000000..916d27ee --- /dev/null +++ b/.styleci.yml @@ -0,0 +1,3 @@ +preset: laravel + +linting: true diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..1aed6ed4 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,21 @@ +language: php + +php: + - 7.0 + - 7.1 + +env: + matrix: + - COMPOSER_FLAGS="--prefer-lowest" + - COMPOSER_FLAGS="" + +before_script: + - travis_retry composer self-update + - travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source + +script: + - phpunit --coverage-text --coverage-clover=coverage.clover + +after_script: + - wget https://scrutinizer-ci.com/ocular.phar + - php ocular.phar code-coverage:upload --format=php-clover coverage.clover diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100755 index 00000000..017196cd --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,7 @@ +# Changelog + +All notable changes to `exponent-push-notifications` will be documented in this file + +## 1.0.0 - 2017-XX-XX + +- initial release diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100755 index 00000000..4da74e3f --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,55 @@ +# Contributing + +Contributions are **welcome** and will be fully **credited**. + +Please read and understand the contribution guide before creating an issue or pull request. + +## Etiquette + +This project is open source, and as such, the maintainers give their free time to build and maintain the source code +held within. They make the code freely available in the hope that it will be of use to other developers. It would be +extremely unfair for them to suffer abuse or anger for their hard work. + +Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the +world that developers are civilized and selfless people. + +It's the duty of the maintainer to ensure that all submissions to the project are of sufficient +quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. + +## Viability + +When requesting or submitting new features, first consider whether it might be useful to others. Open +source projects are used by many developers, who may have entirely different needs to your own. Think about +whether or not your feature is likely to be used by other users of the project. + +## Procedure + +Before filing an issue: + +- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. +- Check to make sure your feature suggestion isn't already present within the project. +- Check the pull requests tab to ensure that the bug doesn't have a fix in progress. +- Check the pull requests tab to ensure that the feature isn't already in progress. + +Before submitting a pull request: + +- Check the codebase to ensure that your feature doesn't already exist. +- Check the pull requests to ensure that another person hasn't already submitted the feature or fix. + +## Requirements + +If the project maintainer has any additional requirements, you will find them listed here. + +- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer). + +- **Add tests!** - Your patch won't be accepted if it doesn't have tests. + +- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. + +- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. + +- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. + +- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. + +**Happy coding**! diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 00000000..2aa66b6c --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +# The MIT License (MIT) + +Copyright (c) Aly Suleiman + +> 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/README.md b/README.md index 746a917d..63908d99 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,106 @@ -# new-channels +# Exponent push notifications channel for Laravel 5.3 -Discuss about new channel proposals our share your finished channels in the [proposal issue](https://github.com/laravel-notification-channels/new-channels/issues/6). +[![Latest Version on Packagist](https://img.shields.io/packagist/v/laravel-notification-channels/laravel-exponent-push-notifications.svg?style=flat-square)](https://packagist.org/packages/alymosul/laravel-exponent-push-notifications) +[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) +[![Build Status](https://travis-ci.org/Alymosul/laravel-exponent-push-notifications.svg?branch=master)](https://travis-ci.org/Alymosul/laravel-exponent-push-notifications) +[![StyleCI](https://styleci.io/repos/96645200/shield?branch=master)](https://styleci.io/repos/96645200) +[![SensioLabsInsight](https://img.shields.io/sensiolabs/i/:sensio_labs_id.svg?style=flat-square)](https://insight.sensiolabs.com/projects/:sensio_labs_id) +[![Quality Score](https://img.shields.io/scrutinizer/g/alymosul/laravel-exponent-push-notifications.svg?style=flat-square)](https://scrutinizer-ci.com/g/alymosul/laravel-exponent-push-notifications) +[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/alymosul/laravel-exponent-push-notifications/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/alymosul/laravel-exponent-push-notifications/?branch=master) +[![Total Downloads](https://img.shields.io/packagist/dt/alymosul/laravel-exponent-push-notifications.svg?style=flat-square)](https://packagist.org/packages/alymosul/laravel-exponent-push-notifications) -Take a look at our [FAQ](http://laravel-notification-channels.com/) to see our small list of rules, to provide top-notch notification channels. +## Contents + +- [Installation](#installation) +- [Usage](#usage) + - [Available Message methods](#available-message-methods) +- [Changelog](#changelog) +- [Testing](#testing) +- [Security](#security) +- [Contributing](#contributing) +- [Credits](#credits) +- [License](#license) + + +## Installation +You can install the package via composer: +```bash +composer require laravel-notification-channels/exponent-push-notifications +``` +You must install the service provider: + +```php +// config/app.php +'providers' => [ + ... + NotificationChannels\ExpoPushNotifications\ExpoPushNotificationsServiceProvider::class, +], +``` + +## Usage + +``` php +use NotificationChannels\ExpoPushNotifications\ExpoChannel; +use NotificationChannels\ExpoPushNotifications\ExpoMessage; +use Illuminate\Notifications\Notification; + +class AccountApproved extends Notification +{ + public function via($notifiable) + { + return [ExpoChannel::class]; + } + + public function toExpoPush($notifiable) + { + return ExpoMessage::create() + ->badge(1) + ->enableSound() + ->body("Your {$notifiable->service} account was approved!"); + } +} +``` + +### Available Message methods + +A list of all available options +- `body('')`: Accepts a string value for the body. +- `enableSound()`: Enables the notification sound. +- `disableSound()`: Mutes the notification sound. +- `badge(1)`: Accepts an integer value for the badge. +- `ttl(60)`: Accepts an integer value for the time to live. + +### Managing Recipients + +This package registers two endpoints that handle the subscription of recipients, the endpoints are defined in src/Http/routes.php file, used by ExpoController and all loaded through the package service provider. + +### Routing a message + +By default the exponent "interest" messages will be sent to will be defined using the {notifiable}.{id} convention, for example `App.User.1`, however you can change this behaviour by including a `routeNotificationForExpoPushNotifications()` in the notifiable class method that returns the interest name. + +## Changelog + +Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. + +## Testing + +``` bash +$ composer test +``` + +## Security + +If you discover any security related issues, please email alymosul@gmail.com instead of using the issue tracker. + +## Contributing + +Please see [CONTRIBUTING](CONTRIBUTING.md) for details. + +## Credits + +- [Aly Suleiman](https://github.com/Alymosul) +- [All Contributors](../../contributors) + +## License + +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. diff --git a/composer.json b/composer.json new file mode 100644 index 00000000..63530d08 --- /dev/null +++ b/composer.json @@ -0,0 +1,45 @@ +{ + "name": "alymosul/exponent-push-notifications", + "description": "Exponent push notifications driver for laravel", + "homepage": "https://github.com/alymosul/exponent-push-notifications", + "license": "MIT", + "authors": [ + { + "name": "Aly Suleiman", + "email": "alymosul@gmail.com", + "role": "Developer" + } + ], + "require": { + "php": ">=7.0", + "alymosul/exponent-server-sdk-php": "1.0.*", + "illuminate/notifications": "5.3 || 5.4.*", + "illuminate/support": "5.3 || 5.4.*", + "illuminate/events": "5.3 || 5.4.*", + "illuminate/queue": "5.3 || 5.4.*", + "illuminate/http": "5.3 || 5.4.*", + "illuminate/routing": "5.3 || 5.4.*", + "illuminate/validation": "5.3 || 5.4.*", + "illuminate/auth": "5.3 || 5.4" + }, + "require-dev": { + "mockery/mockery": "^0.9.5", + "phpunit/phpunit": "~5.7" + }, + "autoload": { + "psr-4": { + "NotificationChannels\\ExpoPushNotifications\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "NotificationChannels\\ExpoPushNotifications\\Test\\": "tests" + } + }, + "scripts": { + "test": "vendor/bin/phpunit" + }, + "config": { + "sort-packages": true + } +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 00000000..b06b7eea --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,29 @@ + + + + + tests + + + + + src/ + + + + + + + + + + diff --git a/src/Exceptions/CouldNotSendNotification.php b/src/Exceptions/CouldNotSendNotification.php new file mode 100644 index 00000000..54830526 --- /dev/null +++ b/src/Exceptions/CouldNotSendNotification.php @@ -0,0 +1,7 @@ +events = $events; + $this->expo = $expo; + } + + /** + * Send the given notification + * + * @param mixed $notifiable + * @param \Illuminate\Notifications\Notification $notification + * + * @throws CouldNotSendNotification + * + * @return void + */ + public function send($notifiable, Notification $notification) + { + $interest = $notifiable->routeNotificationFor('ExpoPushNotifications') + ?: $this->interestName($notifiable); + + try { + $response = $this->expo->notify( + $interest, + $notification->toExpoPush($notifiable)->toArray(), + true + ); + } catch (ExpoException $e) { + $this->events->fire( + new NotificationFailed($notifiable, $notification, 'expo-push-notifications', $e->getMessage()) + ); + } + } + + /** + * Get the interest name for the notifiable. + * + * @param $notifiable + * + * @return string + */ + public function interestName($notifiable) + { + $class = str_replace('\\', '.', get_class($notifiable)); + + return $class.'.'.$notifiable->getKey(); + } +} diff --git a/src/ExpoMessage.php b/src/ExpoMessage.php new file mode 100644 index 00000000..aac73833 --- /dev/null +++ b/src/ExpoMessage.php @@ -0,0 +1,136 @@ +body = $body; + } + + /** + * Set the message body. + * + * @param string $value + * + * @return $this + */ + public function body(string $value) + { + $this->body = $value; + + return $this; + } + + /** + * Enable the message sound. + * + * @return $this + */ + public function enableSound() + { + $this->sound = 'default'; + + return $this; + } + + /** + * Disable the message sound. + * + * @return $this + */ + public function disableSound() + { + $this->sound = null; + + return $this; + } + + /** + * Set the message badge (iOS). + * + * @param int $value + * + * @return $this + */ + public function badge(int $value) + { + $this->badge = $value; + + return $this; + } + + /** + * Set the time to live of the notification + * + * @param int $ttl + * + * @return $this + */ + public function setTtl(int $ttl) + { + $this->ttl = $ttl; + + return $this; + } + + /** + * Get an array representation of the message + * + * @return array + */ + public function toArray() + { + return [ + 'body' => $this->body, + 'sound' => $this->sound, + 'badge' => $this->badge, + 'ttl' => $this->ttl, + ]; + } +} diff --git a/src/ExpoPushNotificationsServiceProvider.php b/src/ExpoPushNotificationsServiceProvider.php new file mode 100644 index 00000000..e672d574 --- /dev/null +++ b/src/ExpoPushNotificationsServiceProvider.php @@ -0,0 +1,35 @@ +app->when(ExpoChannel::class) + ->needs(Expo::class) + ->give(function () { + return new Expo(new ExpoRegistrar(new ExpoFileDriver())); + }); + + //Load routes + $this->loadRoutesFrom(__DIR__ . '/Http/routes.php'); + } + + /** + * Register the application services. + */ + public function register() + { + $this->app->bind(ExpoRepository::class, ExpoFileDriver::class); + } +} diff --git a/src/Http/ExpoController.php b/src/Http/ExpoController.php new file mode 100644 index 00000000..49dfa14a --- /dev/null +++ b/src/Http/ExpoController.php @@ -0,0 +1,94 @@ +expoChannel = $expoChannel; + } + + /** + * Handles subscription endpoint for an expo token + * + * @param Request $request + * + * @return \Illuminate\Http\JsonResponse + */ + public function subscribe(Request $request) + { + $validator = Validator::make($request->all(), [ + 'expo_token' => 'required|string' + ]); + + if ($validator->fails()) { + return JsonResponse::create([ + 'status' => 'failed', + 'error' => [ + 'message' => 'Expo Token is required' + ] + ], 422); + } + + $token = $request->get('expo_token'); + + $interest = $this->expoChannel->interestName(Auth::user()); + + try { + $this->expoChannel->expo->subscribe($interest, $token); + } catch (\Exception $e) { + return JsonResponse::create([ + 'status' => 'failed', + 'error' => [ + 'message' => $e->getMessage() + ] + ], 500); + } + + return JsonResponse::create([ + 'status' => 'succeeded', + 'expo_token' => $token + ], 200); + } + + /** + * Handles removing subscription endpoint for the authenticated interest + * + * @return \Illuminate\Http\JsonResponse + */ + public function unsubscribe() + { + $interest = $this->expoChannel->interestName(Auth::user()); + + try { + $deleted = $this->expoChannel->expo->unsubscribe($interest); + } catch (\Exception $e) { + return JsonResponse::create([ + 'status' => 'failed', + 'error' => [ + 'message' => $e->getMessage() + ] + ], 500); + } + + return JsonResponse::create(['deleted' => $deleted]); + } +} diff --git a/src/Http/routes.php b/src/Http/routes.php new file mode 100644 index 00000000..02baa483 --- /dev/null +++ b/src/Http/routes.php @@ -0,0 +1,13 @@ + 'api/exponent/devices', 'middleware' => 'auth:api, bindings'], function () { + Route::post('subscribe', [ + 'as' => 'register-interest', + 'uses' => 'NotificationChannels\ExpoPushNotifications\Http\ExpoController@subscribe' + ]); + + Route::post('unsubscribe', [ + 'as' => 'remove-interest', + 'uses' => 'NotificationChannels\ExpoPushNotifications\Http\ExpoController@unsubscribe' + ]); +}); diff --git a/tests/ChannelTest.php b/tests/ChannelTest.php new file mode 100644 index 00000000..a09d1db4 --- /dev/null +++ b/tests/ChannelTest.php @@ -0,0 +1,111 @@ +expo = Mockery::mock(Expo::class); + + $this->events = Mockery::mock(Dispatcher::class); + + $this->channel = new ExpoChannel($this->expo, $this->events); + + $this->notification = new TestNotification; + + $this->notifiable = new TestNotifiable; + } + + public function tearDown() + { + Mockery::close(); + + parent::tearDown(); + } + + /** @test */ + public function itCanSendANotification() + { + $message = $this->notification->toExpoPush($this->notifiable); + + $data = $message->toArray(); + + $this->expo->shouldReceive('notify')->with('interest_name', $data, true)->andReturn([['status' => 'ok']]); + + $this->channel->send($this->notifiable, $this->notification); + } + + /** @test */ + public function itFiresFailureEventOnFailure() + { + $message = $this->notification->toExpoPush($this->notifiable); + + $data = $message->toArray(); + + $this->expo->shouldReceive('notify')->with('interest_name', $data, true)->andThrow(ExpoException::class, ''); + + $this->events->shouldReceive('fire')->with(Mockery::type(NotificationFailed::class)); + + $this->channel->send($this->notifiable, $this->notification); + } +} + +class TestNotifiable +{ + use Notifiable; + + public function routeNotificationForExpoPushNotifications() + { + return 'interest_name'; + } + + public function getKey() + { + return 1; + } +} + +class TestNotification extends Notification +{ + public function toExpoPush($notifiable) + { + return new ExpoMessage(); + } +} \ No newline at end of file diff --git a/tests/ExpoControllerTest.php b/tests/ExpoControllerTest.php new file mode 100644 index 00000000..208edd6c --- /dev/null +++ b/tests/ExpoControllerTest.php @@ -0,0 +1,176 @@ +expoChannel = new ExpoChannel(Expo::normalSetup(), new Dispatcher()); + + $this->expoController = new ExpoController($this->expoChannel); + + // We will fake an authenticated user + Auth::shouldReceive('user')->andReturn(new User()); + } + + public function tearDown() + { + \Mockery::close(); + + parent::tearDown(); + } + + /** @test */ + public function aDeviceCanSubscribeToTheSystem() + { + // We will fake a request with the following data + $data = ['expo_token' => 'ExponentPushToken[fakeToken]']; + $request = $this->mockRequest($data); + $request->shouldReceive('get')->with('expo_token')->andReturn($data['expo_token']); + + $this->mockValidator(false); + + /** @var Request $request */ + $response = $this->expoController->subscribe($request); + $response = json_decode($response->content()); + + // The response should contain a succeeded status + $this->assertEquals('succeeded', $response->status); + // The response should return the registered token + $this->assertEquals($data['expo_token'], $response->expo_token); + } + + /** @test */ + public function subscribeReturnsErrorResponseIfTokenInvalid() + { + // We will fake a request with no data + $request = $this->mockRequest([]); + + $this->mockValidator(true); + + /** @var Request $request */ + $response = $this->expoController->subscribe($request); + + // The response should contain a failed status + $this->assertEquals('failed', json_decode($response->content())->status); + // The response status should be 422 + $this->assertEquals(422, $response->getStatusCode()); + } + + /** @test */ + public function subscribeReturnsErrorResponseIfExceptionIsThrown() + { + // We will fake a request with the following data + $data = ['expo_token' => 'ExponentPushToken[fakeToken]']; + $request = $this->mockRequest($data); + $request->shouldReceive('get')->andReturn($data['expo_token']); + + $this->mockValidator(false); + + $expo = \Mockery::mock(Expo::class); + $expo->shouldReceive('subscribe')->andThrow(\Exception::class); + + /** @var Expo $expo */ + $expoChannel = new ExpoChannel($expo, new Dispatcher()); + + /** @var Request $request */ + $response = (new ExpoController($expoChannel))->subscribe($request); + $response = json_decode($response->content()); + + $this->assertEquals('failed', $response->status); + } + + /** @test */ + public function aDeviceCanUnsubscribeFromTheSystem() + { + // We will subscribe an interest to the server. + $token = 'ExponentPushToken[fakeToken]'; + $interest = $this->expoChannel->interestName(new User()); + $this->expoChannel->expo->subscribe($interest, $token); + + $response = $this->expoController->unsubscribe(); + $response = json_decode($response->content()); + + // The response should contain a deleted property with value true + $this->assertTrue($response->deleted); + } + + /** @test */ + public function unsubscribeReturnsErrorResponseIfExceptionIsThrown() + { + $expo = \Mockery::mock(Expo::class); + $expo->shouldReceive('unsubscribe')->andThrow(\Exception::class); + + /** @var Expo $expo */ + $response = (new ExpoController(new ExpoChannel($expo, new Dispatcher())))->unsubscribe(); + $response = json_decode($response->content()); + + $this->assertEquals('failed', $response->status); + } + + /** + * Mocks a request for the ExpoController + * + * @param $data + * + * @return \Mockery\MockInterface + */ + private function mockRequest($data) + { + $request = \Mockery::mock(Request::class); + $request->shouldReceive('all')->andReturn($data); + + return $request; + } + + /** + * @param bool $fails + * + * @return \Mockery\MockInterface + */ + private function mockValidator(bool $fails) + { + $validator = \Mockery::mock(\Illuminate\Validation\Validator::class); + + $validation = \Mockery::mock(Factory::class); + $validation->shouldReceive('make')->once()->andReturn($validator); + + $validator->shouldReceive('fails')->once()->andReturn($fails); + + Validator::swap($validation); + return $validator; + } +} + +class User +{ + public function getKey() + { + return 1; + } +} \ No newline at end of file diff --git a/tests/MessageTest.php b/tests/MessageTest.php new file mode 100644 index 00000000..62b2b862 --- /dev/null +++ b/tests/MessageTest.php @@ -0,0 +1,93 @@ +message = new ExpoMessage(); + } + + /** @test */ + public function itProvidesACreateMethod() + { + $message = ExpoMessage::create('myMessage'); + + $this->assertEquals('myMessage', Arr::get($message->toArray(), 'body')); + } + + /** @test */ + public function itCanAcceptsABodyWhenConstructingAMessage() + { + $message = new ExpoMessage('myMessage'); + + $this->assertEquals('myMessage', Arr::get($message->toArray(), 'body')); + } + + /** @test */ + public function itProvidesACreateMethodThatAcceptsAMessageBody() + { + $message = new ExpoMessage('myMessage'); + + $this->assertEquals('myMessage', Arr::get($message->toArray(), 'body')); + } + + /** @test */ + public function itSetsABodyToTheMessage() + { + $this->message->body('myMessage'); + + $this->assertEquals('myMessage', Arr::get($this->message->toArray(), 'body')); + } + + /** @test */ + public function itSetsADefaultSound() + { + $this->assertEquals('default', Arr::get($this->message->toArray(), 'sound')); + } + + /** @test */ + public function itCanMuteSound() + { + $this->message->disableSound(); + + $this->assertNull(Arr::get($this->message->toArray(), 'sound')); + } + + /** @test */ + public function itCanEnableSound() + { + $this->message->disableSound(); + $this->message->enableSound(); + + $this->assertNotNull(Arr::get($this->message->toArray(), 'sound')); + } + + /** @test */ + public function itCanSetTheBadge() + { + $this->message->badge(5); + + $this->assertEquals(5, Arr::get($this->message->toArray(), 'badge')); + } + + /** @test */ + public function itCanSetTimeToLive() + { + $this->message->setTtl(60); + + $this->assertEquals(60, Arr::get($this->message->toArray(), 'ttl')); + } +} From 843efc22c2597ec5f516cbbddfea07be1bf334ca Mon Sep 17 00:00:00 2001 From: Alymosul Date: Sun, 9 Jul 2017 00:55:26 +0300 Subject: [PATCH 02/95] Update composer.json --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 63530d08..dfaeba62 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { - "name": "alymosul/exponent-push-notifications", + "name": "alymosul/laravel-exponent-push-notifications", "description": "Exponent push notifications driver for laravel", - "homepage": "https://github.com/alymosul/exponent-push-notifications", + "homepage": "https://github.com/alymosul/laravel-exponent-push-notifications", "license": "MIT", "authors": [ { From 912047f730d00d32a17bf7d94d991493cb83fdad Mon Sep 17 00:00:00 2001 From: Aly Suleiman Date: Sat, 8 Jul 2017 22:07:09 +0000 Subject: [PATCH 03/95] Apply fixes from StyleCI --- src/ExpoChannel.php | 6 +++--- src/ExpoMessage.php | 4 ++-- src/ExpoPushNotificationsServiceProvider.php | 4 ++-- src/Http/ExpoController.php | 22 ++++++++++---------- src/Http/routes.php | 4 ++-- tests/ChannelTest.php | 10 ++++----- tests/ExpoControllerTest.php | 13 ++++++------ tests/MessageTest.php | 2 +- 8 files changed, 32 insertions(+), 33 deletions(-) diff --git a/src/ExpoChannel.php b/src/ExpoChannel.php index 0a8711c8..e9c44f0e 100644 --- a/src/ExpoChannel.php +++ b/src/ExpoChannel.php @@ -2,12 +2,12 @@ namespace NotificationChannels\ExpoPushNotifications; -use ExponentPhpSDK\Exceptions\ExpoException; use ExponentPhpSDK\Expo; use Illuminate\Events\Dispatcher; +use Illuminate\Notifications\Notification; +use ExponentPhpSDK\Exceptions\ExpoException; use Illuminate\Notifications\Events\NotificationFailed; use NotificationChannels\ExpoPushNotifications\Exceptions\CouldNotSendNotification; -use Illuminate\Notifications\Notification; class ExpoChannel { @@ -34,7 +34,7 @@ public function __construct(Expo $expo, Dispatcher $events) } /** - * Send the given notification + * Send the given notification. * * @param mixed $notifiable * @param \Illuminate\Notifications\Notification $notification diff --git a/src/ExpoMessage.php b/src/ExpoMessage.php index aac73833..7a39fa12 100644 --- a/src/ExpoMessage.php +++ b/src/ExpoMessage.php @@ -106,7 +106,7 @@ public function badge(int $value) } /** - * Set the time to live of the notification + * Set the time to live of the notification. * * @param int $ttl * @@ -120,7 +120,7 @@ public function setTtl(int $ttl) } /** - * Get an array representation of the message + * Get an array representation of the message. * * @return array */ diff --git a/src/ExpoPushNotificationsServiceProvider.php b/src/ExpoPushNotificationsServiceProvider.php index e672d574..7519a448 100644 --- a/src/ExpoPushNotificationsServiceProvider.php +++ b/src/ExpoPushNotificationsServiceProvider.php @@ -5,8 +5,8 @@ use ExponentPhpSDK\Expo; use ExponentPhpSDK\ExpoRegistrar; use ExponentPhpSDK\ExpoRepository; -use ExponentPhpSDK\Repositories\ExpoFileDriver; use Illuminate\Support\ServiceProvider; +use ExponentPhpSDK\Repositories\ExpoFileDriver; class ExpoPushNotificationsServiceProvider extends ServiceProvider { @@ -22,7 +22,7 @@ public function boot() }); //Load routes - $this->loadRoutesFrom(__DIR__ . '/Http/routes.php'); + $this->loadRoutesFrom(__DIR__.'/Http/routes.php'); } /** diff --git a/src/Http/ExpoController.php b/src/Http/ExpoController.php index 49dfa14a..bc229932 100644 --- a/src/Http/ExpoController.php +++ b/src/Http/ExpoController.php @@ -2,8 +2,8 @@ namespace NotificationChannels\ExpoPushNotifications\Http; -use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Http\JsonResponse; use Illuminate\Routing\Controller; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Validator; @@ -27,7 +27,7 @@ public function __construct(ExpoChannel $expoChannel) } /** - * Handles subscription endpoint for an expo token + * Handles subscription endpoint for an expo token. * * @param Request $request * @@ -36,15 +36,15 @@ public function __construct(ExpoChannel $expoChannel) public function subscribe(Request $request) { $validator = Validator::make($request->all(), [ - 'expo_token' => 'required|string' + 'expo_token' => 'required|string', ]); if ($validator->fails()) { return JsonResponse::create([ 'status' => 'failed', 'error' => [ - 'message' => 'Expo Token is required' - ] + 'message' => 'Expo Token is required', + ], ], 422); } @@ -58,19 +58,19 @@ public function subscribe(Request $request) return JsonResponse::create([ 'status' => 'failed', 'error' => [ - 'message' => $e->getMessage() - ] + 'message' => $e->getMessage(), + ], ], 500); } return JsonResponse::create([ 'status' => 'succeeded', - 'expo_token' => $token + 'expo_token' => $token, ], 200); } /** - * Handles removing subscription endpoint for the authenticated interest + * Handles removing subscription endpoint for the authenticated interest. * * @return \Illuminate\Http\JsonResponse */ @@ -84,8 +84,8 @@ public function unsubscribe() return JsonResponse::create([ 'status' => 'failed', 'error' => [ - 'message' => $e->getMessage() - ] + 'message' => $e->getMessage(), + ], ], 500); } diff --git a/src/Http/routes.php b/src/Http/routes.php index 02baa483..4f0ed16e 100644 --- a/src/Http/routes.php +++ b/src/Http/routes.php @@ -3,11 +3,11 @@ Route::group(['prefix' => 'api/exponent/devices', 'middleware' => 'auth:api, bindings'], function () { Route::post('subscribe', [ 'as' => 'register-interest', - 'uses' => 'NotificationChannels\ExpoPushNotifications\Http\ExpoController@subscribe' + 'uses' => 'NotificationChannels\ExpoPushNotifications\Http\ExpoController@subscribe', ]); Route::post('unsubscribe', [ 'as' => 'remove-interest', - 'uses' => 'NotificationChannels\ExpoPushNotifications\Http\ExpoController@unsubscribe' + 'uses' => 'NotificationChannels\ExpoPushNotifications\Http\ExpoController@unsubscribe', ]); }); diff --git a/tests/ChannelTest.php b/tests/ChannelTest.php index a09d1db4..62ee9eac 100644 --- a/tests/ChannelTest.php +++ b/tests/ChannelTest.php @@ -2,16 +2,16 @@ namespace NotificationChannels\ExpoPushNotifications\Test; -use ExponentPhpSDK\Exceptions\ExpoException; +use Mockery; use ExponentPhpSDK\Expo; +use PHPUnit\Framework\TestCase; use Illuminate\Events\Dispatcher; -use Illuminate\Notifications\Events\NotificationFailed; use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notification; -use Mockery; +use ExponentPhpSDK\Exceptions\ExpoException; +use Illuminate\Notifications\Events\NotificationFailed; use NotificationChannels\ExpoPushNotifications\ExpoChannel; use NotificationChannels\ExpoPushNotifications\ExpoMessage; -use PHPUnit\Framework\TestCase; class ChannelTest extends TestCase { @@ -108,4 +108,4 @@ public function toExpoPush($notifiable) { return new ExpoMessage(); } -} \ No newline at end of file +} diff --git a/tests/ExpoControllerTest.php b/tests/ExpoControllerTest.php index 208edd6c..8f02b63c 100644 --- a/tests/ExpoControllerTest.php +++ b/tests/ExpoControllerTest.php @@ -3,16 +3,14 @@ namespace NotificationChannels\ExpoPushNotifications\Test; use ExponentPhpSDK\Expo; -use ExponentPhpSDK\ExpoRegistrar; -use ExponentPhpSDK\Repositories\ExpoFileDriver; -use Illuminate\Events\Dispatcher; use Illuminate\Http\Request; +use PHPUnit\Framework\TestCase; +use Illuminate\Events\Dispatcher; +use Illuminate\Validation\Factory; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Validator; -use Illuminate\Validation\Factory; use NotificationChannels\ExpoPushNotifications\ExpoChannel; use NotificationChannels\ExpoPushNotifications\Http\ExpoController; -use PHPUnit\Framework\TestCase; class ExpoControllerTest extends TestCase { @@ -134,7 +132,7 @@ public function unsubscribeReturnsErrorResponseIfExceptionIsThrown() } /** - * Mocks a request for the ExpoController + * Mocks a request for the ExpoController. * * @param $data * @@ -163,6 +161,7 @@ private function mockValidator(bool $fails) $validator->shouldReceive('fails')->once()->andReturn($fails); Validator::swap($validation); + return $validator; } } @@ -173,4 +172,4 @@ public function getKey() { return 1; } -} \ No newline at end of file +} diff --git a/tests/MessageTest.php b/tests/MessageTest.php index 62b2b862..46b0532a 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -3,8 +3,8 @@ namespace NotificationChannels\ExpoPushNotifications\Test; use Illuminate\Support\Arr; -use NotificationChannels\ExpoPushNotifications\ExpoMessage; use PHPUnit\Framework\TestCase; +use NotificationChannels\ExpoPushNotifications\ExpoMessage; class MessageTest extends TestCase { From fb016cd7dbe96e7e1d8745801ed5f789102b67e5 Mon Sep 17 00:00:00 2001 From: Alymosul Date: Sun, 9 Jul 2017 01:16:19 +0300 Subject: [PATCH 04/95] Update .travis.yml and remove unused variable from the ExpoChannel --- .travis.yml | 7 +------ src/ExpoChannel.php | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1aed6ed4..b0116bfc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,14 +4,9 @@ php: - 7.0 - 7.1 -env: - matrix: - - COMPOSER_FLAGS="--prefer-lowest" - - COMPOSER_FLAGS="" - before_script: - travis_retry composer self-update - - travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source + - travis_retry composer update --no-interaction --prefer-source script: - phpunit --coverage-text --coverage-clover=coverage.clover diff --git a/src/ExpoChannel.php b/src/ExpoChannel.php index e9c44f0e..d9e6775b 100644 --- a/src/ExpoChannel.php +++ b/src/ExpoChannel.php @@ -49,7 +49,7 @@ public function send($notifiable, Notification $notification) ?: $this->interestName($notifiable); try { - $response = $this->expo->notify( + $this->expo->notify( $interest, $notification->toExpoPush($notifiable)->toArray(), true From 83065176efa8c2d5da04308041b8025ad2f59945 Mon Sep 17 00:00:00 2001 From: Alymosul Date: Sun, 9 Jul 2017 01:26:51 +0300 Subject: [PATCH 05/95] update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 63908d99..084c66ac 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Exponent push notifications channel for Laravel 5.3 -[![Latest Version on Packagist](https://img.shields.io/packagist/v/laravel-notification-channels/laravel-exponent-push-notifications.svg?style=flat-square)](https://packagist.org/packages/alymosul/laravel-exponent-push-notifications) +[![Latest Version on Packagist](https://img.shields.io/packagist/v/alymosul/laravel-exponent-push-notifications.svg?style=flat-square)](https://packagist.org/packages/alymosul/laravel-exponent-push-notifications) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) [![Build Status](https://travis-ci.org/Alymosul/laravel-exponent-push-notifications.svg?branch=master)](https://travis-ci.org/Alymosul/laravel-exponent-push-notifications) [![StyleCI](https://styleci.io/repos/96645200/shield?branch=master)](https://styleci.io/repos/96645200) @@ -25,7 +25,7 @@ ## Installation You can install the package via composer: ```bash -composer require laravel-notification-channels/exponent-push-notifications +composer require alymosul/exponent-push-notifications ``` You must install the service provider: From 76817ada4af327434c15f577c52b87d3db8d1aa5 Mon Sep 17 00:00:00 2001 From: Alymosul Date: Sun, 9 Jul 2017 01:33:54 +0300 Subject: [PATCH 06/95] update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 084c66ac..6c7efc9a 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) [![Build Status](https://travis-ci.org/Alymosul/laravel-exponent-push-notifications.svg?branch=master)](https://travis-ci.org/Alymosul/laravel-exponent-push-notifications) [![StyleCI](https://styleci.io/repos/96645200/shield?branch=master)](https://styleci.io/repos/96645200) -[![SensioLabsInsight](https://img.shields.io/sensiolabs/i/:sensio_labs_id.svg?style=flat-square)](https://insight.sensiolabs.com/projects/:sensio_labs_id) +[![SensioLabsInsight](https://insight.sensiolabs.com/projects/afe0ba9a-e35c-4759-a06f-14a081cf452c/big.png)](https://insight.sensiolabs.com/projects/afe0ba9a-e35c-4759-a06f-14a081cf452c) [![Quality Score](https://img.shields.io/scrutinizer/g/alymosul/laravel-exponent-push-notifications.svg?style=flat-square)](https://scrutinizer-ci.com/g/alymosul/laravel-exponent-push-notifications) [![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/alymosul/laravel-exponent-push-notifications/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/alymosul/laravel-exponent-push-notifications/?branch=master) [![Total Downloads](https://img.shields.io/packagist/dt/alymosul/laravel-exponent-push-notifications.svg?style=flat-square)](https://packagist.org/packages/alymosul/laravel-exponent-push-notifications) From 97d7e0bbfaf70a5467c822e51d28630ea5c5a449 Mon Sep 17 00:00:00 2001 From: Alymosul Date: Sun, 9 Jul 2017 01:37:31 +0300 Subject: [PATCH 07/95] update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6c7efc9a..8b213811 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) [![Build Status](https://travis-ci.org/Alymosul/laravel-exponent-push-notifications.svg?branch=master)](https://travis-ci.org/Alymosul/laravel-exponent-push-notifications) [![StyleCI](https://styleci.io/repos/96645200/shield?branch=master)](https://styleci.io/repos/96645200) -[![SensioLabsInsight](https://insight.sensiolabs.com/projects/afe0ba9a-e35c-4759-a06f-14a081cf452c/big.png)](https://insight.sensiolabs.com/projects/afe0ba9a-e35c-4759-a06f-14a081cf452c) +[![SensioLabsInsight](https://img.shields.io/sensiolabs/i/afe0ba9a-e35c-4759-a06f-14a081cf452c.svg?style=flat-square)](https://insight.sensiolabs.com/projects/afe0ba9a-e35c-4759-a06f-14a081cf452c) [![Quality Score](https://img.shields.io/scrutinizer/g/alymosul/laravel-exponent-push-notifications.svg?style=flat-square)](https://scrutinizer-ci.com/g/alymosul/laravel-exponent-push-notifications) [![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/alymosul/laravel-exponent-push-notifications/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/alymosul/laravel-exponent-push-notifications/?branch=master) [![Total Downloads](https://img.shields.io/packagist/dt/alymosul/laravel-exponent-push-notifications.svg?style=flat-square)](https://packagist.org/packages/alymosul/laravel-exponent-push-notifications) From 4a0e22279c73dbac63210b18d8a725909db2aec0 Mon Sep 17 00:00:00 2001 From: Aly Suleiman Date: Sun, 9 Jul 2017 15:29:33 +0200 Subject: [PATCH 08/95] Update composer.json --- composer.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index dfaeba62..51cab314 100644 --- a/composer.json +++ b/composer.json @@ -13,14 +13,14 @@ "require": { "php": ">=7.0", "alymosul/exponent-server-sdk-php": "1.0.*", - "illuminate/notifications": "5.3 || 5.4.*", - "illuminate/support": "5.3 || 5.4.*", - "illuminate/events": "5.3 || 5.4.*", - "illuminate/queue": "5.3 || 5.4.*", - "illuminate/http": "5.3 || 5.4.*", - "illuminate/routing": "5.3 || 5.4.*", - "illuminate/validation": "5.3 || 5.4.*", - "illuminate/auth": "5.3 || 5.4" + "illuminate/notifications": "5.3.* || 5.4.*", + "illuminate/support": "5.3.* || 5.4.*", + "illuminate/events": "5.3.* || 5.4.*", + "illuminate/queue": "5.3.* || 5.4.*", + "illuminate/http": "5.3.* || 5.4.*", + "illuminate/routing": "5.3.* || 5.4.*", + "illuminate/validation": "5.3.* || 5.4.*", + "illuminate/auth": "5.3.* || 5.4.*" }, "require-dev": { "mockery/mockery": "^0.9.5", From 0450c75cd146382db7c397d453426afae0537b8f Mon Sep 17 00:00:00 2001 From: Aly Suleiman Date: Sun, 9 Jul 2017 15:48:14 +0200 Subject: [PATCH 09/95] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8b213811..596b656d 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ ## Installation You can install the package via composer: ```bash -composer require alymosul/exponent-push-notifications +composer require alymosul/laravel-exponent-push-notifications ``` You must install the service provider: From e5c4fa40d3674bacdedc68977ae8bb81ce681eb9 Mon Sep 17 00:00:00 2001 From: Lukas Klappert Date: Tue, 14 Nov 2017 18:46:26 +0100 Subject: [PATCH 10/95] Update dependencies for Laravel 5.5 --- composer.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 51cab314..3be48335 100644 --- a/composer.json +++ b/composer.json @@ -13,18 +13,18 @@ "require": { "php": ">=7.0", "alymosul/exponent-server-sdk-php": "1.0.*", - "illuminate/notifications": "5.3.* || 5.4.*", - "illuminate/support": "5.3.* || 5.4.*", - "illuminate/events": "5.3.* || 5.4.*", - "illuminate/queue": "5.3.* || 5.4.*", - "illuminate/http": "5.3.* || 5.4.*", - "illuminate/routing": "5.3.* || 5.4.*", - "illuminate/validation": "5.3.* || 5.4.*", - "illuminate/auth": "5.3.* || 5.4.*" + "illuminate/notifications": "~5.5.0", + "illuminate/support": "~5.5.0", + "illuminate/events": "~5.5.0", + "illuminate/queue": "~5.5.0", + "illuminate/http": "~5.5.0", + "illuminate/routing": "~5.5.0", + "illuminate/validation": "~5.5.0", + "illuminate/auth": "~5.5.0" }, "require-dev": { "mockery/mockery": "^0.9.5", - "phpunit/phpunit": "~5.7" + "phpunit/phpunit": "~6.0" }, "autoload": { "psr-4": { From ec403c4d087d24019af52221aa0e81845698bea0 Mon Sep 17 00:00:00 2001 From: Lukas Klappert Date: Tue, 14 Nov 2017 19:28:45 +0100 Subject: [PATCH 11/95] Update README for laravel <= 5.4 --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 596b656d..207fbf0d 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,12 @@ You can install the package via composer: ```bash composer require alymosul/laravel-exponent-push-notifications ``` + +If you use Laravel <= 5.4, please use release v1.0: +```bash +composer require alymosul/laravel-exponent-push-notifications dev-master#v1.0 +``` + You must install the service provider: ```php From d8450608f8d99f3205385e91648db1629abc1d40 Mon Sep 17 00:00:00 2001 From: Alymosul Date: Sat, 12 May 2018 14:55:19 +0200 Subject: [PATCH 12/95] Update dependencies to support Laravel 5.6 --- README.md | 7 +------ composer.json | 16 ++++++++-------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 207fbf0d..4c288196 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Exponent push notifications channel for Laravel 5.3 +# Exponent push notifications channel for Laravel 5 [![Latest Version on Packagist](https://img.shields.io/packagist/v/alymosul/laravel-exponent-push-notifications.svg?style=flat-square)](https://packagist.org/packages/alymosul/laravel-exponent-push-notifications) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) @@ -28,11 +28,6 @@ You can install the package via composer: composer require alymosul/laravel-exponent-push-notifications ``` -If you use Laravel <= 5.4, please use release v1.0: -```bash -composer require alymosul/laravel-exponent-push-notifications dev-master#v1.0 -``` - You must install the service provider: ```php diff --git a/composer.json b/composer.json index 3be48335..165f7cc6 100644 --- a/composer.json +++ b/composer.json @@ -13,14 +13,14 @@ "require": { "php": ">=7.0", "alymosul/exponent-server-sdk-php": "1.0.*", - "illuminate/notifications": "~5.5.0", - "illuminate/support": "~5.5.0", - "illuminate/events": "~5.5.0", - "illuminate/queue": "~5.5.0", - "illuminate/http": "~5.5.0", - "illuminate/routing": "~5.5.0", - "illuminate/validation": "~5.5.0", - "illuminate/auth": "~5.5.0" + "illuminate/notifications": "5.3.* || 5.4.* || 5.5.* || 5.6.*", + "illuminate/support": "5.3.* || 5.4.* || 5.5.* || 5.6.*", + "illuminate/events": "5.3.* || 5.4.* || 5.5.* || 5.6.*", + "illuminate/queue": "5.3.* || 5.4.* || 5.5.* || 5.6.*", + "illuminate/http": "5.3.* || 5.4.* || 5.5.* || 5.6.*", + "illuminate/routing": "5.3.* || 5.4.* || 5.5.* || 5.6.*", + "illuminate/validation": "5.3.* || 5.4.* || 5.5.* || 5.6.*", + "illuminate/auth": "5.3.* || 5.4.* || 5.5.* || 5.6.*" }, "require-dev": { "mockery/mockery": "^0.9.5", From cc2f5946f6bfe4b079255edc76d8616068447547 Mon Sep 17 00:00:00 2001 From: Alymosul Date: Sat, 12 May 2018 14:56:56 +0200 Subject: [PATCH 13/95] Fix StyleCI --- .styleci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.styleci.yml b/.styleci.yml index 916d27ee..0285f179 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -1,3 +1 @@ preset: laravel - -linting: true From f9372849288274145c559cd16a6ed49b0d364ada Mon Sep 17 00:00:00 2001 From: Alymosul Date: Wed, 4 Jul 2018 12:33:01 +0200 Subject: [PATCH 14/95] Add support to attach json data to the notification message. --- src/Exceptions/CouldNotCreateMessage.php | 7 ++++ src/ExpoMessage.php | 47 ++++++++++++++++++++++-- tests/MessageTest.php | 8 ++++ 3 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 src/Exceptions/CouldNotCreateMessage.php diff --git a/src/Exceptions/CouldNotCreateMessage.php b/src/Exceptions/CouldNotCreateMessage.php new file mode 100644 index 00000000..d40e9aa8 --- /dev/null +++ b/src/Exceptions/CouldNotCreateMessage.php @@ -0,0 +1,7 @@ +jsonData = $data; + + return $this; + } + /** * Get an array representation of the message. * @@ -127,10 +165,11 @@ public function setTtl(int $ttl) public function toArray() { return [ - 'body' => $this->body, - 'sound' => $this->sound, - 'badge' => $this->badge, - 'ttl' => $this->ttl, + 'body' => $this->body, + 'sound' => $this->sound, + 'badge' => $this->badge, + 'ttl' => $this->ttl, + 'jsonData' => $this->jsonData, ]; } } diff --git a/tests/MessageTest.php b/tests/MessageTest.php index 46b0532a..5bf0b2d4 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -90,4 +90,12 @@ public function itCanSetTimeToLive() $this->assertEquals(60, Arr::get($this->message->toArray(), 'ttl')); } + + /** @test */ + public function itCanSetJSONData() + { + $this->message->setJsonData('{"name":"Aly"}'); + + $this->assertEquals('{"name":"Aly"}', Arr::get($this->message->toArray(), 'jsonData')); + } } From c6fb91d2e3bf6f660ba336039b98259dc3bbbfe7 Mon Sep 17 00:00:00 2001 From: Aly Suleiman Date: Wed, 4 Jul 2018 10:35:42 +0000 Subject: [PATCH 15/95] Apply fixes from StyleCI --- src/Exceptions/CouldNotCreateMessage.php | 2 +- src/ExpoMessage.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Exceptions/CouldNotCreateMessage.php b/src/Exceptions/CouldNotCreateMessage.php index d40e9aa8..55027fea 100644 --- a/src/Exceptions/CouldNotCreateMessage.php +++ b/src/Exceptions/CouldNotCreateMessage.php @@ -4,4 +4,4 @@ class CouldNotCreateMessage extends \Exception { -} \ No newline at end of file +} diff --git a/src/ExpoMessage.php b/src/ExpoMessage.php index 411243fd..1cf48973 100644 --- a/src/ExpoMessage.php +++ b/src/ExpoMessage.php @@ -143,8 +143,7 @@ public function setJsonData($data) { if (is_array($data)) { $data = json_encode($data); - } - elseif (is_string($data)) { + } elseif (is_string($data)) { @json_decode($data); if (json_last_error() !== JSON_ERROR_NONE) { From c19eeba0a82b8d6e465f75366d71689a8cda1187 Mon Sep 17 00:00:00 2001 From: Alymosul Date: Wed, 4 Jul 2018 12:52:20 +0200 Subject: [PATCH 16/95] Fix json data property in toArray method in ExpoMessage --- src/ExpoMessage.php | 2 +- tests/MessageTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ExpoMessage.php b/src/ExpoMessage.php index 1cf48973..190513ae 100644 --- a/src/ExpoMessage.php +++ b/src/ExpoMessage.php @@ -168,7 +168,7 @@ public function toArray() 'sound' => $this->sound, 'badge' => $this->badge, 'ttl' => $this->ttl, - 'jsonData' => $this->jsonData, + 'data' => $this->jsonData, ]; } } diff --git a/tests/MessageTest.php b/tests/MessageTest.php index 5bf0b2d4..9c80e41b 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -96,6 +96,6 @@ public function itCanSetJSONData() { $this->message->setJsonData('{"name":"Aly"}'); - $this->assertEquals('{"name":"Aly"}', Arr::get($this->message->toArray(), 'jsonData')); + $this->assertEquals('{"name":"Aly"}', Arr::get($this->message->toArray(), 'data')); } } From 883fbf6ef53b74637be7d67ebb02bda8311367cf Mon Sep 17 00:00:00 2001 From: Alymosul Date: Wed, 25 Jul 2018 15:48:58 +0200 Subject: [PATCH 17/95] Accomodate to breaking change introduced in v27 for Android devices --- src/ExpoMessage.php | 20 +++++++++++++++++++- tests/MessageTest.php | 8 ++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/ExpoMessage.php b/src/ExpoMessage.php index 190513ae..bcff967c 100644 --- a/src/ExpoMessage.php +++ b/src/ExpoMessage.php @@ -35,6 +35,13 @@ class ExpoMessage */ protected $ttl = 0; + /** + * ID of the Notification Channel through which to display this notification on Android devices. + * + * @var string + */ + protected $channelId = "Default"; + /** * The json data attached to the message. * @@ -130,6 +137,16 @@ public function setTtl(int $ttl) return $this; } + /** + * Set the channelId of the notification for Android devices. + * + * @param string $channelId + */ + public function setChannelId(string $channelId) + { + $this->channelId = $channelId; + } + /** * Set the json Data attached to the message. * @@ -168,7 +185,8 @@ public function toArray() 'sound' => $this->sound, 'badge' => $this->badge, 'ttl' => $this->ttl, - 'data' => $this->jsonData, + 'channelId' => $this->channelId, + 'data' => $this->jsonData, ]; } } diff --git a/tests/MessageTest.php b/tests/MessageTest.php index 9c80e41b..a36acc38 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -91,6 +91,14 @@ public function itCanSetTimeToLive() $this->assertEquals(60, Arr::get($this->message->toArray(), 'ttl')); } + /** @test */ + public function itCanSetChannelId() + { + $this->message->setChannelId('some-channel'); + + $this->assertEquals('some-channel', Arr::get($this->message->toArray(), 'channelId')); + } + /** @test */ public function itCanSetJSONData() { From 68fddd3c4f4c6f94a2af306484b90e63689a9a49 Mon Sep 17 00:00:00 2001 From: Alymosul Date: Wed, 25 Jul 2018 15:50:01 +0200 Subject: [PATCH 18/95] Fix Styling --- src/ExpoMessage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ExpoMessage.php b/src/ExpoMessage.php index bcff967c..d27c8b68 100644 --- a/src/ExpoMessage.php +++ b/src/ExpoMessage.php @@ -40,7 +40,7 @@ class ExpoMessage * * @var string */ - protected $channelId = "Default"; + protected $channelId = 'Default'; /** * The json data attached to the message. From f61771046e87d53e49d4beddb0e913b80e34a2d8 Mon Sep 17 00:00:00 2001 From: Alymosul Date: Thu, 26 Jul 2018 12:28:17 +0200 Subject: [PATCH 19/95] Return this from setChannelId() --- src/ExpoMessage.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ExpoMessage.php b/src/ExpoMessage.php index d27c8b68..b3f9c546 100644 --- a/src/ExpoMessage.php +++ b/src/ExpoMessage.php @@ -141,10 +141,13 @@ public function setTtl(int $ttl) * Set the channelId of the notification for Android devices. * * @param string $channelId + * + * @return $this */ public function setChannelId(string $channelId) { $this->channelId = $channelId; + return $this; } /** From 469c4535736f60002bcb238249b05ff25870b4b6 Mon Sep 17 00:00:00 2001 From: Aly Suleiman Date: Thu, 26 Jul 2018 10:29:12 +0000 Subject: [PATCH 20/95] Apply fixes from StyleCI --- src/ExpoMessage.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ExpoMessage.php b/src/ExpoMessage.php index b3f9c546..1097586a 100644 --- a/src/ExpoMessage.php +++ b/src/ExpoMessage.php @@ -147,6 +147,7 @@ public function setTtl(int $ttl) public function setChannelId(string $channelId) { $this->channelId = $channelId; + return $this; } From 566820f872bba3f1b3a7b12d41863ce0c3267f88 Mon Sep 17 00:00:00 2001 From: Alymosul Date: Thu, 26 Jul 2018 15:17:02 +0200 Subject: [PATCH 21/95] Fix bug in default value for jsonData --- src/ExpoMessage.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ExpoMessage.php b/src/ExpoMessage.php index b3f9c546..a016bb04 100644 --- a/src/ExpoMessage.php +++ b/src/ExpoMessage.php @@ -47,7 +47,7 @@ class ExpoMessage * * @var string */ - protected $jsonData = ''; + protected $jsonData = '{}'; /** * Create a message with given body. @@ -147,6 +147,7 @@ public function setTtl(int $ttl) public function setChannelId(string $channelId) { $this->channelId = $channelId; + return $this; } From 89c1c2927c35ac173d92ef44ec3b6ae0690d96d3 Mon Sep 17 00:00:00 2001 From: Aly Suleiman Date: Thu, 26 Jul 2018 13:19:35 +0000 Subject: [PATCH 22/95] Apply fixes from StyleCI --- src/ExpoMessage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ExpoMessage.php b/src/ExpoMessage.php index a016bb04..3a7bc8bd 100644 --- a/src/ExpoMessage.php +++ b/src/ExpoMessage.php @@ -147,7 +147,7 @@ public function setTtl(int $ttl) public function setChannelId(string $channelId) { $this->channelId = $channelId; - + return $this; } From 6a3687be2e839d2efe2b1099cc4e6bb225558c13 Mon Sep 17 00:00:00 2001 From: Patrick Kivits Date: Mon, 27 Aug 2018 14:33:17 +0200 Subject: [PATCH 23/95] Implemented Package Discovery --- README.md | 10 +--------- composer.json | 7 +++++++ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4c288196..d30c177c 100644 --- a/README.md +++ b/README.md @@ -28,15 +28,7 @@ You can install the package via composer: composer require alymosul/laravel-exponent-push-notifications ``` -You must install the service provider: - -```php -// config/app.php -'providers' => [ - ... - NotificationChannels\ExpoPushNotifications\ExpoPushNotificationsServiceProvider::class, -], -``` +The package will automatically register itself. ## Usage diff --git a/composer.json b/composer.json index 165f7cc6..1960655d 100644 --- a/composer.json +++ b/composer.json @@ -41,5 +41,12 @@ }, "config": { "sort-packages": true + }, + "extra": { + "laravel": { + "providers": [ + "NotificationChannels\\ExpoPushNotifications\\ExpoPushNotificationsServiceProvider" + ] + } } } From 1e65f1166826657ee6b19241771b043b76aefac8 Mon Sep 17 00:00:00 2001 From: Patrick Kivits Date: Mon, 27 Aug 2018 15:38:08 +0200 Subject: [PATCH 24/95] Implemented database driver for storage of interests --- README.md | 33 +++++++++++ config/exponent-push-notifications.php | 14 +++++ ...push_notification_interests_table.php.stub | 27 +++++++++ src/ExpoPushNotificationsServiceProvider.php | 32 +++++++++- src/Http/routes.php | 2 +- src/Models/Interest.php | 24 ++++++++ src/Repositories/ExpoDatabaseDriver.php | 58 +++++++++++++++++++ 7 files changed, 187 insertions(+), 3 deletions(-) create mode 100644 config/exponent-push-notifications.php create mode 100644 migrations/create_exponent_push_notification_interests_table.php.stub create mode 100644 src/Models/Interest.php create mode 100644 src/Repositories/ExpoDatabaseDriver.php diff --git a/README.md b/README.md index d30c177c..d2d0ff61 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,39 @@ composer require alymosul/laravel-exponent-push-notifications The package will automatically register itself. +You can publish the migration with: +```bash +php artisan vendor:publish --provider="NotificationChannels\ExpoPushNotifications\ExpoPushNotificationsServiceProvider" --tag="migrations" +``` + +After publishing the migration you can create the `exponent_push_notification_interests` table by running the migrations: + +```bash +php artisan migrate +``` + +You can optionally publish the config file with: +```bash +php artisan vendor:publish --provider="NotificationChannels\ExpoPushNotifications\ExpoPushNotificationsServiceProvider" --tag="config" +``` + +This is the contents of the published config file: + +```php +return [ + 'interests' => [ + /* + * Supported: "file", "database" + */ + 'driver' => env('EXPONENT_PUSH_NOTIFICATION_INTERESTS_STORAGE_DRIVER', 'file'), + + 'database' => [ + 'table_name' => 'exponent_push_notification_interests', + ], + ] +]; +``` + ## Usage ``` php diff --git a/config/exponent-push-notifications.php b/config/exponent-push-notifications.php new file mode 100644 index 00000000..b85db592 --- /dev/null +++ b/config/exponent-push-notifications.php @@ -0,0 +1,14 @@ + [ + /* + * Supported: "file", "database" + */ + 'driver' => env('EXPONENT_PUSH_NOTIFICATION_INTERESTS_STORAGE_DRIVER', 'file'), + + 'database' => [ + 'table_name' => 'exponent_push_notification_interests', + ], + ] +]; \ No newline at end of file diff --git a/migrations/create_exponent_push_notification_interests_table.php.stub b/migrations/create_exponent_push_notification_interests_table.php.stub new file mode 100644 index 00000000..95dc2dde --- /dev/null +++ b/migrations/create_exponent_push_notification_interests_table.php.stub @@ -0,0 +1,27 @@ +string('key')->unique(); + $table->string('value'); + }); + } + + /** + * Reverse the migrations. + */ + public function down() + { + Schema::drop(config('exponent-push-notifications.interests.database.table_name')); + } +} \ No newline at end of file diff --git a/src/ExpoPushNotificationsServiceProvider.php b/src/ExpoPushNotificationsServiceProvider.php index 7519a448..c248c832 100644 --- a/src/ExpoPushNotificationsServiceProvider.php +++ b/src/ExpoPushNotificationsServiceProvider.php @@ -5,6 +5,7 @@ use ExponentPhpSDK\Expo; use ExponentPhpSDK\ExpoRegistrar; use ExponentPhpSDK\ExpoRepository; +use NotificationChannels\ExpoPushNotifications\Repositories\ExpoDatabaseDriver; use Illuminate\Support\ServiceProvider; use ExponentPhpSDK\Repositories\ExpoFileDriver; @@ -15,10 +16,30 @@ class ExpoPushNotificationsServiceProvider extends ServiceProvider */ public function boot() { + $this->publishes([ + __DIR__.'/../config/exponent-push-notifications.php' => config_path('exponent-push-notifications.php'), + ], 'config'); + + $this->mergeConfigFrom(__DIR__.'/../config/exponent-push-notifications.php', 'exponent-push-notifications'); + + if (! class_exists('CreateExponentPushNotificationInterestsTable')) { + $timestamp = date('Y_m_d_His', time()); + $this->publishes([ + __DIR__.'/../migrations/create_exponent_push_notification_interests_table.php.stub' => database_path("/migrations/{$timestamp}_create_exponent_push_notification_interests_table.php"), + ], 'migrations'); + } + $this->app->when(ExpoChannel::class) ->needs(Expo::class) ->give(function () { - return new Expo(new ExpoRegistrar(new ExpoFileDriver())); + $driver = new ExpoFileDriver(); + + if(config('exponent-push-notifications.interests.driver') === 'database') + { + $driver = new ExpoDatabaseDriver(); + } + + return new Expo(new ExpoRegistrar($driver)); }); //Load routes @@ -30,6 +51,13 @@ public function boot() */ public function register() { - $this->app->bind(ExpoRepository::class, ExpoFileDriver::class); + $driverClass = ExpoFileDriver::class; + + if(config('exponent-push-notifications.interests.driver') === 'database') + { + $driverClass = ExpoDatabaseDriver::class; + } + + $this->app->bind(ExpoRepository::class, $driverClass); } } diff --git a/src/Http/routes.php b/src/Http/routes.php index 4f0ed16e..dfd005d6 100644 --- a/src/Http/routes.php +++ b/src/Http/routes.php @@ -1,6 +1,6 @@ 'api/exponent/devices', 'middleware' => 'auth:api, bindings'], function () { +Route::group(['prefix' => 'api/exponent/devices', 'middleware' => ['auth:api','bindings']], function () { Route::post('subscribe', [ 'as' => 'register-interest', 'uses' => 'NotificationChannels\ExpoPushNotifications\Http\ExpoController@subscribe', diff --git a/src/Models/Interest.php b/src/Models/Interest.php new file mode 100644 index 00000000..799c0925 --- /dev/null +++ b/src/Models/Interest.php @@ -0,0 +1,24 @@ +table = config('exponent-push-notifications.interests.database.table_name'); + + parent::__construct($attributes); + } +} \ No newline at end of file diff --git a/src/Repositories/ExpoDatabaseDriver.php b/src/Repositories/ExpoDatabaseDriver.php new file mode 100644 index 00000000..cc5187fa --- /dev/null +++ b/src/Repositories/ExpoDatabaseDriver.php @@ -0,0 +1,58 @@ + $key, + 'value' => $value + ]); + + return $interest instanceof Interest; + } + + /** + * Retrieves an Expo token with a given identifier + * + * @param string $key + * + * @return string|null + */ + public function retrieve(string $key) + { + $interest = Interest::where('key', $key)->first(); + + if($interest instanceof Interest) + { + return (string) $interest->value; + } + + return null; + } + + /** + * Removes an Expo token with a given identifier + * + * @param string $key + * + * @return bool + */ + public function forget(string $key): bool + { + return Interest::where('key', $key)->delete(); + } +} \ No newline at end of file From 879d93a746917fa532d8d2ee006af0191484f687 Mon Sep 17 00:00:00 2001 From: Patrick Kivits Date: Mon, 27 Aug 2018 16:02:35 +0200 Subject: [PATCH 25/95] Allow for multiple values per key in database structure (e.q. multiple devices per user) --- ...reate_exponent_push_notification_interests_table.php.stub | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/migrations/create_exponent_push_notification_interests_table.php.stub b/migrations/create_exponent_push_notification_interests_table.php.stub index 95dc2dde..691d7793 100644 --- a/migrations/create_exponent_push_notification_interests_table.php.stub +++ b/migrations/create_exponent_push_notification_interests_table.php.stub @@ -12,8 +12,11 @@ class CreateExponentPushNotificationInterestsTable extends Migration public function up() { Schema::create(config('exponent-push-notifications.interests.database.table_name'), function (Blueprint $table) { - $table->string('key')->unique(); + $table->string('key'); $table->string('value'); + + $table->index('key'); + $table->unique(['key','value']); }); } From af23c8fcd0c8e9a7743d42e2ff08aa9f80f6f0aa Mon Sep 17 00:00:00 2001 From: Patrick Kivits Date: Mon, 27 Aug 2018 16:51:46 +0200 Subject: [PATCH 26/95] Return array of retrieved values to support multiple tokens per user --- src/Repositories/ExpoDatabaseDriver.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Repositories/ExpoDatabaseDriver.php b/src/Repositories/ExpoDatabaseDriver.php index cc5187fa..6b220760 100644 --- a/src/Repositories/ExpoDatabaseDriver.php +++ b/src/Repositories/ExpoDatabaseDriver.php @@ -34,14 +34,7 @@ public function store($key, $value): bool */ public function retrieve(string $key) { - $interest = Interest::where('key', $key)->first(); - - if($interest instanceof Interest) - { - return (string) $interest->value; - } - - return null; + return Interest::where('key', $key)->pluck('value')->toArray(); } /** From 3beed52f51a85b9191e75c6493fca03c31df828c Mon Sep 17 00:00:00 2001 From: Patrick Kivits Date: Tue, 28 Aug 2018 09:12:51 +0200 Subject: [PATCH 27/95] Style CI changes: https://github.styleci.io/analyses/zGyEQ9 --- config/exponent-push-notifications.php | 4 ++-- src/ExpoPushNotificationsServiceProvider.php | 8 +++----- src/Http/routes.php | 2 +- src/Models/Interest.php | 2 +- src/Repositories/ExpoDatabaseDriver.php | 6 +++--- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/config/exponent-push-notifications.php b/config/exponent-push-notifications.php index b85db592..94c93b1f 100644 --- a/config/exponent-push-notifications.php +++ b/config/exponent-push-notifications.php @@ -8,7 +8,7 @@ 'driver' => env('EXPONENT_PUSH_NOTIFICATION_INTERESTS_STORAGE_DRIVER', 'file'), 'database' => [ - 'table_name' => 'exponent_push_notification_interests', - ], + 'table_name' => 'exponent_push_notification_interests' + ] ] ]; \ No newline at end of file diff --git a/src/ExpoPushNotificationsServiceProvider.php b/src/ExpoPushNotificationsServiceProvider.php index c248c832..1afc27b2 100644 --- a/src/ExpoPushNotificationsServiceProvider.php +++ b/src/ExpoPushNotificationsServiceProvider.php @@ -5,9 +5,9 @@ use ExponentPhpSDK\Expo; use ExponentPhpSDK\ExpoRegistrar; use ExponentPhpSDK\ExpoRepository; -use NotificationChannels\ExpoPushNotifications\Repositories\ExpoDatabaseDriver; use Illuminate\Support\ServiceProvider; use ExponentPhpSDK\Repositories\ExpoFileDriver; +use NotificationChannels\ExpoPushNotifications\Repositories\ExpoDatabaseDriver; class ExpoPushNotificationsServiceProvider extends ServiceProvider { @@ -34,8 +34,7 @@ public function boot() ->give(function () { $driver = new ExpoFileDriver(); - if(config('exponent-push-notifications.interests.driver') === 'database') - { + if(config('exponent-push-notifications.interests.driver') === 'database') { $driver = new ExpoDatabaseDriver(); } @@ -53,8 +52,7 @@ public function register() { $driverClass = ExpoFileDriver::class; - if(config('exponent-push-notifications.interests.driver') === 'database') - { + if(config('exponent-push-notifications.interests.driver') === 'database') { $driverClass = ExpoDatabaseDriver::class; } diff --git a/src/Http/routes.php b/src/Http/routes.php index dfd005d6..788512ee 100644 --- a/src/Http/routes.php +++ b/src/Http/routes.php @@ -1,6 +1,6 @@ 'api/exponent/devices', 'middleware' => ['auth:api','bindings']], function () { +Route::group(['prefix' => 'api/exponent/devices', 'middleware' => ['auth:api', 'bindings']], function () { Route::post('subscribe', [ 'as' => 'register-interest', 'uses' => 'NotificationChannels\ExpoPushNotifications\Http\ExpoController@subscribe', diff --git a/src/Models/Interest.php b/src/Models/Interest.php index 799c0925..57fd4160 100644 --- a/src/Models/Interest.php +++ b/src/Models/Interest.php @@ -10,7 +10,7 @@ class Interest extends Model protected $fillable = [ 'key', - 'value' + 'value', ]; public $timestamps = false; diff --git a/src/Repositories/ExpoDatabaseDriver.php b/src/Repositories/ExpoDatabaseDriver.php index 6b220760..812e99e5 100644 --- a/src/Repositories/ExpoDatabaseDriver.php +++ b/src/Repositories/ExpoDatabaseDriver.php @@ -8,7 +8,7 @@ class ExpoDatabaseDriver implements ExpoRepository { /** - * Stores an Expo token with a given identifier + * Stores an Expo token with a given identifier. * * @param $key * @param $value @@ -26,7 +26,7 @@ public function store($key, $value): bool } /** - * Retrieves an Expo token with a given identifier + * Retrieves an Expo token with a given identifier. * * @param string $key * @@ -38,7 +38,7 @@ public function retrieve(string $key) } /** - * Removes an Expo token with a given identifier + * Removes an Expo token with a given identifier. * * @param string $key * From d3908b5d18a4cf399fb6b510f5a2bd6481036482 Mon Sep 17 00:00:00 2001 From: Patrick Kivits Date: Tue, 28 Aug 2018 09:14:52 +0200 Subject: [PATCH 28/95] Style CI changes: https://github.styleci.io/analyses/zDpKgB --- config/exponent-push-notifications.php | 6 +++--- src/ExpoPushNotificationsServiceProvider.php | 4 ++-- src/Repositories/ExpoDatabaseDriver.php | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config/exponent-push-notifications.php b/config/exponent-push-notifications.php index 94c93b1f..ed2eecc6 100644 --- a/config/exponent-push-notifications.php +++ b/config/exponent-push-notifications.php @@ -8,7 +8,7 @@ 'driver' => env('EXPONENT_PUSH_NOTIFICATION_INTERESTS_STORAGE_DRIVER', 'file'), 'database' => [ - 'table_name' => 'exponent_push_notification_interests' - ] - ] + 'table_name' => 'exponent_push_notification_interests', + ], + ], ]; \ No newline at end of file diff --git a/src/ExpoPushNotificationsServiceProvider.php b/src/ExpoPushNotificationsServiceProvider.php index 1afc27b2..46cee5a6 100644 --- a/src/ExpoPushNotificationsServiceProvider.php +++ b/src/ExpoPushNotificationsServiceProvider.php @@ -34,7 +34,7 @@ public function boot() ->give(function () { $driver = new ExpoFileDriver(); - if(config('exponent-push-notifications.interests.driver') === 'database') { + if (config('exponent-push-notifications.interests.driver') === 'database') { $driver = new ExpoDatabaseDriver(); } @@ -52,7 +52,7 @@ public function register() { $driverClass = ExpoFileDriver::class; - if(config('exponent-push-notifications.interests.driver') === 'database') { + if (config('exponent-push-notifications.interests.driver') === 'database') { $driverClass = ExpoDatabaseDriver::class; } diff --git a/src/Repositories/ExpoDatabaseDriver.php b/src/Repositories/ExpoDatabaseDriver.php index 812e99e5..0c40b568 100644 --- a/src/Repositories/ExpoDatabaseDriver.php +++ b/src/Repositories/ExpoDatabaseDriver.php @@ -19,7 +19,7 @@ public function store($key, $value): bool { $interest = Interest::firstOrCreate([ 'key' => $key, - 'value' => $value + 'value' => $value, ]); return $interest instanceof Interest; From 3a634d544ecf9deeeac7c3fcdce0add69eae0183 Mon Sep 17 00:00:00 2001 From: Patrick Kivits Date: Tue, 28 Aug 2018 15:02:15 +0200 Subject: [PATCH 29/95] Added PHP DocBlocks --- src/Models/Interest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Models/Interest.php b/src/Models/Interest.php index 57fd4160..3f868a00 100644 --- a/src/Models/Interest.php +++ b/src/Models/Interest.php @@ -4,17 +4,34 @@ use Illuminate\Database\Eloquent\Model; +/** + * Class Interest + * @package NotificationChannels\ExpoPushNotifications\Models + */ class Interest extends Model { + /** + * @var string + */ protected $table; + /** + * @var array + */ protected $fillable = [ 'key', 'value', ]; + /** + * @var bool + */ public $timestamps = false; + /** + * Interest constructor. + * @param array $attributes + */ public function __construct(array $attributes = []) { $this->table = config('exponent-push-notifications.interests.database.table_name'); From 86cdbf7904628f84dd401506fac0c6f89fd60943 Mon Sep 17 00:00:00 2001 From: Patrick Kivits Date: Tue, 28 Aug 2018 15:02:52 +0200 Subject: [PATCH 30/95] Updated readme for package installation with older versions of Laravel without Package Discovering --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d2d0ff61..d9da973b 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,15 @@ You can install the package via composer: composer require alymosul/laravel-exponent-push-notifications ``` -The package will automatically register itself. +If you are using Laravel 5.5 or higher this package will automatically register itself using [Package Discovery](https://laravel.com/docs/5.5/packages#package-discovery). For older versions of Laravel you must install the service provider manually: + +```php +// config/app.php +'providers' => [ + ... + NotificationChannels\ExpoPushNotifications\ExpoPushNotificationsServiceProvider::class, +], +``` You can publish the migration with: ```bash From b4fb226e6985c8550130499d3edf2a436215eafb Mon Sep 17 00:00:00 2001 From: Patrick Kivits Date: Wed, 29 Aug 2018 09:31:17 +0200 Subject: [PATCH 31/95] Retrieve function now only returns an array either empty or filled with token(s) --- src/Repositories/ExpoDatabaseDriver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Repositories/ExpoDatabaseDriver.php b/src/Repositories/ExpoDatabaseDriver.php index 0c40b568..c923a31c 100644 --- a/src/Repositories/ExpoDatabaseDriver.php +++ b/src/Repositories/ExpoDatabaseDriver.php @@ -30,7 +30,7 @@ public function store($key, $value): bool * * @param string $key * - * @return string|null + * @return array */ public function retrieve(string $key) { From 8989651c1564a17d6e0572eb5a13940b28c47896 Mon Sep 17 00:00:00 2001 From: Patrick Kivits Date: Wed, 29 Aug 2018 09:44:08 +0200 Subject: [PATCH 32/95] Cleanup driver determination in service provider --- src/ExpoPushNotificationsServiceProvider.php | 30 ++++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/ExpoPushNotificationsServiceProvider.php b/src/ExpoPushNotificationsServiceProvider.php index 46cee5a6..732c50ce 100644 --- a/src/ExpoPushNotificationsServiceProvider.php +++ b/src/ExpoPushNotificationsServiceProvider.php @@ -32,13 +32,7 @@ public function boot() $this->app->when(ExpoChannel::class) ->needs(Expo::class) ->give(function () { - $driver = new ExpoFileDriver(); - - if (config('exponent-push-notifications.interests.driver') === 'database') { - $driver = new ExpoDatabaseDriver(); - } - - return new Expo(new ExpoRegistrar($driver)); + return new Expo(new ExpoRegistrar($this->getInterestsDriver())); }); //Load routes @@ -50,12 +44,24 @@ public function boot() */ public function register() { - $driverClass = ExpoFileDriver::class; + $this->app->bind(ExpoRepository::class, get_class($this->getInterestsDriver())); + } + + /** + * @return ExpoRepository + */ + public function getInterestsDriver() + { + $driver = config('exponent-push-notifications.interests.driver'); - if (config('exponent-push-notifications.interests.driver') === 'database') { - $driverClass = ExpoDatabaseDriver::class; + switch ($driver) { + case 'database': + $class = new ExpoDatabaseDriver(); + break; + default: + $class = new ExpoFileDriver(); } - $this->app->bind(ExpoRepository::class, $driverClass); + return $class; } -} +} \ No newline at end of file From f1eb4801faaa67be18e85b1da85a604e936de571 Mon Sep 17 00:00:00 2001 From: Patrick Kivits Date: Wed, 29 Aug 2018 10:11:49 +0200 Subject: [PATCH 33/95] Style CI changes: https://github.styleci.io/analyses/XaOE7B --- src/Models/Interest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Models/Interest.php b/src/Models/Interest.php index 3f868a00..b2add270 100644 --- a/src/Models/Interest.php +++ b/src/Models/Interest.php @@ -5,8 +5,7 @@ use Illuminate\Database\Eloquent\Model; /** - * Class Interest - * @package NotificationChannels\ExpoPushNotifications\Models + * Class Interest. */ class Interest extends Model { From ebc371442c2ef8ac61ccbf3234304585d8283476 Mon Sep 17 00:00:00 2001 From: Patrick Kivits Date: Mon, 3 Sep 2018 09:32:14 +0200 Subject: [PATCH 34/95] Added refactored test suite and tests for database driver --- composer.json | 4 +- phpunit.xml.dist | 2 +- src/ExpoChannel.php | 4 +- src/ExpoPushNotificationsServiceProvider.php | 8 +- src/Http/ExpoController.php | 2 +- tests/ChannelTest.php | 7 +- ...lerTest.php => ExpoDatabaseDriverTest.php} | 57 ++------ tests/ExpoFileDriverTest.php | 132 ++++++++++++++++++ tests/MessageTest.php | 1 - tests/TestCase.php | 107 ++++++++++++++ tests/temp/.gitignore | 2 + 11 files changed, 262 insertions(+), 64 deletions(-) rename tests/{ExpoControllerTest.php => ExpoDatabaseDriverTest.php} (78%) create mode 100644 tests/ExpoFileDriverTest.php create mode 100644 tests/TestCase.php create mode 100644 tests/temp/.gitignore diff --git a/composer.json b/composer.json index 1960655d..4dad50df 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,7 @@ "require": { "php": ">=7.0", "alymosul/exponent-server-sdk-php": "1.0.*", + "illuminate/config": "5.3.* || 5.4.* || 5.5.* || 5.6.*", "illuminate/notifications": "5.3.* || 5.4.* || 5.5.* || 5.6.*", "illuminate/support": "5.3.* || 5.4.* || 5.5.* || 5.6.*", "illuminate/events": "5.3.* || 5.4.* || 5.5.* || 5.6.*", @@ -24,7 +25,8 @@ }, "require-dev": { "mockery/mockery": "^0.9.5", - "phpunit/phpunit": "~6.0" + "phpunit/phpunit": "^6.2|^7.0", + "orchestra/testbench": "~3.5.0|~3.6.0" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b06b7eea..a09f43bd 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -22,7 +22,7 @@ - + diff --git a/src/ExpoChannel.php b/src/ExpoChannel.php index d9e6775b..6cd26356 100644 --- a/src/ExpoChannel.php +++ b/src/ExpoChannel.php @@ -2,11 +2,11 @@ namespace NotificationChannels\ExpoPushNotifications; +use ExponentPhpSDK\Exceptions\ExpoException; use ExponentPhpSDK\Expo; use Illuminate\Events\Dispatcher; -use Illuminate\Notifications\Notification; -use ExponentPhpSDK\Exceptions\ExpoException; use Illuminate\Notifications\Events\NotificationFailed; +use Illuminate\Notifications\Notification; use NotificationChannels\ExpoPushNotifications\Exceptions\CouldNotSendNotification; class ExpoChannel diff --git a/src/ExpoPushNotificationsServiceProvider.php b/src/ExpoPushNotificationsServiceProvider.php index 732c50ce..fbe9fa03 100644 --- a/src/ExpoPushNotificationsServiceProvider.php +++ b/src/ExpoPushNotificationsServiceProvider.php @@ -5,8 +5,8 @@ use ExponentPhpSDK\Expo; use ExponentPhpSDK\ExpoRegistrar; use ExponentPhpSDK\ExpoRepository; -use Illuminate\Support\ServiceProvider; use ExponentPhpSDK\Repositories\ExpoFileDriver; +use Illuminate\Support\ServiceProvider; use NotificationChannels\ExpoPushNotifications\Repositories\ExpoDatabaseDriver; class ExpoPushNotificationsServiceProvider extends ServiceProvider @@ -56,12 +56,10 @@ public function getInterestsDriver() switch ($driver) { case 'database': - $class = new ExpoDatabaseDriver(); + return new ExpoDatabaseDriver(); break; default: - $class = new ExpoFileDriver(); + return new ExpoFileDriver(); } - - return $class; } } \ No newline at end of file diff --git a/src/Http/ExpoController.php b/src/Http/ExpoController.php index bc229932..3838493f 100644 --- a/src/Http/ExpoController.php +++ b/src/Http/ExpoController.php @@ -2,8 +2,8 @@ namespace NotificationChannels\ExpoPushNotifications\Http; -use Illuminate\Http\Request; use Illuminate\Http\JsonResponse; +use Illuminate\Http\Request; use Illuminate\Routing\Controller; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Validator; diff --git a/tests/ChannelTest.php b/tests/ChannelTest.php index 62ee9eac..e72f98e6 100644 --- a/tests/ChannelTest.php +++ b/tests/ChannelTest.php @@ -2,14 +2,13 @@ namespace NotificationChannels\ExpoPushNotifications\Test; -use Mockery; +use ExponentPhpSDK\Exceptions\ExpoException; use ExponentPhpSDK\Expo; -use PHPUnit\Framework\TestCase; use Illuminate\Events\Dispatcher; +use Illuminate\Notifications\Events\NotificationFailed; use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notification; -use ExponentPhpSDK\Exceptions\ExpoException; -use Illuminate\Notifications\Events\NotificationFailed; +use Mockery; use NotificationChannels\ExpoPushNotifications\ExpoChannel; use NotificationChannels\ExpoPushNotifications\ExpoMessage; diff --git a/tests/ExpoControllerTest.php b/tests/ExpoDatabaseDriverTest.php similarity index 78% rename from tests/ExpoControllerTest.php rename to tests/ExpoDatabaseDriverTest.php index 8f02b63c..9f89d776 100644 --- a/tests/ExpoControllerTest.php +++ b/tests/ExpoDatabaseDriverTest.php @@ -3,16 +3,15 @@ namespace NotificationChannels\ExpoPushNotifications\Test; use ExponentPhpSDK\Expo; -use Illuminate\Http\Request; -use PHPUnit\Framework\TestCase; +use ExponentPhpSDK\ExpoRegistrar; use Illuminate\Events\Dispatcher; -use Illuminate\Validation\Factory; +use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; -use Illuminate\Support\Facades\Validator; use NotificationChannels\ExpoPushNotifications\ExpoChannel; use NotificationChannels\ExpoPushNotifications\Http\ExpoController; +use NotificationChannels\ExpoPushNotifications\Repositories\ExpoDatabaseDriver; -class ExpoControllerTest extends TestCase +class ExpoDatabaseDriverTest extends TestCase { /** * @var ExpoChannel @@ -28,7 +27,9 @@ public function setUp() { parent::setUp(); - $this->expoChannel = new ExpoChannel(Expo::normalSetup(), new Dispatcher()); + $this->setUpDatabase(); + + $this->expoChannel = new ExpoChannel(new Expo(new ExpoRegistrar(new ExpoDatabaseDriver())), new Dispatcher()); $this->expoController = new ExpoController($this->expoChannel); @@ -130,46 +131,4 @@ public function unsubscribeReturnsErrorResponseIfExceptionIsThrown() $this->assertEquals('failed', $response->status); } - - /** - * Mocks a request for the ExpoController. - * - * @param $data - * - * @return \Mockery\MockInterface - */ - private function mockRequest($data) - { - $request = \Mockery::mock(Request::class); - $request->shouldReceive('all')->andReturn($data); - - return $request; - } - - /** - * @param bool $fails - * - * @return \Mockery\MockInterface - */ - private function mockValidator(bool $fails) - { - $validator = \Mockery::mock(\Illuminate\Validation\Validator::class); - - $validation = \Mockery::mock(Factory::class); - $validation->shouldReceive('make')->once()->andReturn($validator); - - $validator->shouldReceive('fails')->once()->andReturn($fails); - - Validator::swap($validation); - - return $validator; - } -} - -class User -{ - public function getKey() - { - return 1; - } -} +} \ No newline at end of file diff --git a/tests/ExpoFileDriverTest.php b/tests/ExpoFileDriverTest.php new file mode 100644 index 00000000..0efb2623 --- /dev/null +++ b/tests/ExpoFileDriverTest.php @@ -0,0 +1,132 @@ +expoChannel = new ExpoChannel(new Expo(new ExpoRegistrar(new ExpoFileDriver())), new Dispatcher()); + + $this->expoController = new ExpoController($this->expoChannel); + + // We will fake an authenticated user + Auth::shouldReceive('user')->andReturn(new User()); + } + + public function tearDown() + { + \Mockery::close(); + + parent::tearDown(); + } + + /** @test */ + public function aDeviceCanSubscribeToTheSystem() + { + // We will fake a request with the following data + $data = ['expo_token' => 'ExponentPushToken[fakeToken]']; + $request = $this->mockRequest($data); + $request->shouldReceive('get')->with('expo_token')->andReturn($data['expo_token']); + + $this->mockValidator(false); + + /** @var Request $request */ + $response = $this->expoController->subscribe($request); + $response = json_decode($response->content()); + + // The response should contain a succeeded status + $this->assertEquals('succeeded', $response->status); + // The response should return the registered token + $this->assertEquals($data['expo_token'], $response->expo_token); + } + + /** @test */ + public function subscribeReturnsErrorResponseIfTokenInvalid() + { + // We will fake a request with no data + $request = $this->mockRequest([]); + + $this->mockValidator(true); + + /** @var Request $request */ + $response = $this->expoController->subscribe($request); + + // The response should contain a failed status + $this->assertEquals('failed', json_decode($response->content())->status); + // The response status should be 422 + $this->assertEquals(422, $response->getStatusCode()); + } + + /** @test */ + public function subscribeReturnsErrorResponseIfExceptionIsThrown() + { + // We will fake a request with the following data + $data = ['expo_token' => 'ExponentPushToken[fakeToken]']; + $request = $this->mockRequest($data); + $request->shouldReceive('get')->andReturn($data['expo_token']); + + $this->mockValidator(false); + + $expo = \Mockery::mock(Expo::class); + $expo->shouldReceive('subscribe')->andThrow(\Exception::class); + + /** @var Expo $expo */ + $expoChannel = new ExpoChannel($expo, new Dispatcher()); + + /** @var Request $request */ + $response = (new ExpoController($expoChannel))->subscribe($request); + $response = json_decode($response->content()); + + $this->assertEquals('failed', $response->status); + } + + /** @test */ + public function aDeviceCanUnsubscribeFromTheSystem() + { + // We will subscribe an interest to the server. + $token = 'ExponentPushToken[fakeToken]'; + $interest = $this->expoChannel->interestName(new User()); + $this->expoChannel->expo->subscribe($interest, $token); + + $response = $this->expoController->unsubscribe(); + $response = json_decode($response->content()); + + // The response should contain a deleted property with value true + $this->assertTrue($response->deleted); + } + + /** @test */ + public function unsubscribeReturnsErrorResponseIfExceptionIsThrown() + { + $expo = \Mockery::mock(Expo::class); + $expo->shouldReceive('unsubscribe')->andThrow(\Exception::class); + + /** @var Expo $expo */ + $response = (new ExpoController(new ExpoChannel($expo, new Dispatcher())))->unsubscribe(); + $response = json_decode($response->content()); + + $this->assertEquals('failed', $response->status); + } +} \ No newline at end of file diff --git a/tests/MessageTest.php b/tests/MessageTest.php index a36acc38..058de7f2 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -3,7 +3,6 @@ namespace NotificationChannels\ExpoPushNotifications\Test; use Illuminate\Support\Arr; -use PHPUnit\Framework\TestCase; use NotificationChannels\ExpoPushNotifications\ExpoMessage; class MessageTest extends TestCase diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 00000000..6ea2336c --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,107 @@ +set('database.default', 'sqlite'); + + $app['config']->set('database.connections.sqlite', [ + 'driver' => 'sqlite', + 'database' => $this->getTempDirectory().'/database.sqlite', + 'prefix' => '', + ]); + + $app['config']->set('auth.providers.users.model', User::class); + } + + protected function setUpDatabase() + { + $this->resetDatabase(); + + $this->createExponentPushNotificationInterestsTable(); + } + + protected function resetDatabase() + { + file_put_contents($this->getTempDirectory().'/database.sqlite', null); + } + + protected function createExponentPushNotificationInterestsTable() + { + include_once '__DIR__'.'/../migrations/create_exponent_push_notification_interests_table.php.stub'; + + (new \CreateExponentPushNotificationInterestsTable())->up(); + } + + public function getTempDirectory(): string + { + return __DIR__.'/temp'; + } + + public function markTestAsPassed() + { + $this->assertTrue(true); + } + + /** + * Mocks a request for the ExpoController. + * + * @param $data + * + * @return \Mockery\MockInterface + */ + public function mockRequest($data) + { + $request = \Mockery::mock(Request::class); + $request->shouldReceive('all')->andReturn($data); + + return $request; + } + + /** + * @param bool $fails + * + * @return \Mockery\MockInterface + */ + public function mockValidator(bool $fails) + { + $validator = \Mockery::mock(\Illuminate\Validation\Validator::class); + + $validation = \Mockery::mock(Factory::class); + $validation->shouldReceive('make')->once()->andReturn($validator); + + $validator->shouldReceive('fails')->once()->andReturn($fails); + + Validator::swap($validation); + + return $validator; + } +} + +class User +{ + public function getKey() + { + return 1; + } +} \ No newline at end of file diff --git a/tests/temp/.gitignore b/tests/temp/.gitignore new file mode 100644 index 00000000..c96a04f0 --- /dev/null +++ b/tests/temp/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file From 40cae8a2e7d02073ac9de1e8d96df457012da8cc Mon Sep 17 00:00:00 2001 From: Patrick Kivits Date: Mon, 3 Sep 2018 07:44:24 +0000 Subject: [PATCH 35/95] Apply fixes from StyleCI --- config/exponent-push-notifications.php | 2 +- src/ExpoChannel.php | 4 ++-- src/ExpoPushNotificationsServiceProvider.php | 4 ++-- src/Http/ExpoController.php | 2 +- src/Models/Interest.php | 2 +- src/Repositories/ExpoDatabaseDriver.php | 2 +- tests/ChannelTest.php | 6 +++--- tests/ExpoDatabaseDriverTest.php | 4 ++-- tests/ExpoFileDriverTest.php | 6 +++--- tests/TestCase.php | 4 ++-- 10 files changed, 18 insertions(+), 18 deletions(-) diff --git a/config/exponent-push-notifications.php b/config/exponent-push-notifications.php index ed2eecc6..88654355 100644 --- a/config/exponent-push-notifications.php +++ b/config/exponent-push-notifications.php @@ -11,4 +11,4 @@ 'table_name' => 'exponent_push_notification_interests', ], ], -]; \ No newline at end of file +]; diff --git a/src/ExpoChannel.php b/src/ExpoChannel.php index 6cd26356..d9e6775b 100644 --- a/src/ExpoChannel.php +++ b/src/ExpoChannel.php @@ -2,11 +2,11 @@ namespace NotificationChannels\ExpoPushNotifications; -use ExponentPhpSDK\Exceptions\ExpoException; use ExponentPhpSDK\Expo; use Illuminate\Events\Dispatcher; -use Illuminate\Notifications\Events\NotificationFailed; use Illuminate\Notifications\Notification; +use ExponentPhpSDK\Exceptions\ExpoException; +use Illuminate\Notifications\Events\NotificationFailed; use NotificationChannels\ExpoPushNotifications\Exceptions\CouldNotSendNotification; class ExpoChannel diff --git a/src/ExpoPushNotificationsServiceProvider.php b/src/ExpoPushNotificationsServiceProvider.php index fbe9fa03..c67d9e4e 100644 --- a/src/ExpoPushNotificationsServiceProvider.php +++ b/src/ExpoPushNotificationsServiceProvider.php @@ -5,8 +5,8 @@ use ExponentPhpSDK\Expo; use ExponentPhpSDK\ExpoRegistrar; use ExponentPhpSDK\ExpoRepository; -use ExponentPhpSDK\Repositories\ExpoFileDriver; use Illuminate\Support\ServiceProvider; +use ExponentPhpSDK\Repositories\ExpoFileDriver; use NotificationChannels\ExpoPushNotifications\Repositories\ExpoDatabaseDriver; class ExpoPushNotificationsServiceProvider extends ServiceProvider @@ -62,4 +62,4 @@ public function getInterestsDriver() return new ExpoFileDriver(); } } -} \ No newline at end of file +} diff --git a/src/Http/ExpoController.php b/src/Http/ExpoController.php index 3838493f..bc229932 100644 --- a/src/Http/ExpoController.php +++ b/src/Http/ExpoController.php @@ -2,8 +2,8 @@ namespace NotificationChannels\ExpoPushNotifications\Http; -use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Http\JsonResponse; use Illuminate\Routing\Controller; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Validator; diff --git a/src/Models/Interest.php b/src/Models/Interest.php index b2add270..a8115faa 100644 --- a/src/Models/Interest.php +++ b/src/Models/Interest.php @@ -37,4 +37,4 @@ public function __construct(array $attributes = []) parent::__construct($attributes); } -} \ No newline at end of file +} diff --git a/src/Repositories/ExpoDatabaseDriver.php b/src/Repositories/ExpoDatabaseDriver.php index c923a31c..2bdf075b 100644 --- a/src/Repositories/ExpoDatabaseDriver.php +++ b/src/Repositories/ExpoDatabaseDriver.php @@ -48,4 +48,4 @@ public function forget(string $key): bool { return Interest::where('key', $key)->delete(); } -} \ No newline at end of file +} diff --git a/tests/ChannelTest.php b/tests/ChannelTest.php index e72f98e6..403aed19 100644 --- a/tests/ChannelTest.php +++ b/tests/ChannelTest.php @@ -2,13 +2,13 @@ namespace NotificationChannels\ExpoPushNotifications\Test; -use ExponentPhpSDK\Exceptions\ExpoException; +use Mockery; use ExponentPhpSDK\Expo; use Illuminate\Events\Dispatcher; -use Illuminate\Notifications\Events\NotificationFailed; use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notification; -use Mockery; +use ExponentPhpSDK\Exceptions\ExpoException; +use Illuminate\Notifications\Events\NotificationFailed; use NotificationChannels\ExpoPushNotifications\ExpoChannel; use NotificationChannels\ExpoPushNotifications\ExpoMessage; diff --git a/tests/ExpoDatabaseDriverTest.php b/tests/ExpoDatabaseDriverTest.php index 9f89d776..baccbb13 100644 --- a/tests/ExpoDatabaseDriverTest.php +++ b/tests/ExpoDatabaseDriverTest.php @@ -3,9 +3,9 @@ namespace NotificationChannels\ExpoPushNotifications\Test; use ExponentPhpSDK\Expo; +use Illuminate\Http\Request; use ExponentPhpSDK\ExpoRegistrar; use Illuminate\Events\Dispatcher; -use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use NotificationChannels\ExpoPushNotifications\ExpoChannel; use NotificationChannels\ExpoPushNotifications\Http\ExpoController; @@ -131,4 +131,4 @@ public function unsubscribeReturnsErrorResponseIfExceptionIsThrown() $this->assertEquals('failed', $response->status); } -} \ No newline at end of file +} diff --git a/tests/ExpoFileDriverTest.php b/tests/ExpoFileDriverTest.php index 0efb2623..533668c1 100644 --- a/tests/ExpoFileDriverTest.php +++ b/tests/ExpoFileDriverTest.php @@ -3,11 +3,11 @@ namespace NotificationChannels\ExpoPushNotifications\Test; use ExponentPhpSDK\Expo; +use Illuminate\Http\Request; use ExponentPhpSDK\ExpoRegistrar; -use ExponentPhpSDK\Repositories\ExpoFileDriver; use Illuminate\Events\Dispatcher; -use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; +use ExponentPhpSDK\Repositories\ExpoFileDriver; use NotificationChannels\ExpoPushNotifications\ExpoChannel; use NotificationChannels\ExpoPushNotifications\Http\ExpoController; @@ -129,4 +129,4 @@ public function unsubscribeReturnsErrorResponseIfExceptionIsThrown() $this->assertEquals('failed', $response->status); } -} \ No newline at end of file +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 6ea2336c..7563924c 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -4,8 +4,8 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Validator; -use NotificationChannels\ExpoPushNotifications\ExpoPushNotificationsServiceProvider; use Orchestra\Testbench\TestCase as OrchestraTestCase; +use NotificationChannels\ExpoPushNotifications\ExpoPushNotificationsServiceProvider; abstract class TestCase extends OrchestraTestCase { @@ -104,4 +104,4 @@ public function getKey() { return 1; } -} \ No newline at end of file +} From 8ba9172b635b402d4c890f9fbd42989f6fad69a7 Mon Sep 17 00:00:00 2001 From: Patrick Kivits Date: Wed, 5 Sep 2018 10:15:26 +0200 Subject: [PATCH 36/95] Update ExpoChannel.php --- src/ExpoChannel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ExpoChannel.php b/src/ExpoChannel.php index d9e6775b..e04ed5a4 100644 --- a/src/ExpoChannel.php +++ b/src/ExpoChannel.php @@ -3,7 +3,7 @@ namespace NotificationChannels\ExpoPushNotifications; use ExponentPhpSDK\Expo; -use Illuminate\Events\Dispatcher; +use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Notifications\Notification; use ExponentPhpSDK\Exceptions\ExpoException; use Illuminate\Notifications\Events\NotificationFailed; From 591fb14618058ab2de0ac22277fb31d62fc1efea Mon Sep 17 00:00:00 2001 From: Patrick Kivits Date: Wed, 5 Sep 2018 08:16:48 +0000 Subject: [PATCH 37/95] Apply fixes from StyleCI --- src/ExpoChannel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ExpoChannel.php b/src/ExpoChannel.php index e04ed5a4..84f81522 100644 --- a/src/ExpoChannel.php +++ b/src/ExpoChannel.php @@ -3,8 +3,8 @@ namespace NotificationChannels\ExpoPushNotifications; use ExponentPhpSDK\Expo; -use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Notifications\Notification; +use Illuminate\Contracts\Events\Dispatcher; use ExponentPhpSDK\Exceptions\ExpoException; use Illuminate\Notifications\Events\NotificationFailed; use NotificationChannels\ExpoPushNotifications\Exceptions\CouldNotSendNotification; From dd3d4e6b86eacf3174838e10df20669e053ec915 Mon Sep 17 00:00:00 2001 From: Patrick Kivits Date: Wed, 5 Sep 2018 15:43:31 +0200 Subject: [PATCH 38/95] Allow for unsubscribing per token instead of purging all tokens per user when token is provided. --- src/Http/ExpoController.php | 19 +++++++++++++++++-- src/Repositories/ExpoDatabaseDriver.php | 24 ++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/Http/ExpoController.php b/src/Http/ExpoController.php index bc229932..198b02cb 100644 --- a/src/Http/ExpoController.php +++ b/src/Http/ExpoController.php @@ -74,12 +74,27 @@ public function subscribe(Request $request) * * @return \Illuminate\Http\JsonResponse */ - public function unsubscribe() + public function unsubscribe(Request $request) { $interest = $this->expoChannel->interestName(Auth::user()); + $validator = Validator::make($request->all(), [ + 'expo_token' => 'sometimes|string', + ]); + + if ($validator->fails()) { + return JsonResponse::create([ + 'status' => 'failed', + 'error' => [ + 'message' => 'Expo Token is invalid', + ], + ], 422); + } + + $token = $request->get('expo_token') ?: null; + try { - $deleted = $this->expoChannel->expo->unsubscribe($interest); + $deleted = $this->expoChannel->expo->unsubscribe($interest, $token); } catch (\Exception $e) { return JsonResponse::create([ 'status' => 'failed', diff --git a/src/Repositories/ExpoDatabaseDriver.php b/src/Repositories/ExpoDatabaseDriver.php index 2bdf075b..78b77166 100644 --- a/src/Repositories/ExpoDatabaseDriver.php +++ b/src/Repositories/ExpoDatabaseDriver.php @@ -41,11 +41,31 @@ public function retrieve(string $key) * Removes an Expo token with a given identifier. * * @param string $key + * @param string $value * * @return bool */ - public function forget(string $key): bool + public function forget(string $key, string $value = null): bool { - return Interest::where('key', $key)->delete(); + // Delete interest + $delete = Interest::where('key', $key); + + if(isset($value)) + { + // Only delete this token + $delete->where('value', $value); + } + + $delete->delete(); + + // Check if our interest exist + $count = Interest::where('key', $key); + + if(isset($value)) + { + $count->where('value', $value); + } + + return $count->count() === 0; } } From 898b3c8f6b234324a7a475c0896863c09cf69f8d Mon Sep 17 00:00:00 2001 From: Patrick Kivits Date: Wed, 5 Sep 2018 13:44:48 +0000 Subject: [PATCH 39/95] Apply fixes from StyleCI --- src/Repositories/ExpoDatabaseDriver.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Repositories/ExpoDatabaseDriver.php b/src/Repositories/ExpoDatabaseDriver.php index 78b77166..a2c38d17 100644 --- a/src/Repositories/ExpoDatabaseDriver.php +++ b/src/Repositories/ExpoDatabaseDriver.php @@ -50,8 +50,7 @@ public function forget(string $key, string $value = null): bool // Delete interest $delete = Interest::where('key', $key); - if(isset($value)) - { + if (isset($value)) { // Only delete this token $delete->where('value', $value); } @@ -61,8 +60,7 @@ public function forget(string $key, string $value = null): bool // Check if our interest exist $count = Interest::where('key', $key); - if(isset($value)) - { + if (isset($value)) { $count->where('value', $value); } From e0f98e083bbbdbcae9e40a0c620cc0ea6aa348f3 Mon Sep 17 00:00:00 2001 From: Patrick Kivits Date: Wed, 5 Sep 2018 16:25:12 +0200 Subject: [PATCH 40/95] Fix tests with request parameter in request and added tests for single token unsubscription --- tests/ExpoDatabaseDriverTest.php | 35 ++++++++++++++++++++++++++++++-- tests/ExpoFileDriverTest.php | 35 ++++++++++++++++++++++++++++++-- 2 files changed, 66 insertions(+), 4 deletions(-) diff --git a/tests/ExpoDatabaseDriverTest.php b/tests/ExpoDatabaseDriverTest.php index baccbb13..35ad3f1a 100644 --- a/tests/ExpoDatabaseDriverTest.php +++ b/tests/ExpoDatabaseDriverTest.php @@ -104,15 +104,43 @@ public function subscribeReturnsErrorResponseIfExceptionIsThrown() $this->assertEquals('failed', $response->status); } + /** @test */ + public function aDeviceCanUnsubscribeSingleTokenFromTheSystem() + { + // We will fake a request with the following data + $data = ['expo_token' => 'ExponentPushToken[fakeToken]']; + $request = $this->mockRequest($data); + $request->shouldReceive('get')->with('expo_token')->andReturn($data['expo_token']); + + $this->mockValidator(false); + + // We will subscribe an interest to the server. + $token = 'ExponentPushToken[fakeToken]'; + $interest = $this->expoChannel->interestName(new User()); + $this->expoChannel->expo->subscribe($interest, $token); + + $response = $this->expoController->unsubscribe($request); + $response = json_decode($response->content()); + + // The response should contain a deleted property with value true + $this->assertTrue($response->deleted); + } + /** @test */ public function aDeviceCanUnsubscribeFromTheSystem() { + // We will fake a request with the following data + $request = $this->mockRequest([]); + $request->shouldReceive('get')->with('expo_token')->andReturn([]); + + $this->mockValidator(false); + // We will subscribe an interest to the server. $token = 'ExponentPushToken[fakeToken]'; $interest = $this->expoChannel->interestName(new User()); $this->expoChannel->expo->subscribe($interest, $token); - $response = $this->expoController->unsubscribe(); + $response = $this->expoController->unsubscribe($request); $response = json_decode($response->content()); // The response should contain a deleted property with value true @@ -122,11 +150,14 @@ public function aDeviceCanUnsubscribeFromTheSystem() /** @test */ public function unsubscribeReturnsErrorResponseIfExceptionIsThrown() { + $request = $this->mockRequest([]); + $request->shouldReceive('get')->with('expo_token')->andReturn([]); + $expo = \Mockery::mock(Expo::class); $expo->shouldReceive('unsubscribe')->andThrow(\Exception::class); /** @var Expo $expo */ - $response = (new ExpoController(new ExpoChannel($expo, new Dispatcher())))->unsubscribe(); + $response = (new ExpoController(new ExpoChannel($expo, new Dispatcher())))->unsubscribe($request); $response = json_decode($response->content()); $this->assertEquals('failed', $response->status); diff --git a/tests/ExpoFileDriverTest.php b/tests/ExpoFileDriverTest.php index 533668c1..8cc97cd3 100644 --- a/tests/ExpoFileDriverTest.php +++ b/tests/ExpoFileDriverTest.php @@ -102,15 +102,43 @@ public function subscribeReturnsErrorResponseIfExceptionIsThrown() $this->assertEquals('failed', $response->status); } + /** @test */ + public function aDeviceCanUnsubscribeSingleTokenFromTheSystem() + { + // We will fake a request with the following data + $data = ['expo_token' => 'ExponentPushToken[fakeToken]']; + $request = $this->mockRequest($data); + $request->shouldReceive('get')->with('expo_token')->andReturn($data['expo_token']); + + $this->mockValidator(false); + + // We will subscribe an interest to the server. + $token = 'ExponentPushToken[fakeToken]'; + $interest = $this->expoChannel->interestName(new User()); + $this->expoChannel->expo->subscribe($interest, $token); + + $response = $this->expoController->unsubscribe($request); + $response = json_decode($response->content()); + + // The response should contain a deleted property with value true + $this->assertTrue($response->deleted); + } + /** @test */ public function aDeviceCanUnsubscribeFromTheSystem() { + // We will fake a request with the following data + $request = $this->mockRequest([]); + $request->shouldReceive('get')->with('expo_token')->andReturn([]); + + $this->mockValidator(false); + // We will subscribe an interest to the server. $token = 'ExponentPushToken[fakeToken]'; $interest = $this->expoChannel->interestName(new User()); $this->expoChannel->expo->subscribe($interest, $token); - $response = $this->expoController->unsubscribe(); + $response = $this->expoController->unsubscribe($request); $response = json_decode($response->content()); // The response should contain a deleted property with value true @@ -120,11 +148,14 @@ public function aDeviceCanUnsubscribeFromTheSystem() /** @test */ public function unsubscribeReturnsErrorResponseIfExceptionIsThrown() { + $request = $this->mockRequest([]); + $request->shouldReceive('get')->with('expo_token')->andReturn([]); + $expo = \Mockery::mock(Expo::class); $expo->shouldReceive('unsubscribe')->andThrow(\Exception::class); /** @var Expo $expo */ - $response = (new ExpoController(new ExpoChannel($expo, new Dispatcher())))->unsubscribe(); + $response = (new ExpoController(new ExpoChannel($expo, new Dispatcher())))->unsubscribe($request); $response = json_decode($response->content()); $this->assertEquals('failed', $response->status); From 4e826541e5f5fafa0a7d4ffe26f2062ddeedd171 Mon Sep 17 00:00:00 2001 From: Alymosul Date: Thu, 27 Sep 2018 11:40:35 +0200 Subject: [PATCH 41/95] Add support to Laravel 5.7 and require expo-sdk v1.1.* --- composer.json | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index 4dad50df..75777b31 100644 --- a/composer.json +++ b/composer.json @@ -12,21 +12,21 @@ ], "require": { "php": ">=7.0", - "alymosul/exponent-server-sdk-php": "1.0.*", - "illuminate/config": "5.3.* || 5.4.* || 5.5.* || 5.6.*", - "illuminate/notifications": "5.3.* || 5.4.* || 5.5.* || 5.6.*", - "illuminate/support": "5.3.* || 5.4.* || 5.5.* || 5.6.*", - "illuminate/events": "5.3.* || 5.4.* || 5.5.* || 5.6.*", - "illuminate/queue": "5.3.* || 5.4.* || 5.5.* || 5.6.*", - "illuminate/http": "5.3.* || 5.4.* || 5.5.* || 5.6.*", - "illuminate/routing": "5.3.* || 5.4.* || 5.5.* || 5.6.*", - "illuminate/validation": "5.3.* || 5.4.* || 5.5.* || 5.6.*", - "illuminate/auth": "5.3.* || 5.4.* || 5.5.* || 5.6.*" + "alymosul/exponent-server-sdk-php": "1.1.*", + "illuminate/config": "5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.*", + "illuminate/notifications": "5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.*", + "illuminate/support": "5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.*", + "illuminate/events": "5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.*", + "illuminate/queue": "5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.*", + "illuminate/http": "5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.*", + "illuminate/routing": "5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.*", + "illuminate/validation": "5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.*", + "illuminate/auth": "5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.*" }, "require-dev": { "mockery/mockery": "^0.9.5", - "phpunit/phpunit": "^6.2|^7.0", - "orchestra/testbench": "~3.5.0|~3.6.0" + "phpunit/phpunit": "~5.4||~5.7||~6.0||^7.0", + "orchestra/testbench": "~3.3||~3.4||~3.5||~3.6||~3.7" }, "autoload": { "psr-4": { From e5c0757ed33d766e1dc4bd34b9e198bbba6dc292 Mon Sep 17 00:00:00 2001 From: Alymosul Date: Thu, 27 Sep 2018 11:50:19 +0200 Subject: [PATCH 42/95] Wording... --- config/exponent-push-notifications.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/config/exponent-push-notifications.php b/config/exponent-push-notifications.php index 88654355..9b5805ca 100644 --- a/config/exponent-push-notifications.php +++ b/config/exponent-push-notifications.php @@ -1,10 +1,13 @@ [ - /* - * Supported: "file", "database" - */ 'driver' => env('EXPONENT_PUSH_NOTIFICATION_INTERESTS_STORAGE_DRIVER', 'file'), 'database' => [ From 12072103ca16a0300c35d864affad04d6456e311 Mon Sep 17 00:00:00 2001 From: Alymosul Date: Thu, 27 Sep 2018 12:04:21 +0200 Subject: [PATCH 43/95] Fix Risky tests. --- tests/ChannelTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/ChannelTest.php b/tests/ChannelTest.php index 403aed19..26ff75ed 100644 --- a/tests/ChannelTest.php +++ b/tests/ChannelTest.php @@ -41,6 +41,8 @@ class ChannelTest extends TestCase public function setUp() { + parent::setUp(); + $this->expo = Mockery::mock(Expo::class); $this->events = Mockery::mock(Dispatcher::class); @@ -54,9 +56,9 @@ public function setUp() public function tearDown() { - Mockery::close(); - parent::tearDown(); + + Mockery::close(); } /** @test */ From 220ae380dd4ff8ea712086d75b8cb7b3fee49f32 Mon Sep 17 00:00:00 2001 From: Alymosul Date: Thu, 27 Sep 2018 12:26:10 +0200 Subject: [PATCH 44/95] [Refactoring] Publish the migration files only if we are using the database driver. --- ...push_notification_interests_table.php.stub | 3 +- src/ExpoPushNotificationsServiceProvider.php | 55 ++++++++++++++----- 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/migrations/create_exponent_push_notification_interests_table.php.stub b/migrations/create_exponent_push_notification_interests_table.php.stub index 691d7793..b705c1d4 100644 --- a/migrations/create_exponent_push_notification_interests_table.php.stub +++ b/migrations/create_exponent_push_notification_interests_table.php.stub @@ -12,10 +12,9 @@ class CreateExponentPushNotificationInterestsTable extends Migration public function up() { Schema::create(config('exponent-push-notifications.interests.database.table_name'), function (Blueprint $table) { - $table->string('key'); + $table->string('key')->index(); $table->string('value'); - $table->index('key'); $table->unique(['key','value']); }); } diff --git a/src/ExpoPushNotificationsServiceProvider.php b/src/ExpoPushNotificationsServiceProvider.php index c67d9e4e..9a6979d8 100644 --- a/src/ExpoPushNotificationsServiceProvider.php +++ b/src/ExpoPushNotificationsServiceProvider.php @@ -13,34 +13,30 @@ class ExpoPushNotificationsServiceProvider extends ServiceProvider { /** * Bootstrap the application services. + * + * @return void */ public function boot() { - $this->publishes([ - __DIR__.'/../config/exponent-push-notifications.php' => config_path('exponent-push-notifications.php'), - ], 'config'); + $this->setupConfig(); - $this->mergeConfigFrom(__DIR__.'/../config/exponent-push-notifications.php', 'exponent-push-notifications'); + $repository = $this->getInterestsDriver(); - if (! class_exists('CreateExponentPushNotificationInterestsTable')) { - $timestamp = date('Y_m_d_His', time()); - $this->publishes([ - __DIR__.'/../migrations/create_exponent_push_notification_interests_table.php.stub' => database_path("/migrations/{$timestamp}_create_exponent_push_notification_interests_table.php"), - ], 'migrations'); - } + $this->shouldPublishMigrations($repository); $this->app->when(ExpoChannel::class) ->needs(Expo::class) - ->give(function () { - return new Expo(new ExpoRegistrar($this->getInterestsDriver())); + ->give(function () use ($repository) { + return new Expo(new ExpoRegistrar($repository)); }); - //Load routes $this->loadRoutesFrom(__DIR__.'/Http/routes.php'); } /** * Register the application services. + * + * @return void */ public function register() { @@ -48,6 +44,8 @@ public function register() } /** + * Gets the Expo repository driver based on config. + * * @return ExpoRepository */ public function getInterestsDriver() @@ -62,4 +60,35 @@ public function getInterestsDriver() return new ExpoFileDriver(); } } + + /** + * Publishes the configuration files for the package. + * + * @return void + */ + protected function setupConfig() + { + $this->publishes([ + __DIR__ . '/../config/exponent-push-notifications.php' => config_path('exponent-push-notifications.php'), + ], 'config'); + + $this->mergeConfigFrom(__DIR__.'/../config/exponent-push-notifications.php', 'exponent-push-notifications'); + } + + /** + * Publishes the migration files needed in the package. + * + * @param ExpoRepository $repository + * + * @return void + */ + private function shouldPublishMigrations(ExpoRepository $repository) + { + if ($repository instanceof ExpoDatabaseDriver && !class_exists('CreateExponentPushNotificationInterestsTable')) { + $timestamp = date('Y_m_d_His', time()); + $this->publishes([ + __DIR__ . '/../migrations/create_exponent_push_notification_interests_table.php.stub' => database_path("/migrations/{$timestamp}_create_exponent_push_notification_interests_table.php"), + ], 'migrations'); + } + } } From bd8ec7efe0dc1a0aadb3e85b2dda94dfa17635e6 Mon Sep 17 00:00:00 2001 From: Alymosul Date: Thu, 27 Sep 2018 13:08:50 +0200 Subject: [PATCH 45/95] Fix DocBlocks --- src/Http/ExpoController.php | 4 +++- src/Models/Interest.php | 10 +++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Http/ExpoController.php b/src/Http/ExpoController.php index 198b02cb..e42cb873 100644 --- a/src/Http/ExpoController.php +++ b/src/Http/ExpoController.php @@ -72,7 +72,9 @@ public function subscribe(Request $request) /** * Handles removing subscription endpoint for the authenticated interest. * - * @return \Illuminate\Http\JsonResponse + * @param Request $request + * + * @return JsonResponse */ public function unsubscribe(Request $request) { diff --git a/src/Models/Interest.php b/src/Models/Interest.php index a8115faa..aebf6986 100644 --- a/src/Models/Interest.php +++ b/src/Models/Interest.php @@ -4,17 +4,18 @@ use Illuminate\Database\Eloquent\Model; -/** - * Class Interest. - */ class Interest extends Model { /** + * The associated table. + * * @var string */ protected $table; /** + * The attributes that are mass assignable. + * * @var array */ protected $fillable = [ @@ -23,12 +24,15 @@ class Interest extends Model ]; /** + * Indicates if the model should be timestamped. + * * @var bool */ public $timestamps = false; /** * Interest constructor. + * * @param array $attributes */ public function __construct(array $attributes = []) From 38db4182b219890b4b121e000e6885c1470ba14a Mon Sep 17 00:00:00 2001 From: Alymosul Date: Thu, 27 Sep 2018 13:16:12 +0200 Subject: [PATCH 46/95] [Refactoring] Compare directly with the output of the delete() instead of querying the database again. --- src/Repositories/ExpoDatabaseDriver.php | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/Repositories/ExpoDatabaseDriver.php b/src/Repositories/ExpoDatabaseDriver.php index a2c38d17..752ce5dd 100644 --- a/src/Repositories/ExpoDatabaseDriver.php +++ b/src/Repositories/ExpoDatabaseDriver.php @@ -47,23 +47,12 @@ public function retrieve(string $key) */ public function forget(string $key, string $value = null): bool { - // Delete interest - $delete = Interest::where('key', $key); + $query = Interest::where('key', $key); - if (isset($value)) { - // Only delete this token - $delete->where('value', $value); + if ($value) { + $query->where('value', $value); } - $delete->delete(); - - // Check if our interest exist - $count = Interest::where('key', $key); - - if (isset($value)) { - $count->where('value', $value); - } - - return $count->count() === 0; + return $query->delete() > 0; } } From 62cd23af219f42269ae49ca8fc34079df8e0f152 Mon Sep 17 00:00:00 2001 From: Alymosul Date: Thu, 27 Sep 2018 14:48:57 +0200 Subject: [PATCH 47/95] [Refactoring] Removed ExpoDatabaseDriver and replaced it with a dataprovider, so that we can keep the ExpoControllerTest. --- ...eDriverTest.php => ExpoControllerTest.php} | 162 ++++++++++++++--- tests/ExpoFileDriverTest.php | 163 ------------------ tests/TestCase.php | 85 ++++----- 3 files changed, 172 insertions(+), 238 deletions(-) rename tests/{ExpoDatabaseDriverTest.php => ExpoControllerTest.php} (52%) delete mode 100644 tests/ExpoFileDriverTest.php diff --git a/tests/ExpoDatabaseDriverTest.php b/tests/ExpoControllerTest.php similarity index 52% rename from tests/ExpoDatabaseDriverTest.php rename to tests/ExpoControllerTest.php index 35ad3f1a..56abe6d7 100644 --- a/tests/ExpoDatabaseDriverTest.php +++ b/tests/ExpoControllerTest.php @@ -3,25 +3,39 @@ namespace NotificationChannels\ExpoPushNotifications\Test; use ExponentPhpSDK\Expo; +use ExponentPhpSDK\ExpoRepository; +use Illuminate\Contracts\Validation\Factory; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Validator; use ExponentPhpSDK\ExpoRegistrar; use Illuminate\Events\Dispatcher; use Illuminate\Support\Facades\Auth; +use ExponentPhpSDK\Repositories\ExpoFileDriver; use NotificationChannels\ExpoPushNotifications\ExpoChannel; use NotificationChannels\ExpoPushNotifications\Http\ExpoController; +use NotificationChannels\ExpoPushNotifications\Models\Interest; use NotificationChannels\ExpoPushNotifications\Repositories\ExpoDatabaseDriver; -class ExpoDatabaseDriverTest extends TestCase +class ExpoControllerTest extends TestCase { /** - * @var ExpoChannel + * @var ExpoController */ - protected $expoChannel; + protected $expoController; /** - * @var ExpoController + * Sets up the expo controller with the given expo channel. + * + * @param ExpoRepository $expoRepository + * + * @return array */ - protected $expoController; + protected function setupExpo(ExpoRepository $expoRepository) + { + $expoChannel = new ExpoChannel(new Expo(new ExpoRegistrar($expoRepository)), new Dispatcher); + $expoController = new ExpoController($expoChannel); + return [$expoController, $expoChannel]; + } public function setUp() { @@ -29,10 +43,6 @@ public function setUp() $this->setUpDatabase(); - $this->expoChannel = new ExpoChannel(new Expo(new ExpoRegistrar(new ExpoDatabaseDriver())), new Dispatcher()); - - $this->expoController = new ExpoController($this->expoChannel); - // We will fake an authenticated user Auth::shouldReceive('user')->andReturn(new User()); } @@ -44,9 +54,29 @@ public function tearDown() parent::tearDown(); } - /** @test */ - public function aDeviceCanSubscribeToTheSystem() + /** + * Data provider to help test the expo controller with the different repositories + * + * @return array + */ + public function availableRepositories() + { + return [ + [new ExpoDatabaseDriver], + [new ExpoFileDriver] + ]; + } + + /** @test + * + * @param $expoRepository + * + * @dataProvider availableRepositories + */ + public function aDeviceCanSubscribeToTheSystem($expoRepository) { + list($expoController, $expoChannel) = $this->setupExpo($expoRepository); + // We will fake a request with the following data $data = ['expo_token' => 'ExponentPushToken[fakeToken]']; $request = $this->mockRequest($data); @@ -55,25 +85,39 @@ public function aDeviceCanSubscribeToTheSystem() $this->mockValidator(false); /** @var Request $request */ - $response = $this->expoController->subscribe($request); + $response = $expoController->subscribe($request); $response = json_decode($response->content()); // The response should contain a succeeded status $this->assertEquals('succeeded', $response->status); // The response should return the registered token $this->assertEquals($data['expo_token'], $response->expo_token); + + if ($expoRepository instanceof ExpoDatabaseDriver) { + $this->assertDatabaseHas(config('exponent-push-notifications.interests.database.table_name'), [ + 'key' => 'NotificationChannels.ExpoPushNotifications.Test.User.'.(new User)->getKey(), + 'value' => $data['expo_token'] + ]); + } } - /** @test */ - public function subscribeReturnsErrorResponseIfTokenInvalid() + /** @test + * + * @param $expoRepository + * + * @dataProvider availableRepositories + */ + public function subscribeReturnsErrorResponseIfTokenInvalid($expoRepository) { + list($expoController, $expoChannel) = $this->setupExpo($expoRepository); + // We will fake a request with no data $request = $this->mockRequest([]); $this->mockValidator(true); /** @var Request $request */ - $response = $this->expoController->subscribe($request); + $response = $expoController->subscribe($request); // The response should contain a failed status $this->assertEquals('failed', json_decode($response->content())->status); @@ -104,9 +148,17 @@ public function subscribeReturnsErrorResponseIfExceptionIsThrown() $this->assertEquals('failed', $response->status); } - /** @test */ - public function aDeviceCanUnsubscribeSingleTokenFromTheSystem() + /** @test + * + * + * @dataProvider availableRepositories + * + * @param $expoRepository + */ + public function aDeviceCanUnsubscribeSingleTokenFromTheSystem($expoRepository) { + list($expoController, $expoChannel) = $this->setupExpo($expoRepository); + // We will fake a request with the following data $data = ['expo_token' => 'ExponentPushToken[fakeToken]']; $request = $this->mockRequest($data); @@ -116,19 +168,33 @@ public function aDeviceCanUnsubscribeSingleTokenFromTheSystem() // We will subscribe an interest to the server. $token = 'ExponentPushToken[fakeToken]'; - $interest = $this->expoChannel->interestName(new User()); - $this->expoChannel->expo->subscribe($interest, $token); + $interest = $expoChannel->interestName(new User()); + $expoChannel->expo->subscribe($interest, $token); - $response = $this->expoController->unsubscribe($request); + $response = $expoController->unsubscribe($request); $response = json_decode($response->content()); // The response should contain a deleted property with value true $this->assertTrue($response->deleted); + + if ($expoRepository instanceof ExpoDatabaseDriver) { + $this->assertDatabaseMissing(config('exponent-push-notifications.interests.database.table_name'), [ + 'key' => 'NotificationChannels.ExpoPushNotifications.Test.User.'.(new User)->getKey(), + 'value' => $data['expo_token'] + ]); + } } - /** @test */ - public function aDeviceCanUnsubscribeFromTheSystem() + /** @test + * + * @param $expoRepository + * + * @dataProvider availableRepositories + */ + public function aDeviceCanUnsubscribeFromTheSystem($expoRepository) { + list($expoController, $expoChannel) = $this->setupExpo($expoRepository); + // We will fake a request with the following data $request = $this->mockRequest([]); $request->shouldReceive('get')->with('expo_token')->andReturn([]); @@ -137,14 +203,18 @@ public function aDeviceCanUnsubscribeFromTheSystem() // We will subscribe an interest to the server. $token = 'ExponentPushToken[fakeToken]'; - $interest = $this->expoChannel->interestName(new User()); - $this->expoChannel->expo->subscribe($interest, $token); + $interest = $expoChannel->interestName(new User()); + $expoChannel->expo->subscribe($interest, $token); - $response = $this->expoController->unsubscribe($request); + $response = $expoController->unsubscribe($request); $response = json_decode($response->content()); // The response should contain a deleted property with value true $this->assertTrue($response->deleted); + + if ($expoRepository instanceof ExpoDatabaseDriver) { + $this->assertEquals(0, Interest::count()); + } } /** @test */ @@ -162,4 +232,46 @@ public function unsubscribeReturnsErrorResponseIfExceptionIsThrown() $this->assertEquals('failed', $response->status); } + /** + * Mocks a request for the ExpoController. + * + * @param $data + * + * @return \Mockery\MockInterface + */ + public function mockRequest($data) + { + $request = \Mockery::mock(Request::class); + $request->shouldReceive('all')->andReturn($data); + + return $request; + } + + /** + * @param bool $fails + * + * @return \Mockery\MockInterface + */ + public function mockValidator(bool $fails) + { + $validator = \Mockery::mock(\Illuminate\Validation\Validator::class); + + $validation = \Mockery::mock(Factory::class); + + $validation->shouldReceive('make')->once()->andReturn($validator); + + $validator->shouldReceive('fails')->once()->andReturn($fails); + + Validator::swap($validation); + + return $validator; + } +} + +class User +{ + public function getKey() + { + return 1; + } } diff --git a/tests/ExpoFileDriverTest.php b/tests/ExpoFileDriverTest.php deleted file mode 100644 index 8cc97cd3..00000000 --- a/tests/ExpoFileDriverTest.php +++ /dev/null @@ -1,163 +0,0 @@ -expoChannel = new ExpoChannel(new Expo(new ExpoRegistrar(new ExpoFileDriver())), new Dispatcher()); - - $this->expoController = new ExpoController($this->expoChannel); - - // We will fake an authenticated user - Auth::shouldReceive('user')->andReturn(new User()); - } - - public function tearDown() - { - \Mockery::close(); - - parent::tearDown(); - } - - /** @test */ - public function aDeviceCanSubscribeToTheSystem() - { - // We will fake a request with the following data - $data = ['expo_token' => 'ExponentPushToken[fakeToken]']; - $request = $this->mockRequest($data); - $request->shouldReceive('get')->with('expo_token')->andReturn($data['expo_token']); - - $this->mockValidator(false); - - /** @var Request $request */ - $response = $this->expoController->subscribe($request); - $response = json_decode($response->content()); - - // The response should contain a succeeded status - $this->assertEquals('succeeded', $response->status); - // The response should return the registered token - $this->assertEquals($data['expo_token'], $response->expo_token); - } - - /** @test */ - public function subscribeReturnsErrorResponseIfTokenInvalid() - { - // We will fake a request with no data - $request = $this->mockRequest([]); - - $this->mockValidator(true); - - /** @var Request $request */ - $response = $this->expoController->subscribe($request); - - // The response should contain a failed status - $this->assertEquals('failed', json_decode($response->content())->status); - // The response status should be 422 - $this->assertEquals(422, $response->getStatusCode()); - } - - /** @test */ - public function subscribeReturnsErrorResponseIfExceptionIsThrown() - { - // We will fake a request with the following data - $data = ['expo_token' => 'ExponentPushToken[fakeToken]']; - $request = $this->mockRequest($data); - $request->shouldReceive('get')->andReturn($data['expo_token']); - - $this->mockValidator(false); - - $expo = \Mockery::mock(Expo::class); - $expo->shouldReceive('subscribe')->andThrow(\Exception::class); - - /** @var Expo $expo */ - $expoChannel = new ExpoChannel($expo, new Dispatcher()); - - /** @var Request $request */ - $response = (new ExpoController($expoChannel))->subscribe($request); - $response = json_decode($response->content()); - - $this->assertEquals('failed', $response->status); - } - - /** @test */ - public function aDeviceCanUnsubscribeSingleTokenFromTheSystem() - { - // We will fake a request with the following data - $data = ['expo_token' => 'ExponentPushToken[fakeToken]']; - $request = $this->mockRequest($data); - $request->shouldReceive('get')->with('expo_token')->andReturn($data['expo_token']); - - $this->mockValidator(false); - - // We will subscribe an interest to the server. - $token = 'ExponentPushToken[fakeToken]'; - $interest = $this->expoChannel->interestName(new User()); - $this->expoChannel->expo->subscribe($interest, $token); - - $response = $this->expoController->unsubscribe($request); - $response = json_decode($response->content()); - - // The response should contain a deleted property with value true - $this->assertTrue($response->deleted); - } - - /** @test */ - public function aDeviceCanUnsubscribeFromTheSystem() - { - // We will fake a request with the following data - $request = $this->mockRequest([]); - $request->shouldReceive('get')->with('expo_token')->andReturn([]); - - $this->mockValidator(false); - - // We will subscribe an interest to the server. - $token = 'ExponentPushToken[fakeToken]'; - $interest = $this->expoChannel->interestName(new User()); - $this->expoChannel->expo->subscribe($interest, $token); - - $response = $this->expoController->unsubscribe($request); - $response = json_decode($response->content()); - - // The response should contain a deleted property with value true - $this->assertTrue($response->deleted); - } - - /** @test */ - public function unsubscribeReturnsErrorResponseIfExceptionIsThrown() - { - $request = $this->mockRequest([]); - $request->shouldReceive('get')->with('expo_token')->andReturn([]); - - $expo = \Mockery::mock(Expo::class); - $expo->shouldReceive('unsubscribe')->andThrow(\Exception::class); - - /** @var Expo $expo */ - $response = (new ExpoController(new ExpoChannel($expo, new Dispatcher())))->unsubscribe($request); - $response = json_decode($response->content()); - - $this->assertEquals('failed', $response->status); - } -} diff --git a/tests/TestCase.php b/tests/TestCase.php index 7563924c..cea0cb7d 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,8 +2,6 @@ namespace NotificationChannels\ExpoPushNotifications\Test; -use Illuminate\Http\Request; -use Illuminate\Support\Facades\Validator; use Orchestra\Testbench\TestCase as OrchestraTestCase; use NotificationChannels\ExpoPushNotifications\ExpoPushNotificationsServiceProvider; @@ -14,6 +12,13 @@ public function setUp() parent::setUp(); } + /** + * Get package providers. + * + * @param \Illuminate\Foundation\Application $app + * + * @return array + */ protected function getPackageProviders($app) { return [ @@ -21,19 +26,31 @@ protected function getPackageProviders($app) ]; } + /** + * Define environment setup. + * + * @param \Illuminate\Foundation\Application $app + * + * @return void + */ public function getEnvironmentSetUp($app) { $app['config']->set('database.default', 'sqlite'); $app['config']->set('database.connections.sqlite', [ 'driver' => 'sqlite', - 'database' => $this->getTempDirectory().'/database.sqlite', + 'database' => $this->getDatabaseDirectory().'/database.sqlite', 'prefix' => '', ]); $app['config']->set('auth.providers.users.model', User::class); } + /** + * Sets up the database. + * + * @return void + */ protected function setUpDatabase() { $this->resetDatabase(); @@ -41,67 +58,35 @@ protected function setUpDatabase() $this->createExponentPushNotificationInterestsTable(); } + /** + * Drops the database. + * + * @return void + */ protected function resetDatabase() { - file_put_contents($this->getTempDirectory().'/database.sqlite', null); - } - - protected function createExponentPushNotificationInterestsTable() - { - include_once '__DIR__'.'/../migrations/create_exponent_push_notification_interests_table.php.stub'; - - (new \CreateExponentPushNotificationInterestsTable())->up(); - } - - public function getTempDirectory(): string - { - return __DIR__.'/temp'; - } - - public function markTestAsPassed() - { - $this->assertTrue(true); + file_put_contents(__DIR__.'/temp'.'/database.sqlite', null); } /** - * Mocks a request for the ExpoController. - * - * @param $data + * Creates the interests table. * - * @return \Mockery\MockInterface + * @return void */ - public function mockRequest($data) + protected function createExponentPushNotificationInterestsTable() { - $request = \Mockery::mock(Request::class); - $request->shouldReceive('all')->andReturn($data); + include_once '__DIR__'.'/../migrations/create_exponent_push_notification_interests_table.php.stub'; - return $request; + (new \CreateExponentPushNotificationInterestsTable())->up(); } /** - * @param bool $fails + * Gets the directory path for the testing database. * - * @return \Mockery\MockInterface + * @return string */ - public function mockValidator(bool $fails) + public function getDatabaseDirectory(): string { - $validator = \Mockery::mock(\Illuminate\Validation\Validator::class); - - $validation = \Mockery::mock(Factory::class); - $validation->shouldReceive('make')->once()->andReturn($validator); - - $validator->shouldReceive('fails')->once()->andReturn($fails); - - Validator::swap($validation); - - return $validator; - } -} - -class User -{ - public function getKey() - { - return 1; + return __DIR__.'/temp'; } } From 0a3bc4acb32bece41d21f131c946c1c8f362ede9 Mon Sep 17 00:00:00 2001 From: Aly Suleiman Date: Thu, 27 Sep 2018 12:52:00 +0000 Subject: [PATCH 48/95] Apply fixes from StyleCI --- src/ExpoPushNotificationsServiceProvider.php | 6 +++--- tests/ExpoControllerTest.php | 18 ++++++++++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/ExpoPushNotificationsServiceProvider.php b/src/ExpoPushNotificationsServiceProvider.php index 9a6979d8..3b6ffe7f 100644 --- a/src/ExpoPushNotificationsServiceProvider.php +++ b/src/ExpoPushNotificationsServiceProvider.php @@ -69,7 +69,7 @@ public function getInterestsDriver() protected function setupConfig() { $this->publishes([ - __DIR__ . '/../config/exponent-push-notifications.php' => config_path('exponent-push-notifications.php'), + __DIR__.'/../config/exponent-push-notifications.php' => config_path('exponent-push-notifications.php'), ], 'config'); $this->mergeConfigFrom(__DIR__.'/../config/exponent-push-notifications.php', 'exponent-push-notifications'); @@ -84,10 +84,10 @@ protected function setupConfig() */ private function shouldPublishMigrations(ExpoRepository $repository) { - if ($repository instanceof ExpoDatabaseDriver && !class_exists('CreateExponentPushNotificationInterestsTable')) { + if ($repository instanceof ExpoDatabaseDriver && ! class_exists('CreateExponentPushNotificationInterestsTable')) { $timestamp = date('Y_m_d_His', time()); $this->publishes([ - __DIR__ . '/../migrations/create_exponent_push_notification_interests_table.php.stub' => database_path("/migrations/{$timestamp}_create_exponent_push_notification_interests_table.php"), + __DIR__.'/../migrations/create_exponent_push_notification_interests_table.php.stub' => database_path("/migrations/{$timestamp}_create_exponent_push_notification_interests_table.php"), ], 'migrations'); } } diff --git a/tests/ExpoControllerTest.php b/tests/ExpoControllerTest.php index 56abe6d7..4832d37b 100644 --- a/tests/ExpoControllerTest.php +++ b/tests/ExpoControllerTest.php @@ -3,17 +3,17 @@ namespace NotificationChannels\ExpoPushNotifications\Test; use ExponentPhpSDK\Expo; -use ExponentPhpSDK\ExpoRepository; -use Illuminate\Contracts\Validation\Factory; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Validator; use ExponentPhpSDK\ExpoRegistrar; use Illuminate\Events\Dispatcher; +use ExponentPhpSDK\ExpoRepository; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Validator; +use Illuminate\Contracts\Validation\Factory; use ExponentPhpSDK\Repositories\ExpoFileDriver; use NotificationChannels\ExpoPushNotifications\ExpoChannel; -use NotificationChannels\ExpoPushNotifications\Http\ExpoController; use NotificationChannels\ExpoPushNotifications\Models\Interest; +use NotificationChannels\ExpoPushNotifications\Http\ExpoController; use NotificationChannels\ExpoPushNotifications\Repositories\ExpoDatabaseDriver; class ExpoControllerTest extends TestCase @@ -34,6 +34,7 @@ protected function setupExpo(ExpoRepository $expoRepository) { $expoChannel = new ExpoChannel(new Expo(new ExpoRegistrar($expoRepository)), new Dispatcher); $expoController = new ExpoController($expoChannel); + return [$expoController, $expoChannel]; } @@ -55,7 +56,7 @@ public function tearDown() } /** - * Data provider to help test the expo controller with the different repositories + * Data provider to help test the expo controller with the different repositories. * * @return array */ @@ -63,7 +64,7 @@ public function availableRepositories() { return [ [new ExpoDatabaseDriver], - [new ExpoFileDriver] + [new ExpoFileDriver], ]; } @@ -96,7 +97,7 @@ public function aDeviceCanSubscribeToTheSystem($expoRepository) if ($expoRepository instanceof ExpoDatabaseDriver) { $this->assertDatabaseHas(config('exponent-push-notifications.interests.database.table_name'), [ 'key' => 'NotificationChannels.ExpoPushNotifications.Test.User.'.(new User)->getKey(), - 'value' => $data['expo_token'] + 'value' => $data['expo_token'], ]); } } @@ -180,7 +181,7 @@ public function aDeviceCanUnsubscribeSingleTokenFromTheSystem($expoRepository) if ($expoRepository instanceof ExpoDatabaseDriver) { $this->assertDatabaseMissing(config('exponent-push-notifications.interests.database.table_name'), [ 'key' => 'NotificationChannels.ExpoPushNotifications.Test.User.'.(new User)->getKey(), - 'value' => $data['expo_token'] + 'value' => $data['expo_token'], ]); } } @@ -232,6 +233,7 @@ public function unsubscribeReturnsErrorResponseIfExceptionIsThrown() $this->assertEquals('failed', $response->status); } + /** * Mocks a request for the ExpoController. * From 0b10eca0f6294e3814de5503b672cf2ad52c1b1a Mon Sep 17 00:00:00 2001 From: Danijel Dedic Date: Thu, 13 Dec 2018 09:39:05 +0100 Subject: [PATCH 49/95] Add Message title property --- src/ExpoMessage.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/ExpoMessage.php b/src/ExpoMessage.php index 3a7bc8bd..f94f249d 100644 --- a/src/ExpoMessage.php +++ b/src/ExpoMessage.php @@ -6,6 +6,13 @@ class ExpoMessage { + /** + * The message title. + * + * @var string + */ + protected $title; + /** * The message body. * @@ -71,6 +78,20 @@ public function __construct(string $body = '') $this->body = $body; } + /** + * Set the message title. + * + * @param string $value + * + * @return $this + */ + public function title(string $value) + { + $this->title = $value; + + return $this; + } + /** * Set the message body. * @@ -185,6 +206,7 @@ public function setJsonData($data) public function toArray() { return [ + 'title' => $this- 'body' => $this->body, 'sound' => $this->sound, 'badge' => $this->badge, From f3cdeb99b2a83179d0d33f72ca17c7eef6222521 Mon Sep 17 00:00:00 2001 From: Danijel Dedic Date: Thu, 13 Dec 2018 09:40:31 +0100 Subject: [PATCH 50/95] Bump --- src/ExpoMessage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ExpoMessage.php b/src/ExpoMessage.php index f94f249d..113bc692 100644 --- a/src/ExpoMessage.php +++ b/src/ExpoMessage.php @@ -7,7 +7,7 @@ class ExpoMessage { /** - * The message title. + * The message title * * @var string */ From 1a6ef9b1f73ac45eed73966ee7c40d49d04cb663 Mon Sep 17 00:00:00 2001 From: Danijel Dedic Date: Thu, 13 Dec 2018 09:42:13 +0100 Subject: [PATCH 51/95] fix typo --- src/ExpoMessage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ExpoMessage.php b/src/ExpoMessage.php index 113bc692..9e93f63d 100644 --- a/src/ExpoMessage.php +++ b/src/ExpoMessage.php @@ -206,7 +206,7 @@ public function setJsonData($data) public function toArray() { return [ - 'title' => $this- + 'title' => $this->title, 'body' => $this->body, 'sound' => $this->sound, 'badge' => $this->badge, From 86a7aec33276afe89310ae769c39406c9b0c0dd9 Mon Sep 17 00:00:00 2001 From: Danijel Dedic Date: Thu, 13 Dec 2018 09:43:44 +0100 Subject: [PATCH 52/95] style ci --- src/ExpoMessage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ExpoMessage.php b/src/ExpoMessage.php index 9e93f63d..d00c2060 100644 --- a/src/ExpoMessage.php +++ b/src/ExpoMessage.php @@ -7,7 +7,7 @@ class ExpoMessage { /** - * The message title + * The message title. * * @var string */ From 11472027e2499a46de02013ab6de6b2e5cfcf8ae Mon Sep 17 00:00:00 2001 From: Iulian Date: Tue, 15 Jan 2019 15:40:18 +0200 Subject: [PATCH 53/95] Update README.md One step is missing --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d9da973b..cc8692fc 100644 --- a/README.md +++ b/README.md @@ -36,8 +36,12 @@ If you are using Laravel 5.5 or higher this package will automatically register ... NotificationChannels\ExpoPushNotifications\ExpoPushNotificationsServiceProvider::class, ], -``` +``` +Before publish exponent notification migration you must add in .env file: +```bash +EXPONENT_PUSH_NOTIFICATION_INTERESTS_STORAGE_DRIVER=database +``` You can publish the migration with: ```bash php artisan vendor:publish --provider="NotificationChannels\ExpoPushNotifications\ExpoPushNotificationsServiceProvider" --tag="migrations" From 88e93d09a10d7b0b6f66d102e4e94423ea333d1a Mon Sep 17 00:00:00 2001 From: Jean-Luc Nguyen Date: Fri, 19 Apr 2019 17:29:34 +0200 Subject: [PATCH 54/95] Added support for Laravel 5.8 --- composer.json | 18 +++++++++--------- src/ExpoChannel.php | 2 +- tests/ChannelTest.php | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index 75777b31..3413e418 100644 --- a/composer.json +++ b/composer.json @@ -13,15 +13,15 @@ "require": { "php": ">=7.0", "alymosul/exponent-server-sdk-php": "1.1.*", - "illuminate/config": "5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.*", - "illuminate/notifications": "5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.*", - "illuminate/support": "5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.*", - "illuminate/events": "5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.*", - "illuminate/queue": "5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.*", - "illuminate/http": "5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.*", - "illuminate/routing": "5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.*", - "illuminate/validation": "5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.*", - "illuminate/auth": "5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.*" + "illuminate/config": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*", + "illuminate/notifications": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*", + "illuminate/support": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*", + "illuminate/events": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*", + "illuminate/queue": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*", + "illuminate/http": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*", + "illuminate/routing": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*", + "illuminate/validation": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*", + "illuminate/auth": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*" }, "require-dev": { "mockery/mockery": "^0.9.5", diff --git a/src/ExpoChannel.php b/src/ExpoChannel.php index 84f81522..4e37ff40 100644 --- a/src/ExpoChannel.php +++ b/src/ExpoChannel.php @@ -55,7 +55,7 @@ public function send($notifiable, Notification $notification) true ); } catch (ExpoException $e) { - $this->events->fire( + $this->events->dispatch( new NotificationFailed($notifiable, $notification, 'expo-push-notifications', $e->getMessage()) ); } diff --git a/tests/ChannelTest.php b/tests/ChannelTest.php index 26ff75ed..730782bd 100644 --- a/tests/ChannelTest.php +++ b/tests/ChannelTest.php @@ -82,7 +82,7 @@ public function itFiresFailureEventOnFailure() $this->expo->shouldReceive('notify')->with('interest_name', $data, true)->andThrow(ExpoException::class, ''); - $this->events->shouldReceive('fire')->with(Mockery::type(NotificationFailed::class)); + $this->events->shouldReceive('dispatch')->with(Mockery::type(NotificationFailed::class)); $this->channel->send($this->notifiable, $this->notification); } From 1d96aa927f41c94efbfe66858f492f66471baeb8 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 28 Jun 2019 20:46:11 +0100 Subject: [PATCH 55/95] Updated README.md - included ExpoMessage()->title('') in example because receive an error without it - included jsonData() in example - added missing Available Message Methods --- README.md | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index cc8692fc..01fe953f 100644 --- a/README.md +++ b/README.md @@ -11,19 +11,19 @@ ## Contents -- [Installation](#installation) -- [Usage](#usage) - - [Available Message methods](#available-message-methods) -- [Changelog](#changelog) -- [Testing](#testing) -- [Security](#security) -- [Contributing](#contributing) -- [Credits](#credits) -- [License](#license) - +- [Installation](#installation) +- [Usage](#usage) - [Available Message methods](#available-message-methods) +- [Changelog](#changelog) +- [Testing](#testing) +- [Security](#security) +- [Contributing](#contributing) +- [Credits](#credits) +- [License](#license) ## Installation + You can install the package via composer: + ```bash composer require alymosul/laravel-exponent-push-notifications ``` @@ -38,11 +38,15 @@ If you are using Laravel 5.5 or higher this package will automatically register ], ``` -Before publish exponent notification migration you must add in .env file: + +Before publish exponent notification migration you must add in .env file: + ```bash EXPONENT_PUSH_NOTIFICATION_INTERESTS_STORAGE_DRIVER=database ``` + You can publish the migration with: + ```bash php artisan vendor:publish --provider="NotificationChannels\ExpoPushNotifications\ExpoPushNotificationsServiceProvider" --tag="migrations" ``` @@ -54,6 +58,7 @@ php artisan migrate ``` You can optionally publish the config file with: + ```bash php artisan vendor:publish --provider="NotificationChannels\ExpoPushNotifications\ExpoPushNotificationsServiceProvider" --tag="config" ``` @@ -77,7 +82,7 @@ return [ ## Usage -``` php +```php use NotificationChannels\ExpoPushNotifications\ExpoChannel; use NotificationChannels\ExpoPushNotifications\ExpoMessage; use Illuminate\Notifications\Notification; @@ -94,6 +99,7 @@ class AccountApproved extends Notification return ExpoMessage::create() ->badge(1) ->enableSound() + ->title("Congratulations!") ->body("Your {$notifiable->service} account was approved!"); } } @@ -102,11 +108,13 @@ class AccountApproved extends Notification ### Available Message methods A list of all available options -- `body('')`: Accepts a string value for the body. -- `enableSound()`: Enables the notification sound. -- `disableSound()`: Mutes the notification sound. -- `badge(1)`: Accepts an integer value for the badge. -- `ttl(60)`: Accepts an integer value for the time to live. + +- `title('')`: Accepts a string value for the title. +- `body('')`: Accepts a string value for the body. +- `enableSound()`: Enables the notification sound. +- `disableSound()`: Mutes the notification sound. +- `badge(1)`: Accepts an integer value for the badge. +- `ttl(60)`: Accepts an integer value for the time to live. -`jsonData('')`: Accepts a json string or an array for additional. -`channelID('')`: Accepts a string to set the channelId of the notification for Android devices. ### Managing Recipients @@ -122,7 +130,7 @@ Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recen ## Testing -``` bash +```bash $ composer test ``` @@ -136,8 +144,8 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details. ## Credits -- [Aly Suleiman](https://github.com/Alymosul) -- [All Contributors](../../contributors) +- [Aly Suleiman](https://github.com/Alymosul) +- [All Contributors](../../contributors) ## License From 58f5d3361e099969366e8f4c94ecbf224ea0c569 Mon Sep 17 00:00:00 2001 From: Peter Elmered Date: Fri, 6 Sep 2019 16:33:05 +0200 Subject: [PATCH 56/95] Added support for Laravel 6.0 --- composer.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 3413e418..c08bb0c5 100644 --- a/composer.json +++ b/composer.json @@ -13,15 +13,15 @@ "require": { "php": ">=7.0", "alymosul/exponent-server-sdk-php": "1.1.*", - "illuminate/config": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*", - "illuminate/notifications": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*", - "illuminate/support": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*", - "illuminate/events": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*", - "illuminate/queue": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*", - "illuminate/http": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*", - "illuminate/routing": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*", - "illuminate/validation": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*", - "illuminate/auth": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*" + "illuminate/config": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*" || 6.0.*", + "illuminate/notifications": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*" || 6.0.*", + "illuminate/support": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*" || 6.0.*", + "illuminate/events": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*" || 6.0.*", + "illuminate/queue": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*" || 6.0.*", + "illuminate/http": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*" || 6.0.*", + "illuminate/routing": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*" || 6.0.*", + "illuminate/validation": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*" || 6.0.*", + "illuminate/auth": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*" || 6.0.*" }, "require-dev": { "mockery/mockery": "^0.9.5", From 2d614ea05a3daa400472e71316bdd9b2d8fc6911 Mon Sep 17 00:00:00 2001 From: Peter Elmered Date: Fri, 6 Sep 2019 16:35:57 +0200 Subject: [PATCH 57/95] Fix JSON formatting --- composer.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index c08bb0c5..64d760ab 100644 --- a/composer.json +++ b/composer.json @@ -13,15 +13,15 @@ "require": { "php": ">=7.0", "alymosul/exponent-server-sdk-php": "1.1.*", - "illuminate/config": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*" || 6.0.*", - "illuminate/notifications": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*" || 6.0.*", - "illuminate/support": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*" || 6.0.*", - "illuminate/events": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*" || 6.0.*", - "illuminate/queue": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*" || 6.0.*", - "illuminate/http": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*" || 6.0.*", - "illuminate/routing": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*" || 6.0.*", - "illuminate/validation": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*" || 6.0.*", - "illuminate/auth": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*" || 6.0.*" + "illuminate/config": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.* || 6.0.*", + "illuminate/notifications": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.* || 6.0.*", + "illuminate/support": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.* || 6.0.*", + "illuminate/events": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.* || 6.0.*", + "illuminate/queue": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.* || 6.0.*", + "illuminate/http": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.* || 6.0.*", + "illuminate/routing": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.* || 6.0.*", + "illuminate/validation": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.* || 6.0.*", + "illuminate/auth": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.* || 6.0.*" }, "require-dev": { "mockery/mockery": "^0.9.5", From a077f8b3b6795a77f080eb0617813ac624e3de98 Mon Sep 17 00:00:00 2001 From: Peter Elmered Date: Fri, 6 Sep 2019 17:17:05 +0200 Subject: [PATCH 58/95] Fix Laravel version constraints --- composer.json | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 64d760ab..c2c6241f 100644 --- a/composer.json +++ b/composer.json @@ -13,15 +13,7 @@ "require": { "php": ">=7.0", "alymosul/exponent-server-sdk-php": "1.1.*", - "illuminate/config": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.* || 6.0.*", - "illuminate/notifications": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.* || 6.0.*", - "illuminate/support": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.* || 6.0.*", - "illuminate/events": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.* || 6.0.*", - "illuminate/queue": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.* || 6.0.*", - "illuminate/http": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.* || 6.0.*", - "illuminate/routing": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.* || 6.0.*", - "illuminate/validation": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.* || 6.0.*", - "illuminate/auth": "5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.* || 6.0.*" + "laravel/framework": "^5.6 || ^6.0", }, "require-dev": { "mockery/mockery": "^0.9.5", From 2db8c14041bad608fc0eec7c7c0584cc672f14ed Mon Sep 17 00:00:00 2001 From: Peter Elmered Date: Wed, 11 Sep 2019 13:54:55 +0200 Subject: [PATCH 59/95] Fix composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c2c6241f..62d6cc61 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "require": { "php": ">=7.0", "alymosul/exponent-server-sdk-php": "1.1.*", - "laravel/framework": "^5.6 || ^6.0", + "laravel/framework": "^5.6 || ^6.0" }, "require-dev": { "mockery/mockery": "^0.9.5", From 6dc610d796f785d42eafc5bdd105854d59c3655b Mon Sep 17 00:00:00 2001 From: Peter Elmered Date: Mon, 16 Sep 2019 12:06:45 +0200 Subject: [PATCH 60/95] Replace PHP 7.0 and 7.1 with 7.2 and 7.3 in Travis test matrix --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index b0116bfc..21f10d33 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: php php: - - 7.0 - - 7.1 + - 7.2 + - 7.3 before_script: - travis_retry composer self-update From a7e3d610d3604bc4dfcc27818805f7cc98545d34 Mon Sep 17 00:00:00 2001 From: Peter Elmered Date: Mon, 16 Sep 2019 12:45:33 +0200 Subject: [PATCH 61/95] Use locally installed phpunit --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 21f10d33..8c61e12f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ before_script: - travis_retry composer update --no-interaction --prefer-source script: - - phpunit --coverage-text --coverage-clover=coverage.clover + - vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover after_script: - wget https://scrutinizer-ci.com/ocular.phar From 8af7de9342d7b97bf838077cc41adc2fa01fdc16 Mon Sep 17 00:00:00 2001 From: Peter Elmered Date: Mon, 16 Sep 2019 12:50:16 +0200 Subject: [PATCH 62/95] Require PHP 7.1.3 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 62d6cc61..2f3aa0ff 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "php": ">=7.0", + "php": "^7.1.3", "alymosul/exponent-server-sdk-php": "1.1.*", "laravel/framework": "^5.6 || ^6.0" }, From 6655d44c8ac38dbe12bcce0de189707c65086f42 Mon Sep 17 00:00:00 2001 From: Aly Suleiman Date: Wed, 18 Sep 2019 15:51:42 +0000 Subject: [PATCH 63/95] Apply fixes from StyleCI --- tests/ExpoControllerTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/ExpoControllerTest.php b/tests/ExpoControllerTest.php index 4832d37b..02aaa7d1 100644 --- a/tests/ExpoControllerTest.php +++ b/tests/ExpoControllerTest.php @@ -76,7 +76,7 @@ public function availableRepositories() */ public function aDeviceCanSubscribeToTheSystem($expoRepository) { - list($expoController, $expoChannel) = $this->setupExpo($expoRepository); + [$expoController, $expoChannel] = $this->setupExpo($expoRepository); // We will fake a request with the following data $data = ['expo_token' => 'ExponentPushToken[fakeToken]']; @@ -110,7 +110,7 @@ public function aDeviceCanSubscribeToTheSystem($expoRepository) */ public function subscribeReturnsErrorResponseIfTokenInvalid($expoRepository) { - list($expoController, $expoChannel) = $this->setupExpo($expoRepository); + [$expoController, $expoChannel] = $this->setupExpo($expoRepository); // We will fake a request with no data $request = $this->mockRequest([]); @@ -158,7 +158,7 @@ public function subscribeReturnsErrorResponseIfExceptionIsThrown() */ public function aDeviceCanUnsubscribeSingleTokenFromTheSystem($expoRepository) { - list($expoController, $expoChannel) = $this->setupExpo($expoRepository); + [$expoController, $expoChannel] = $this->setupExpo($expoRepository); // We will fake a request with the following data $data = ['expo_token' => 'ExponentPushToken[fakeToken]']; @@ -194,7 +194,7 @@ public function aDeviceCanUnsubscribeSingleTokenFromTheSystem($expoRepository) */ public function aDeviceCanUnsubscribeFromTheSystem($expoRepository) { - list($expoController, $expoChannel) = $this->setupExpo($expoRepository); + [$expoController, $expoChannel] = $this->setupExpo($expoRepository); // We will fake a request with the following data $request = $this->mockRequest([]); From ddcff604fe05c0f92030df95b6bf55c5ef3cf175 Mon Sep 17 00:00:00 2001 From: Aly Suleiman Date: Fri, 20 Sep 2019 10:32:53 +0200 Subject: [PATCH 64/95] Update README.md Co-Authored-By: atymic <50683531+atymic@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cc8692fc..6cd04d4a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Exponent push notifications channel for Laravel 5 +# Exponent push notifications channel for Laravel [![Latest Version on Packagist](https://img.shields.io/packagist/v/alymosul/laravel-exponent-push-notifications.svg?style=flat-square)](https://packagist.org/packages/alymosul/laravel-exponent-push-notifications) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) From 2579fea52145611c90d51901b48d6411902adf15 Mon Sep 17 00:00:00 2001 From: Aly Suleiman Date: Fri, 20 Sep 2019 10:35:15 +0200 Subject: [PATCH 65/95] Update composer.json Co-Authored-By: atymic <50683531+atymic@users.noreply.github.com> --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2f3aa0ff..f16bb86c 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "require-dev": { "mockery/mockery": "^0.9.5", "phpunit/phpunit": "~5.4||~5.7||~6.0||^7.0", - "orchestra/testbench": "~3.3||~3.4||~3.5||~3.6||~3.7" + "orchestra/testbench": "~3.3||~4.0" }, "autoload": { "psr-4": { From c5e7cd2ee5fa5e42f65eb83af311d5e2af283470 Mon Sep 17 00:00:00 2001 From: Marcos Date: Thu, 28 Nov 2019 17:41:14 -0300 Subject: [PATCH 66/95] Make channelId property optional --- src/ExpoMessage.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/ExpoMessage.php b/src/ExpoMessage.php index d00c2060..5cafe367 100644 --- a/src/ExpoMessage.php +++ b/src/ExpoMessage.php @@ -47,7 +47,7 @@ class ExpoMessage * * @var string */ - protected $channelId = 'Default'; + protected $channelId = ''; /** * The json data attached to the message. @@ -205,14 +205,17 @@ public function setJsonData($data) */ public function toArray() { - return [ + $message = [ 'title' => $this->title, 'body' => $this->body, 'sound' => $this->sound, 'badge' => $this->badge, 'ttl' => $this->ttl, - 'channelId' => $this->channelId, - 'data' => $this->jsonData, + 'data' => $this->jsonData ]; + if (!empty($this->channelId)) { + $message['channelId'] = $this->channelId; + } + return $message; } } From f2a809560c8ad56d0975a380a62268f89818e6fb Mon Sep 17 00:00:00 2001 From: Marcos Date: Fri, 29 Nov 2019 11:54:48 -0300 Subject: [PATCH 67/95] Fix style --- src/ExpoMessage.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ExpoMessage.php b/src/ExpoMessage.php index 5cafe367..feaebb79 100644 --- a/src/ExpoMessage.php +++ b/src/ExpoMessage.php @@ -211,11 +211,12 @@ public function toArray() 'sound' => $this->sound, 'badge' => $this->badge, 'ttl' => $this->ttl, - 'data' => $this->jsonData + 'data' => $this->jsonData, ]; - if (!empty($this->channelId)) { + if (! empty($this->channelId)) { $message['channelId'] = $this->channelId; } + return $message; } } From 3fd130ef8809e14b243ca2cd05ce663545c6a300 Mon Sep 17 00:00:00 2001 From: jonny Date: Thu, 2 Jan 2020 18:40:49 +0000 Subject: [PATCH 68/95] line break for jsonData and channelID examples --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 01fe953f..60f48130 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,9 @@ A list of all available options - `enableSound()`: Enables the notification sound. - `disableSound()`: Mutes the notification sound. - `badge(1)`: Accepts an integer value for the badge. -- `ttl(60)`: Accepts an integer value for the time to live. -`jsonData('')`: Accepts a json string or an array for additional. -`channelID('')`: Accepts a string to set the channelId of the notification for Android devices. +- `ttl(60)`: Accepts an integer value for the time to live. +- `jsonData('')`: Accepts a json string or an array for additional. +- `channelID('')`: Accepts a string to set the channelId of the notification for Android devices. ### Managing Recipients From a54a982c4ba4f06ce3e71cd4c414f5b9eaec01b9 Mon Sep 17 00:00:00 2001 From: Aly Suleiman Date: Tue, 14 Jan 2020 09:22:33 +0000 Subject: [PATCH 69/95] Apply fixes from StyleCI --- src/ExpoChannel.php | 4 ++-- src/ExpoPushNotificationsServiceProvider.php | 2 +- src/Http/ExpoController.php | 2 +- tests/ChannelTest.php | 6 +++--- tests/ExpoControllerTest.php | 10 +++++----- tests/TestCase.php | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/ExpoChannel.php b/src/ExpoChannel.php index 4e37ff40..47c655e4 100644 --- a/src/ExpoChannel.php +++ b/src/ExpoChannel.php @@ -2,11 +2,11 @@ namespace NotificationChannels\ExpoPushNotifications; +use ExponentPhpSDK\Exceptions\ExpoException; use ExponentPhpSDK\Expo; -use Illuminate\Notifications\Notification; use Illuminate\Contracts\Events\Dispatcher; -use ExponentPhpSDK\Exceptions\ExpoException; use Illuminate\Notifications\Events\NotificationFailed; +use Illuminate\Notifications\Notification; use NotificationChannels\ExpoPushNotifications\Exceptions\CouldNotSendNotification; class ExpoChannel diff --git a/src/ExpoPushNotificationsServiceProvider.php b/src/ExpoPushNotificationsServiceProvider.php index 3b6ffe7f..505bbe2a 100644 --- a/src/ExpoPushNotificationsServiceProvider.php +++ b/src/ExpoPushNotificationsServiceProvider.php @@ -5,8 +5,8 @@ use ExponentPhpSDK\Expo; use ExponentPhpSDK\ExpoRegistrar; use ExponentPhpSDK\ExpoRepository; -use Illuminate\Support\ServiceProvider; use ExponentPhpSDK\Repositories\ExpoFileDriver; +use Illuminate\Support\ServiceProvider; use NotificationChannels\ExpoPushNotifications\Repositories\ExpoDatabaseDriver; class ExpoPushNotificationsServiceProvider extends ServiceProvider diff --git a/src/Http/ExpoController.php b/src/Http/ExpoController.php index e42cb873..29ae8c96 100644 --- a/src/Http/ExpoController.php +++ b/src/Http/ExpoController.php @@ -2,8 +2,8 @@ namespace NotificationChannels\ExpoPushNotifications\Http; -use Illuminate\Http\Request; use Illuminate\Http\JsonResponse; +use Illuminate\Http\Request; use Illuminate\Routing\Controller; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Validator; diff --git a/tests/ChannelTest.php b/tests/ChannelTest.php index 730782bd..b115d9b9 100644 --- a/tests/ChannelTest.php +++ b/tests/ChannelTest.php @@ -2,13 +2,13 @@ namespace NotificationChannels\ExpoPushNotifications\Test; -use Mockery; +use ExponentPhpSDK\Exceptions\ExpoException; use ExponentPhpSDK\Expo; use Illuminate\Events\Dispatcher; +use Illuminate\Notifications\Events\NotificationFailed; use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notification; -use ExponentPhpSDK\Exceptions\ExpoException; -use Illuminate\Notifications\Events\NotificationFailed; +use Mockery; use NotificationChannels\ExpoPushNotifications\ExpoChannel; use NotificationChannels\ExpoPushNotifications\ExpoMessage; diff --git a/tests/ExpoControllerTest.php b/tests/ExpoControllerTest.php index 02aaa7d1..5a9d27af 100644 --- a/tests/ExpoControllerTest.php +++ b/tests/ExpoControllerTest.php @@ -3,17 +3,17 @@ namespace NotificationChannels\ExpoPushNotifications\Test; use ExponentPhpSDK\Expo; -use Illuminate\Http\Request; use ExponentPhpSDK\ExpoRegistrar; -use Illuminate\Events\Dispatcher; use ExponentPhpSDK\ExpoRepository; +use ExponentPhpSDK\Repositories\ExpoFileDriver; +use Illuminate\Contracts\Validation\Factory; +use Illuminate\Events\Dispatcher; +use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Validator; -use Illuminate\Contracts\Validation\Factory; -use ExponentPhpSDK\Repositories\ExpoFileDriver; use NotificationChannels\ExpoPushNotifications\ExpoChannel; -use NotificationChannels\ExpoPushNotifications\Models\Interest; use NotificationChannels\ExpoPushNotifications\Http\ExpoController; +use NotificationChannels\ExpoPushNotifications\Models\Interest; use NotificationChannels\ExpoPushNotifications\Repositories\ExpoDatabaseDriver; class ExpoControllerTest extends TestCase diff --git a/tests/TestCase.php b/tests/TestCase.php index cea0cb7d..3be1b8b7 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,8 +2,8 @@ namespace NotificationChannels\ExpoPushNotifications\Test; -use Orchestra\Testbench\TestCase as OrchestraTestCase; use NotificationChannels\ExpoPushNotifications\ExpoPushNotificationsServiceProvider; +use Orchestra\Testbench\TestCase as OrchestraTestCase; abstract class TestCase extends OrchestraTestCase { From 833ba1205dd55e3e850d32344eb8b5dc42dc6913 Mon Sep 17 00:00:00 2001 From: Enrico Nardo Date: Fri, 13 Mar 2020 12:04:48 +0100 Subject: [PATCH 70/95] Debug option is now configurable. ExpoException during notification can now be thrown. --- config/exponent-push-notifications.php | 2 ++ src/ExpoChannel.php | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/config/exponent-push-notifications.php b/config/exponent-push-notifications.php index 9b5805ca..ae797ae4 100644 --- a/config/exponent-push-notifications.php +++ b/config/exponent-push-notifications.php @@ -7,6 +7,8 @@ */ return [ + 'debug' => env('EXPONENT_PUSH_NOTIFICATION_DEBUG', false), + 'interests' => [ 'driver' => env('EXPONENT_PUSH_NOTIFICATION_INTERESTS_STORAGE_DRIVER', 'file'), diff --git a/src/ExpoChannel.php b/src/ExpoChannel.php index 47c655e4..65861517 100644 --- a/src/ExpoChannel.php +++ b/src/ExpoChannel.php @@ -52,7 +52,7 @@ public function send($notifiable, Notification $notification) $this->expo->notify( $interest, $notification->toExpoPush($notifiable)->toArray(), - true + config('exponent-push-notifications.debug') ); } catch (ExpoException $e) { $this->events->dispatch( From 1c3537e31c31fb49601318f5977c67748f8444fa Mon Sep 17 00:00:00 2001 From: Enrico Nardo Date: Fri, 13 Mar 2020 12:33:03 +0100 Subject: [PATCH 71/95] Composer json update --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f16bb86c..1610b033 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "alymosul/laravel-exponent-push-notifications", + "name": "codificio/laravel-exponent-push-notifications", "description": "Exponent push notifications driver for laravel", "homepage": "https://github.com/alymosul/laravel-exponent-push-notifications", "license": "MIT", From 4497f4101cf64b2a8e408a4b2d1b47f5283a5352 Mon Sep 17 00:00:00 2001 From: Hirbod Date: Fri, 20 Mar 2020 15:16:06 +0100 Subject: [PATCH 72/95] Update composer.json add laravel 7 support --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f16bb86c..494889cb 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "require": { "php": "^7.1.3", "alymosul/exponent-server-sdk-php": "1.1.*", - "laravel/framework": "^5.6 || ^6.0" + "laravel/framework": "^5.6 | ^6.0 | ^7.0" }, "require-dev": { "mockery/mockery": "^0.9.5", From ef173c24fb725c03063e505da098e1914ed43813 Mon Sep 17 00:00:00 2001 From: Enrico Nardo Date: Mon, 23 Mar 2020 09:33:48 +0100 Subject: [PATCH 73/95] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1610b033..f16bb86c 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "codificio/laravel-exponent-push-notifications", + "name": "alymosul/laravel-exponent-push-notifications", "description": "Exponent push notifications driver for laravel", "homepage": "https://github.com/alymosul/laravel-exponent-push-notifications", "license": "MIT", From 69f0527d039305c138e46038dcef1772f3ac788c Mon Sep 17 00:00:00 2001 From: Samuel Visscher Date: Mon, 6 Jul 2020 14:34:13 +0200 Subject: [PATCH 74/95] Allow events to be configurable through config --- src/Models/Interest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Models/Interest.php b/src/Models/Interest.php index aebf6986..468a1116 100644 --- a/src/Models/Interest.php +++ b/src/Models/Interest.php @@ -13,6 +13,13 @@ class Interest extends Model */ protected $table; + /** + * The event map for the model. + * + * @var array + */ + protected $dispatchesEvents; + /** * The attributes that are mass assignable. * @@ -37,6 +44,8 @@ class Interest extends Model */ public function __construct(array $attributes = []) { + $this->dispatchesEvents = config('exponent-push-notifications.interests.database.events'); + $this->table = config('exponent-push-notifications.interests.database.table_name'); parent::__construct($attributes); From d5a89432ac913d3a2b40e40d460afa7dc3b76dd0 Mon Sep 17 00:00:00 2001 From: Samuel Visscher Date: Mon, 6 Jul 2020 14:37:56 +0200 Subject: [PATCH 75/95] Add documentation --- README.md | 2 ++ config/exponent-push-notifications.php | 2 ++ 2 files changed, 4 insertions(+) diff --git a/README.md b/README.md index 83e0696e..279be3e7 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,8 @@ return [ 'driver' => env('EXPONENT_PUSH_NOTIFICATION_INTERESTS_STORAGE_DRIVER', 'file'), 'database' => [ + 'events' => [], + 'table_name' => 'exponent_push_notification_interests', ], ] diff --git a/config/exponent-push-notifications.php b/config/exponent-push-notifications.php index 9b5805ca..01d9f0d5 100644 --- a/config/exponent-push-notifications.php +++ b/config/exponent-push-notifications.php @@ -11,6 +11,8 @@ 'driver' => env('EXPONENT_PUSH_NOTIFICATION_INTERESTS_STORAGE_DRIVER', 'file'), 'database' => [ + 'events' => [], + 'table_name' => 'exponent_push_notification_interests', ], ], From 35df5510db2509d8a373ed49d488d59c72911af0 Mon Sep 17 00:00:00 2001 From: Enrico Nardo Date: Wed, 8 Jul 2020 09:08:32 +0200 Subject: [PATCH 76/95] Exponent debug is now true by default --- config/exponent-push-notifications.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/exponent-push-notifications.php b/config/exponent-push-notifications.php index ae797ae4..79151532 100644 --- a/config/exponent-push-notifications.php +++ b/config/exponent-push-notifications.php @@ -7,7 +7,7 @@ */ return [ - 'debug' => env('EXPONENT_PUSH_NOTIFICATION_DEBUG', false), + 'debug' => env('EXPONENT_PUSH_NOTIFICATION_DEBUG', true), 'interests' => [ 'driver' => env('EXPONENT_PUSH_NOTIFICATION_INTERESTS_STORAGE_DRIVER', 'file'), From 3941afbf2e70e9a2a95db890c16a0cd46f74fdd7 Mon Sep 17 00:00:00 2001 From: Mauricio Guariero Dias Date: Tue, 8 Sep 2020 15:27:15 -0400 Subject: [PATCH 77/95] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 494889cb..1cc277f9 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "require": { "php": "^7.1.3", "alymosul/exponent-server-sdk-php": "1.1.*", - "laravel/framework": "^5.6 | ^6.0 | ^7.0" + "laravel/framework": "^5.6 | ^6.0 | ^7.0 | ^8.0" }, "require-dev": { "mockery/mockery": "^0.9.5", From edeb1e05fbf7d2510042518c7e3ad19659a2d34a Mon Sep 17 00:00:00 2001 From: abdullah abunada Date: Wed, 9 Sep 2020 18:07:53 +0300 Subject: [PATCH 78/95] [Change]: Allow developers to change the notification priority parameter as Expo documentation --- src/ExpoMessage.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/ExpoMessage.php b/src/ExpoMessage.php index feaebb79..d61b52ca 100644 --- a/src/ExpoMessage.php +++ b/src/ExpoMessage.php @@ -56,6 +56,13 @@ class ExpoMessage */ protected $jsonData = '{}'; + /** + * The priority of notification message for Android devices. + * + * @var string + */ + protected $priority = 'default'; + /** * Create a message with given body. * @@ -198,6 +205,20 @@ public function setJsonData($data) return $this; } + /** + * Set the priority of the notification for Android devices, must be one of [default, normal, high]. + * + * @param string $priority + * + * @return $this + */ + public function setPriority(string $priority) + { + $this->priority = $priority; + + return $this; + } + /** * Get an array representation of the message. * @@ -212,6 +233,7 @@ public function toArray() 'badge' => $this->badge, 'ttl' => $this->ttl, 'data' => $this->jsonData, + 'priority' => $this->priority, ]; if (! empty($this->channelId)) { $message['channelId'] = $this->channelId; From 90110999ad00e5a43cdb69e0a0c70add5f184f70 Mon Sep 17 00:00:00 2001 From: abdullah abunada Date: Wed, 9 Sep 2020 18:14:08 +0300 Subject: [PATCH 79/95] [Change]: Allow to change the notification priority parameter as Expo documentation. --- README.md | 1 + src/ExpoMessage.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 279be3e7..c59154ba 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,7 @@ A list of all available options - `ttl(60)`: Accepts an integer value for the time to live. - `jsonData('')`: Accepts a json string or an array for additional. - `channelID('')`: Accepts a string to set the channelId of the notification for Android devices. +- `priority('default')`: Accepts a string to set the priority of the notification, must be one of [default, normal, high]. ### Managing Recipients diff --git a/src/ExpoMessage.php b/src/ExpoMessage.php index d61b52ca..57519881 100644 --- a/src/ExpoMessage.php +++ b/src/ExpoMessage.php @@ -206,13 +206,13 @@ public function setJsonData($data) } /** - * Set the priority of the notification for Android devices, must be one of [default, normal, high]. + * Set the priority of the notification, must be one of [default, normal, high]. * * @param string $priority * * @return $this */ - public function setPriority(string $priority) + public function priority(string $priority) { $this->priority = $priority; From 9964d75b5400e2e671f707577998fe0883ece894 Mon Sep 17 00:00:00 2001 From: sebastiansson Date: Thu, 17 Dec 2020 11:00:03 +0100 Subject: [PATCH 80/95] Allow middleware to be configurable through config --- config/exponent-push-notifications.php | 5 +++++ src/Http/routes.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/config/exponent-push-notifications.php b/config/exponent-push-notifications.php index 42f6df8a..e4080121 100644 --- a/config/exponent-push-notifications.php +++ b/config/exponent-push-notifications.php @@ -7,6 +7,11 @@ */ return [ + 'middleware' => [ + //'auth:sanctum', <- Only use this middleware if you're using Sanctum + 'auth:api', + 'bindings' + ], 'debug' => env('EXPONENT_PUSH_NOTIFICATION_DEBUG', true), 'interests' => [ diff --git a/src/Http/routes.php b/src/Http/routes.php index 788512ee..4b6602e9 100644 --- a/src/Http/routes.php +++ b/src/Http/routes.php @@ -1,6 +1,6 @@ 'api/exponent/devices', 'middleware' => ['auth:api', 'bindings']], function () { +Route::group(['prefix' => 'api/exponent/devices', 'middleware' => config('middleware') ?? ['auth:api', 'bindings']], function () { Route::post('subscribe', [ 'as' => 'register-interest', 'uses' => 'NotificationChannels\ExpoPushNotifications\Http\ExpoController@subscribe', From e2006726c83d62ea3fe7483ec21736901f309a3e Mon Sep 17 00:00:00 2001 From: sebastiansson Date: Thu, 17 Dec 2020 11:03:28 +0100 Subject: [PATCH 81/95] Only use config if defined Fallback for those who have an old published config --- src/Http/routes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Http/routes.php b/src/Http/routes.php index 4b6602e9..0cff3986 100644 --- a/src/Http/routes.php +++ b/src/Http/routes.php @@ -1,6 +1,6 @@ 'api/exponent/devices', 'middleware' => config('middleware') ?? ['auth:api', 'bindings']], function () { +Route::group(['prefix' => 'api/exponent/devices', 'middleware' => !config('middleware') ?? ['auth:api', 'bindings']], function () { Route::post('subscribe', [ 'as' => 'register-interest', 'uses' => 'NotificationChannels\ExpoPushNotifications\Http\ExpoController@subscribe', From 8e2339618cd8a4459d450a244e3a5d9680f882b6 Mon Sep 17 00:00:00 2001 From: sebastiansson Date: Thu, 17 Dec 2020 11:20:06 +0100 Subject: [PATCH 82/95] Add fix incorrect use of config --- config/exponent-push-notifications.php | 2 +- src/Http/routes.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/exponent-push-notifications.php b/config/exponent-push-notifications.php index e4080121..8c039f0d 100644 --- a/config/exponent-push-notifications.php +++ b/config/exponent-push-notifications.php @@ -8,7 +8,7 @@ return [ 'middleware' => [ - //'auth:sanctum', <- Only use this middleware if you're using Sanctum + //'auth:sanctum', //<- Use only this middleware if you're using Sanctum 'auth:api', 'bindings' ], diff --git a/src/Http/routes.php b/src/Http/routes.php index 0cff3986..c8fdc380 100644 --- a/src/Http/routes.php +++ b/src/Http/routes.php @@ -1,6 +1,6 @@ 'api/exponent/devices', 'middleware' => !config('middleware') ?? ['auth:api', 'bindings']], function () { +Route::group(['prefix' => 'api/exponent/devices', "middleware" => config("exponent-push-notifications")["middleware"]], function () { Route::post('subscribe', [ 'as' => 'register-interest', 'uses' => 'NotificationChannels\ExpoPushNotifications\Http\ExpoController@subscribe', From 87b24d4975f22c537791c2a5bb4388d3102d48f7 Mon Sep 17 00:00:00 2001 From: sebastiansson Date: Wed, 3 Feb 2021 07:58:18 +0100 Subject: [PATCH 83/95] Register middleware in container --- src/ExpoPushNotificationsServiceProvider.php | 4 ++++ src/Http/routes.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ExpoPushNotificationsServiceProvider.php b/src/ExpoPushNotificationsServiceProvider.php index 505bbe2a..984580ce 100644 --- a/src/ExpoPushNotificationsServiceProvider.php +++ b/src/ExpoPushNotificationsServiceProvider.php @@ -30,6 +30,10 @@ public function boot() return new Expo(new ExpoRegistrar($repository)); }); + $router = $this->app->make(Router::class); + // It's also possible to add a middleware group + $router->middlewareGroup('expo.middleware', config("exponent-push-notifications")["middleware"]); + $this->loadRoutesFrom(__DIR__.'/Http/routes.php'); } diff --git a/src/Http/routes.php b/src/Http/routes.php index c8fdc380..16a3a81d 100644 --- a/src/Http/routes.php +++ b/src/Http/routes.php @@ -1,6 +1,6 @@ 'api/exponent/devices', "middleware" => config("exponent-push-notifications")["middleware"]], function () { +Route::group(['prefix' => 'api/exponent/devices', "middleware" => 'expo.middleware'], function () { Route::post('subscribe', [ 'as' => 'register-interest', 'uses' => 'NotificationChannels\ExpoPushNotifications\Http\ExpoController@subscribe', From c3a90dc55bb930c40c8ecb43e4ad06485c6d7a47 Mon Sep 17 00:00:00 2001 From: sebastiansson Date: Wed, 3 Feb 2021 08:01:59 +0100 Subject: [PATCH 84/95] Add inject router --- src/ExpoPushNotificationsServiceProvider.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ExpoPushNotificationsServiceProvider.php b/src/ExpoPushNotificationsServiceProvider.php index 984580ce..093f6eb4 100644 --- a/src/ExpoPushNotificationsServiceProvider.php +++ b/src/ExpoPushNotificationsServiceProvider.php @@ -16,7 +16,7 @@ class ExpoPushNotificationsServiceProvider extends ServiceProvider * * @return void */ - public function boot() + public function boot(\Illuminate\Routing\Router $router) { $this->setupConfig(); @@ -29,9 +29,7 @@ public function boot() ->give(function () use ($repository) { return new Expo(new ExpoRegistrar($repository)); }); - - $router = $this->app->make(Router::class); - // It's also possible to add a middleware group + $router->middlewareGroup('expo.middleware', config("exponent-push-notifications")["middleware"]); $this->loadRoutesFrom(__DIR__.'/Http/routes.php'); From 3a557f07d5f00d417b80fcdfac0f801526f310c1 Mon Sep 17 00:00:00 2001 From: regy42 Date: Mon, 1 Feb 2021 12:33:49 +0100 Subject: [PATCH 85/95] Update to support php 8 --- composer.json | 8 ++++---- tests/ChannelTest.php | 4 ++-- tests/ExpoControllerTest.php | 4 ++-- tests/MessageTest.php | 2 +- tests/TestCase.php | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 1cc277f9..98d8842d 100644 --- a/composer.json +++ b/composer.json @@ -11,14 +11,14 @@ } ], "require": { - "php": "^7.1.3", + "php": "^7.1.3|^8.0", "alymosul/exponent-server-sdk-php": "1.1.*", "laravel/framework": "^5.6 | ^6.0 | ^7.0 | ^8.0" }, "require-dev": { - "mockery/mockery": "^0.9.5", - "phpunit/phpunit": "~5.4||~5.7||~6.0||^7.0", - "orchestra/testbench": "~3.3||~4.0" + "mockery/mockery": "^0.9.5||^1.0", + "phpunit/phpunit": "~5.4||~5.7||~6.0||^7.0||^8.0||^9.0", + "orchestra/testbench": "~3.3||~4.0||^6.0" }, "autoload": { "psr-4": { diff --git a/tests/ChannelTest.php b/tests/ChannelTest.php index b115d9b9..f1901b82 100644 --- a/tests/ChannelTest.php +++ b/tests/ChannelTest.php @@ -39,7 +39,7 @@ class ChannelTest extends TestCase */ protected $notifiable; - public function setUp() + protected function setUp(): void { parent::setUp(); @@ -54,7 +54,7 @@ public function setUp() $this->notifiable = new TestNotifiable; } - public function tearDown() + public function tearDown(): void { parent::tearDown(); diff --git a/tests/ExpoControllerTest.php b/tests/ExpoControllerTest.php index 5a9d27af..97c10642 100644 --- a/tests/ExpoControllerTest.php +++ b/tests/ExpoControllerTest.php @@ -38,7 +38,7 @@ protected function setupExpo(ExpoRepository $expoRepository) return [$expoController, $expoChannel]; } - public function setUp() + protected function setUp(): void { parent::setUp(); @@ -48,7 +48,7 @@ public function setUp() Auth::shouldReceive('user')->andReturn(new User()); } - public function tearDown() + public function tearDown(): void { \Mockery::close(); diff --git a/tests/MessageTest.php b/tests/MessageTest.php index 058de7f2..ba9d1213 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -12,7 +12,7 @@ class MessageTest extends TestCase */ protected $message; - public function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/tests/TestCase.php b/tests/TestCase.php index 3be1b8b7..9d9e35f4 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -7,7 +7,7 @@ abstract class TestCase extends OrchestraTestCase { - public function setUp() + protected function setUp(): void { parent::setUp(); } From 94b30f7d11d4d021bd75ecd8cf11b0d53c7eb85d Mon Sep 17 00:00:00 2001 From: sebastiansson Date: Mon, 8 Feb 2021 07:34:25 +0100 Subject: [PATCH 86/95] Remove router dependency injection --- src/ExpoPushNotificationsServiceProvider.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ExpoPushNotificationsServiceProvider.php b/src/ExpoPushNotificationsServiceProvider.php index 093f6eb4..e32493a8 100644 --- a/src/ExpoPushNotificationsServiceProvider.php +++ b/src/ExpoPushNotificationsServiceProvider.php @@ -16,7 +16,7 @@ class ExpoPushNotificationsServiceProvider extends ServiceProvider * * @return void */ - public function boot(\Illuminate\Routing\Router $router) + public function boot() { $this->setupConfig(); @@ -29,8 +29,9 @@ public function boot(\Illuminate\Routing\Router $router) ->give(function () use ($repository) { return new Expo(new ExpoRegistrar($repository)); }); - - $router->middlewareGroup('expo.middleware', config("exponent-push-notifications")["middleware"]); + + $router = $this->app['router']; + $router->middlewareGroup('expo.middleware', config('exponent-push-notifications')['middleware']); $this->loadRoutesFrom(__DIR__.'/Http/routes.php'); } From 32f5e1e6e8bf98885ee5d2f6090f1b5161054df6 Mon Sep 17 00:00:00 2001 From: sebastiansson Date: Mon, 8 Feb 2021 07:34:58 +0100 Subject: [PATCH 87/95] Change double quotes to single quotes --- src/Http/routes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Http/routes.php b/src/Http/routes.php index 16a3a81d..ef090a0d 100644 --- a/src/Http/routes.php +++ b/src/Http/routes.php @@ -1,6 +1,6 @@ 'api/exponent/devices', "middleware" => 'expo.middleware'], function () { +Route::group(['prefix' => 'api/exponent/devices', 'middleware' => 'expo.middleware'], function () { Route::post('subscribe', [ 'as' => 'register-interest', 'uses' => 'NotificationChannels\ExpoPushNotifications\Http\ExpoController@subscribe', From 4634274b1b8d350831a9daec7295f77c1f35ab2d Mon Sep 17 00:00:00 2001 From: Aly Suleiman Date: Mon, 8 Feb 2021 11:17:08 +0000 Subject: [PATCH 88/95] Apply fixes from StyleCI --- config/exponent-push-notifications.php | 4 ++-- src/ExpoPushNotificationsServiceProvider.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/exponent-push-notifications.php b/config/exponent-push-notifications.php index 8c039f0d..29a3ad13 100644 --- a/config/exponent-push-notifications.php +++ b/config/exponent-push-notifications.php @@ -9,8 +9,8 @@ return [ 'middleware' => [ //'auth:sanctum', //<- Use only this middleware if you're using Sanctum - 'auth:api', - 'bindings' + 'auth:api', + 'bindings', ], 'debug' => env('EXPONENT_PUSH_NOTIFICATION_DEBUG', true), diff --git a/src/ExpoPushNotificationsServiceProvider.php b/src/ExpoPushNotificationsServiceProvider.php index e32493a8..241884b1 100644 --- a/src/ExpoPushNotificationsServiceProvider.php +++ b/src/ExpoPushNotificationsServiceProvider.php @@ -30,7 +30,7 @@ public function boot() return new Expo(new ExpoRegistrar($repository)); }); - $router = $this->app['router']; + $router = $this->app['router']; $router->middlewareGroup('expo.middleware', config('exponent-push-notifications')['middleware']); $this->loadRoutesFrom(__DIR__.'/Http/routes.php'); From bd95e3ae01092ba4304729ca312a9249aa0097b7 Mon Sep 17 00:00:00 2001 From: Jindrich Regal Date: Thu, 11 Mar 2021 13:53:07 +0100 Subject: [PATCH 89/95] Update to support php 8 - address PR change requests --- tests/ChannelTest.php | 2 +- tests/ExpoControllerTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ChannelTest.php b/tests/ChannelTest.php index f1901b82..936e5345 100644 --- a/tests/ChannelTest.php +++ b/tests/ChannelTest.php @@ -54,7 +54,7 @@ protected function setUp(): void $this->notifiable = new TestNotifiable; } - public function tearDown(): void + protected function tearDown(): void { parent::tearDown(); diff --git a/tests/ExpoControllerTest.php b/tests/ExpoControllerTest.php index 97c10642..c1ccea87 100644 --- a/tests/ExpoControllerTest.php +++ b/tests/ExpoControllerTest.php @@ -48,7 +48,7 @@ protected function setUp(): void Auth::shouldReceive('user')->andReturn(new User()); } - public function tearDown(): void + protected function tearDown(): void { \Mockery::close(); From 857587966989627d6ddbb22178a51342874cba88 Mon Sep 17 00:00:00 2001 From: Mediabc Date: Thu, 29 Jul 2021 14:04:10 +0300 Subject: [PATCH 90/95] Update exponent-server-sdk-php version Update exponent-server-sdk-php version. Version include some improvements, such as processing API error response with empty body. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 98d8842d..f5195d2b 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ ], "require": { "php": "^7.1.3|^8.0", - "alymosul/exponent-server-sdk-php": "1.1.*", + "alymosul/exponent-server-sdk-php": "1.3.*", "laravel/framework": "^5.6 | ^6.0 | ^7.0 | ^8.0" }, "require-dev": { From 14201d9bcdb18bc39e0dcf7b9d87fe8da2a1f7d8 Mon Sep 17 00:00:00 2001 From: Mediabc Date: Thu, 29 Jul 2021 14:42:17 +0300 Subject: [PATCH 91/95] Fix tests --- src/ExpoChannel.php | 4 +++- tests/ChannelTest.php | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ExpoChannel.php b/src/ExpoChannel.php index 65861517..4412310e 100644 --- a/src/ExpoChannel.php +++ b/src/ExpoChannel.php @@ -48,9 +48,11 @@ public function send($notifiable, Notification $notification) $interest = $notifiable->routeNotificationFor('ExpoPushNotifications') ?: $this->interestName($notifiable); + $interests = [ $interest ]; + try { $this->expo->notify( - $interest, + $interests, $notification->toExpoPush($notifiable)->toArray(), config('exponent-push-notifications.debug') ); diff --git a/tests/ChannelTest.php b/tests/ChannelTest.php index 936e5345..710c0d2a 100644 --- a/tests/ChannelTest.php +++ b/tests/ChannelTest.php @@ -68,7 +68,7 @@ public function itCanSendANotification() $data = $message->toArray(); - $this->expo->shouldReceive('notify')->with('interest_name', $data, true)->andReturn([['status' => 'ok']]); + $this->expo->shouldReceive('notify')->with(['interest_name'], $data, true)->andReturn([['status' => 'ok']]); $this->channel->send($this->notifiable, $this->notification); } @@ -80,7 +80,7 @@ public function itFiresFailureEventOnFailure() $data = $message->toArray(); - $this->expo->shouldReceive('notify')->with('interest_name', $data, true)->andThrow(ExpoException::class, ''); + $this->expo->shouldReceive('notify')->with(['interest_name'], $data, true)->andThrow(ExpoException::class, ''); $this->events->shouldReceive('dispatch')->with(Mockery::type(NotificationFailed::class)); From d54d20bbc7cbaec52fd3940eb5dedef800c5298e Mon Sep 17 00:00:00 2001 From: Mediabc Date: Thu, 29 Jul 2021 15:21:39 +0300 Subject: [PATCH 92/95] Fix code style --- src/ExpoChannel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ExpoChannel.php b/src/ExpoChannel.php index 4412310e..5f07d8cc 100644 --- a/src/ExpoChannel.php +++ b/src/ExpoChannel.php @@ -48,7 +48,7 @@ public function send($notifiable, Notification $notification) $interest = $notifiable->routeNotificationFor('ExpoPushNotifications') ?: $this->interestName($notifiable); - $interests = [ $interest ]; + $interests = [$interest]; try { $this->expo->notify( From cc76c48c051dc302410a771fc23c83054e678a31 Mon Sep 17 00:00:00 2001 From: Aly Suleiman Date: Thu, 9 Sep 2021 10:20:20 +0000 Subject: [PATCH 93/95] Apply fixes from StyleCI --- src/ExpoChannel.php | 8 ++++---- src/ExpoMessage.php | 18 +++++++++--------- src/ExpoPushNotificationsServiceProvider.php | 2 +- src/Http/ExpoController.php | 6 +++--- src/Models/Interest.php | 2 +- src/Repositories/ExpoDatabaseDriver.php | 6 +++--- tests/ExpoControllerTest.php | 4 ++-- tests/TestCase.php | 2 +- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/ExpoChannel.php b/src/ExpoChannel.php index 5f07d8cc..9c366a47 100644 --- a/src/ExpoChannel.php +++ b/src/ExpoChannel.php @@ -24,8 +24,8 @@ class ExpoChannel /** * ExpoChannel constructor. * - * @param Expo $expo - * @param Dispatcher $events + * @param Expo $expo + * @param Dispatcher $events */ public function __construct(Expo $expo, Dispatcher $events) { @@ -36,8 +36,8 @@ public function __construct(Expo $expo, Dispatcher $events) /** * Send the given notification. * - * @param mixed $notifiable - * @param \Illuminate\Notifications\Notification $notification + * @param mixed $notifiable + * @param \Illuminate\Notifications\Notification $notification * * @throws CouldNotSendNotification * diff --git a/src/ExpoMessage.php b/src/ExpoMessage.php index 57519881..60dedba8 100644 --- a/src/ExpoMessage.php +++ b/src/ExpoMessage.php @@ -66,7 +66,7 @@ class ExpoMessage /** * Create a message with given body. * - * @param string $body + * @param string $body * * @return static */ @@ -78,7 +78,7 @@ public static function create($body = '') /** * ExpoMessage constructor. * - * @param string $body + * @param string $body */ public function __construct(string $body = '') { @@ -88,7 +88,7 @@ public function __construct(string $body = '') /** * Set the message title. * - * @param string $value + * @param string $value * * @return $this */ @@ -102,7 +102,7 @@ public function title(string $value) /** * Set the message body. * - * @param string $value + * @param string $value * * @return $this */ @@ -140,7 +140,7 @@ public function disableSound() /** * Set the message badge (iOS). * - * @param int $value + * @param int $value * * @return $this */ @@ -154,7 +154,7 @@ public function badge(int $value) /** * Set the time to live of the notification. * - * @param int $ttl + * @param int $ttl * * @return $this */ @@ -168,7 +168,7 @@ public function setTtl(int $ttl) /** * Set the channelId of the notification for Android devices. * - * @param string $channelId + * @param string $channelId * * @return $this */ @@ -182,7 +182,7 @@ public function setChannelId(string $channelId) /** * Set the json Data attached to the message. * - * @param array|string $data + * @param array|string $data * * @return $this * @@ -208,7 +208,7 @@ public function setJsonData($data) /** * Set the priority of the notification, must be one of [default, normal, high]. * - * @param string $priority + * @param string $priority * * @return $this */ diff --git a/src/ExpoPushNotificationsServiceProvider.php b/src/ExpoPushNotificationsServiceProvider.php index 241884b1..4aa4974d 100644 --- a/src/ExpoPushNotificationsServiceProvider.php +++ b/src/ExpoPushNotificationsServiceProvider.php @@ -81,7 +81,7 @@ protected function setupConfig() /** * Publishes the migration files needed in the package. * - * @param ExpoRepository $repository + * @param ExpoRepository $repository * * @return void */ diff --git a/src/Http/ExpoController.php b/src/Http/ExpoController.php index 29ae8c96..df059386 100644 --- a/src/Http/ExpoController.php +++ b/src/Http/ExpoController.php @@ -19,7 +19,7 @@ class ExpoController extends Controller /** * ExpoController constructor. * - * @param ExpoChannel $expoChannel + * @param ExpoChannel $expoChannel */ public function __construct(ExpoChannel $expoChannel) { @@ -29,7 +29,7 @@ public function __construct(ExpoChannel $expoChannel) /** * Handles subscription endpoint for an expo token. * - * @param Request $request + * @param Request $request * * @return \Illuminate\Http\JsonResponse */ @@ -72,7 +72,7 @@ public function subscribe(Request $request) /** * Handles removing subscription endpoint for the authenticated interest. * - * @param Request $request + * @param Request $request * * @return JsonResponse */ diff --git a/src/Models/Interest.php b/src/Models/Interest.php index 468a1116..093fd640 100644 --- a/src/Models/Interest.php +++ b/src/Models/Interest.php @@ -40,7 +40,7 @@ class Interest extends Model /** * Interest constructor. * - * @param array $attributes + * @param array $attributes */ public function __construct(array $attributes = []) { diff --git a/src/Repositories/ExpoDatabaseDriver.php b/src/Repositories/ExpoDatabaseDriver.php index 752ce5dd..86eb2932 100644 --- a/src/Repositories/ExpoDatabaseDriver.php +++ b/src/Repositories/ExpoDatabaseDriver.php @@ -28,7 +28,7 @@ public function store($key, $value): bool /** * Retrieves an Expo token with a given identifier. * - * @param string $key + * @param string $key * * @return array */ @@ -40,8 +40,8 @@ public function retrieve(string $key) /** * Removes an Expo token with a given identifier. * - * @param string $key - * @param string $value + * @param string $key + * @param string $value * * @return bool */ diff --git a/tests/ExpoControllerTest.php b/tests/ExpoControllerTest.php index c1ccea87..c4a925d5 100644 --- a/tests/ExpoControllerTest.php +++ b/tests/ExpoControllerTest.php @@ -26,7 +26,7 @@ class ExpoControllerTest extends TestCase /** * Sets up the expo controller with the given expo channel. * - * @param ExpoRepository $expoRepository + * @param ExpoRepository $expoRepository * * @return array */ @@ -250,7 +250,7 @@ public function mockRequest($data) } /** - * @param bool $fails + * @param bool $fails * * @return \Mockery\MockInterface */ diff --git a/tests/TestCase.php b/tests/TestCase.php index 9d9e35f4..a84a49a6 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -29,7 +29,7 @@ protected function getPackageProviders($app) /** * Define environment setup. * - * @param \Illuminate\Foundation\Application $app + * @param \Illuminate\Foundation\Application $app * * @return void */ From 65b1463ab68d7c5529b5abb5206d0e515646a046 Mon Sep 17 00:00:00 2001 From: Udipta Gogoi <57178072+udiptaweb@users.noreply.github.com> Date: Mon, 13 Sep 2021 01:14:40 +0530 Subject: [PATCH 94/95] isset for config('exponent-push-notifications') and default empty array --- src/ExpoPushNotificationsServiceProvider.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ExpoPushNotificationsServiceProvider.php b/src/ExpoPushNotificationsServiceProvider.php index 4aa4974d..e4ad382f 100644 --- a/src/ExpoPushNotificationsServiceProvider.php +++ b/src/ExpoPushNotificationsServiceProvider.php @@ -31,7 +31,9 @@ public function boot() }); $router = $this->app['router']; - $router->middlewareGroup('expo.middleware', config('exponent-push-notifications')['middleware']); + + $router->middlewareGroup('expo.middleware', isset(config('exponent-push-notifications')['middleware']) ? config('exponent-push-notifications')['middleware'] : [] ); + $this->loadRoutesFrom(__DIR__.'/Http/routes.php'); } From 99be5210bd67e87c38d9c90c8e5950da81ecf700 Mon Sep 17 00:00:00 2001 From: Udipta Gogoi <57178072+udiptaweb@users.noreply.github.com> Date: Mon, 13 Sep 2021 01:21:30 +0530 Subject: [PATCH 95/95] isset for config('exponent-push-notifications') and set default empty array --- src/ExpoPushNotificationsServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ExpoPushNotificationsServiceProvider.php b/src/ExpoPushNotificationsServiceProvider.php index e4ad382f..131877da 100644 --- a/src/ExpoPushNotificationsServiceProvider.php +++ b/src/ExpoPushNotificationsServiceProvider.php @@ -32,7 +32,7 @@ public function boot() $router = $this->app['router']; - $router->middlewareGroup('expo.middleware', isset(config('exponent-push-notifications')['middleware']) ? config('exponent-push-notifications')['middleware'] : [] ); + $router->middlewareGroup('expo.middleware', isset(config('exponent-push-notifications')['middleware']) ? config('exponent-push-notifications')['middleware'] : []); $this->loadRoutesFrom(__DIR__.'/Http/routes.php');