diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..73f69e0
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
+# Editor-based HTTP Client requests
+/httpRequests/
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..e3d68ca
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/laravel-fcm-notification-channel.iml b/.idea/laravel-fcm-notification-channel.iml
new file mode 100644
index 0000000..0af378f
--- /dev/null
+++ b/.idea/laravel-fcm-notification-channel.iml
@@ -0,0 +1,103 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..28a804d
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..6a6d442
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/php.xml b/.idea/php.xml
new file mode 100644
index 0000000..00b0c8b
--- /dev/null
+++ b/.idea/php.xml
@@ -0,0 +1,109 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/phpunit.xml b/.idea/phpunit.xml
new file mode 100644
index 0000000..4f8104c
--- /dev/null
+++ b/.idea/phpunit.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.php_cs b/.php_cs
index e8c5a2a..118e05c 100644
--- a/.php_cs
+++ b/.php_cs
@@ -1,77 +1,71 @@
notPath('vendor')
+ ->in(__DIR__)
+ ->name('*.php')
+ ->ignoreDotFiles(true)
+ ->ignoreVCS(true);
-use Symfony\CS\Config\Config;
-use Symfony\CS\FixerInterface;
-use Symfony\CS\Finder\DefaultFinder;
-
-$fixers = [
- 'blankline_after_open_tag',
- 'braces',
- 'concat_without_spaces',
- 'double_arrow_multiline_whitespaces',
- 'duplicate_semicolon',
- 'elseif',
- 'empty_return',
- 'encoding',
- 'eof_ending',
- 'extra_empty_lines',
- 'function_call_space',
- 'function_declaration',
- 'include',
- 'indentation',
- 'join_function',
- 'line_after_namespace',
- 'linefeed',
- 'list_commas',
- 'logical_not_operators_with_successor_space',
- 'lowercase_constants',
- 'lowercase_keywords',
- 'method_argument_space',
- 'multiline_array_trailing_comma',
- 'multiline_spaces_before_semicolon',
- 'multiple_use',
- 'namespace_no_leading_whitespace',
- 'no_blank_lines_after_class_opening',
- 'no_empty_lines_after_phpdocs',
- 'object_operator',
- 'operators_spaces',
- 'parenthesis',
- 'phpdoc_indent',
- 'phpdoc_inline_tag',
- 'phpdoc_no_access',
- 'phpdoc_no_package',
- 'phpdoc_scalar',
- 'phpdoc_short_description',
- 'phpdoc_to_comment',
- 'phpdoc_trim',
- 'phpdoc_type_to_var',
- 'phpdoc_var_without_name',
- 'remove_leading_slash_use',
- 'remove_lines_between_uses',
- 'return',
- 'self_accessor',
- 'short_array_syntax',
- 'short_echo_tag',
- 'short_tag',
- 'single_array_no_trailing_comma',
- 'single_blank_line_before_namespace',
- 'single_line_after_imports',
- 'single_quote',
- 'spaces_before_semicolon',
- 'spaces_cast',
- 'standardize_not_equal',
- 'ternary_spaces',
- 'trailing_spaces',
- 'trim_array_spaces',
- 'unalign_equals',
- 'unary_operators_spaces',
- 'unused_use',
- 'visibility',
- 'whitespacy_lines',
-];
-
-return Config::create()
- ->finder(DefaultFinder::create()->in(__DIR__))
- ->fixers($fixers)
- ->level(FixerInterface::NONE_LEVEL)
- ->setUsingCache(true);
+return PhpCsFixer\Config::create()
+ ->setRules([
+ '@PSR2' => true,
+ /*
+ * Arrays
+ */
+ // PHP arrays should be declared using the short syntax [] not array().
+ 'array_syntax' => ['syntax' => 'short'],
+ // In array declaration, there MUST be a whitespace after each comma.
+ 'whitespace_after_comma_in_array' => true,
+ // PHP multi-line arrays should have a trailing comma.
+ 'trailing_comma_in_multiline_array' => true,
+ /*
+ * Whitespaces
+ */
+ // Ensure there is no code on the same line as the PHP open tag and it is followed by a blank line.
+ 'blank_line_after_opening_tag' => true,
+ // Methods must be separated with one blank line.
+ 'method_separation' => true,
+ // An empty line feed should precede a return statement.
+ 'blank_line_before_return' => true,
+ // Remove trailing whitespace at the end of blank lines.
+ 'no_whitespace_in_blank_line' => true,
+ // Logical NOT operators (!) should have one trailing whitespace.
+ 'not_operator_with_successor_space' => true,
+ // There should not be space before or after object T_OBJECT_OPERATOR ->.
+ 'object_operator_without_whitespace' => true,
+ // A single space should be between cast and variable.
+ 'cast_spaces' => true,
+ // There should be exactly one blank line before a namespace declaration.
+ 'single_blank_line_before_namespace' => true,
+ // Standardize spaces around ternary operator.
+ 'ternary_operator_spaces' => true,
+ /*
+ * PHPDocs
+ */
+ // Docblocks should have the same indentation as the documented subject.
+ 'phpdoc_indent' => true,
+ // Annotations in phpdocs should be ordered so that param annotations come first, then throws annotations, then return annotations.
+ 'phpdoc_order' => true,
+ // The type of @return annotations of methods returning a reference to itself must be $this.
+ 'phpdoc_return_self_reference' => true,
+ // Phpdocs summary should end in either a full stop, exclamation mark, or question mark.
+ 'phpdoc_summary' => true,
+ // Docblocks should only be used on structural elements.
+ 'phpdoc_to_comment' => true,
+ // @package and @subpackage annotations should be omitted from phpdocs.
+ 'phpdoc_no_package' => true,
+ // @var and @type annotations should not contain the variable name.
+ 'phpdoc_var_without_name' => true,
+ // Scalar types should always be written in the same form. int not integer, bool not boolean, float not real or double.
+ 'phpdoc_scalar' => true,
+ /*
+ * Other
+ */
+ // Single line comments should use double slashes // and not hash #.
+ 'hash_to_slash_comment' => true,
+ // Cast (boolean) and (integer) should be written as (bool) and (int), (double) and (real) as (float).
+ 'short_scalar_cast' => true,
+ // The import statements should be sorted by length.
+ 'ordered_imports' => ['sortAlgorithm' => 'length'],
+ ])
+ ->setFinder($finder);
diff --git a/README.md b/README.md
index f82e71d..0cf789a 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# FCM notification channel for Laravel 5.3
+# FCM notification channel for Laravel 6.x
This package makes it easy to send notifications using [Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-messaging/) (FCM) with Laravel 5.3.
This package is based on [brozot/laravel-fcm](https://github.com/brozot/Laravel-FCM), so please read that documentation for more information.
@@ -17,20 +17,37 @@ This package is based on [brozot/laravel-fcm](https://github.com/brozot/Laravel-
## Installation
-You can install this package via composer:
+Before installation you should to add this repository to your `composer.json` file :
+```
+"repositories": [
+ {
+ "type": "vcs",
+ "url": "https://github.com/ahmed-aliraqi/laravel-fcm-notification-channel"
+ }
+],
+```
+
+Now you can install this package via composer:
``` bash
-composer require enniel/laravel-fcm-notification-channel:1.*
+composer require enniel/laravel-fcm-notification-channel
```
-Register the provider directly in your app configuration file `config/app.php`:
-``` php
-'providers' => [
- // ...
- NotificationChannels\FCM\ServiceProvider::class
-]
+## Package Configuration
+
+In your `.env` file, add the server key and the secret key for the Firebase Cloud Messaging:
+
+```dotenv
+FCM_SERVER_KEY=my_secret_server_key
+FCM_SENDER_ID=my_secret_sender_id
```
+To get these keys, you must create a new application on the [firebase cloud messaging console](https://console.firebase.google.com/).
+
+After the creation of your application on Firebase, you can find keys in `project settings -> cloud messaging`.
+
+
+
## Usage
Now you can use the channel in your `via()` method inside the notification:
@@ -49,7 +66,7 @@ class ExampleNotification extends Notification
public function toFCM($notifiable)
{
return (new FCMMessage())
- ->notification([
+ ->data([
'title' => 'Notification title',
'body' => 'Notification body',
]);
diff --git a/composer.json b/composer.json
index 6b85992..53e83d0 100644
--- a/composer.json
+++ b/composer.json
@@ -13,16 +13,16 @@
"email": "razumov.evgeni@gmail.com"
}],
"require": {
- "php": ">=5.5.9",
- "brozot/laravel-fcm": "~1.2.5",
- "illuminate/notifications": "~5.3",
- "illuminate/queue": "~5.1",
- "illuminate/support": "~5.1"
+ "php": "^7.1.3",
+ "apility/laravel-fcm": "^1.4",
+ "illuminate/notifications": "^7.7",
+ "illuminate/support": "^7.7",
+ "illuminate/queue": "^7.7"
},
"require-dev": {
- "friendsofphp/php-cs-fixer": "~1.12.2",
- "phpunit/phpunit": "4.*",
- "mockery/mockery": "^1.0"
+ "phpunit/phpunit": "^9.1",
+ "mockery/mockery": "^1.3",
+ "friendsofphp/php-cs-fixer": "^2.16"
},
"autoload": {
"psr-4": {
@@ -32,15 +32,19 @@
},
"scripts": {
"test": [
- "@phpcs",
"@phpunit"
],
- "phpcs": "php vendor/bin/php-cs-fixer --diff --dry-run -v fix",
- "phpunit": "php vendor/bin/phpunit"
+ "phpcs": "vendor/bin/php-cs-fixer fix",
+ "phpunit": "vendor/bin/phpunit"
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
+ },
+ "laravel": {
+ "providers": [
+ "NotificationChannels\\FCM\\ServiceProvider"
+ ]
}
},
"minimum-stability": "dev",
diff --git a/phpunit.xml b/phpunit.xml
index 58e1a70..b88c77b 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -1,14 +1,13 @@
+ backupStaticAttributes="false"
+ bootstrap="vendor/autoload.php"
+ colors="true"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ processIsolation="false"
+ stopOnFailure="false">
diff --git a/src/FCMChannel.php b/src/FCMChannel.php
index b8000cf..18e0019 100644
--- a/src/FCMChannel.php
+++ b/src/FCMChannel.php
@@ -2,9 +2,9 @@
namespace NotificationChannels\FCM;
-use LaravelFCM\Sender\FCMSender;
-use Illuminate\Events\Dispatcher;
+use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Notifications\Notification;
+use LaravelFCM\Sender\FCMSender;
use NotificationChannels\FCM\Exceptions\CouldNotSendNotification;
class FCMChannel
@@ -15,14 +15,15 @@ class FCMChannel
protected $sender;
/**
- * @var \Illuminate\Events\Dispatcher
+ * @var \Illuminate\Contracts\Events\Dispatcher
*/
protected $events;
/**
* Constructor.
*
- * @param \LaravelFCM\Sender\FCMSender $sender
+ * @param \LaravelFCM\Sender\FCMSender $sender
+ * @param \Illuminate\Contracts\Events\Dispatcher $events
*/
public function __construct(FCMSender $sender, Dispatcher $events)
{
@@ -62,7 +63,7 @@ public function send($notifiable, Notification $notification)
$response = $this->sender->{$method}(...$message->getArgs());
- $this->events->fire(new MessageWasSended($response, $notifiable));
+ $this->events->dispatch(new MessageWasSended($response, $notifiable));
return $response;
}
diff --git a/src/FCMMessage.php b/src/FCMMessage.php
index c011f06..dab82dd 100644
--- a/src/FCMMessage.php
+++ b/src/FCMMessage.php
@@ -4,9 +4,9 @@
use Illuminate\Support\Arr;
use LaravelFCM\Message\Options;
-use LaravelFCM\Message\PayloadData;
use LaravelFCM\Message\OptionsBuilder;
use LaravelFCM\Message\OptionsPriorities;
+use LaravelFCM\Message\PayloadData;
use LaravelFCM\Message\PayloadDataBuilder;
use LaravelFCM\Message\PayloadNotification;
use LaravelFCM\Message\PayloadNotificationBuilder;
@@ -150,11 +150,9 @@ public function __construct($options = null, $notification = null, $data = null)
/**
* Call method.
*
- * @param string $method
- * @param mixed $value
- *
+ * @param string $method
+ * @param array $arguments
* @return mixed
- * @throws \BadMethodCallException
*/
public function __call($method, array $arguments)
{
@@ -196,9 +194,10 @@ public function __call($method, array $arguments)
/**
* Create Message.
*
- * @param mixed $options
- * @param mixed $notification
- * @param mixed $data
+ * @param mixed $options
+ * @param mixed $notification
+ * @param mixed $data
+ * @return \NotificationChannels\FCM\FCMMessage
*/
public static function create($options = null, $notification = null, $data = null)
{
@@ -244,7 +243,7 @@ protected static function makeInvalidArgumentException($data, $method, $containe
}
return new InvalidArgumentException(
- 'The argument for %s::%s must be instanceof %s, %s, null or array. %s given.',
+ 'The argument for %s::%s must be instanceof %s, %s, null or array. %s given.',
[
self::class, $method, $container, $builder, $type,
]
@@ -273,7 +272,7 @@ protected static function populateBuilder($builder, array $map, array $data)
* Set Options.
*
* @param mixed $options
- * @return
+ * @return $this
*/
public function options($options = null)
{
diff --git a/src/FCMMessageTopic.php b/src/FCMMessageTopic.php
index 89fdfed..1ba4d39 100644
--- a/src/FCMMessageTopic.php
+++ b/src/FCMMessageTopic.php
@@ -19,7 +19,7 @@ public function to($recipient)
}
return new InvalidArgumentException(
- 'The argument for %s::%s must be instanceof %s, null or array. %s given.',
+ 'The argument for %s::%s must be instanceof %s, null or array. %s given.',
[
self::class, 'to', Topics::class, $type,
]
diff --git a/tests/FCMChannelTest.php b/tests/FCMChannelTest.php
index 1e3a720..85d9895 100644
--- a/tests/FCMChannelTest.php
+++ b/tests/FCMChannelTest.php
@@ -2,27 +2,28 @@
namespace NotificationChannels\FCM\Test;
-use Mockery;
-use LaravelFCM\Sender\FCMSender;
-use Illuminate\Events\Dispatcher;
+use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Notifications\Notifiable;
-use NotificationChannels\FCM\FCMChannel;
-use NotificationChannels\FCM\FCMMessage;
use Illuminate\Notifications\Notification;
use LaravelFCM\Response\DownstreamResponse;
-use NotificationChannels\FCM\MessageWasSended;
+use LaravelFCM\Sender\FCMSender;
+use Mockery;
use NotificationChannels\FCM\Exceptions\CouldNotSendNotification;
+use NotificationChannels\FCM\FCMChannel;
+use NotificationChannels\FCM\FCMMessage;
+use NotificationChannels\FCM\MessageWasSended;
+use PHPUnit\Framework\TestCase;
-class FCMChannelTest extends \PHPUnit_Framework_TestCase
+class FCMChannelTest extends TestCase
{
- public function setUp()
+ public function setUp(): void
{
$this->sender = Mockery::mock(FCMSender::class);
$this->events = Mockery::mock(Dispatcher::class);
$this->channel = new FCMChannel($this->sender, $this->events);
}
- public function tearDown()
+ public function tearDown(): void
{
Mockery::close();
parent::tearDown();
@@ -38,7 +39,7 @@ public function it_can_send_a_notification()
$message->to($to);
$args = $message->getArgs();
$this->sender->shouldReceive('sendTo')->with(...$args)->andReturn(Mockery::mock(DownstreamResponse::class));
- $this->events->shouldReceive('fire')->with(Mockery::type(MessageWasSended::class));
+ $this->events->shouldReceive('dispatch')->with(Mockery::type(MessageWasSended::class));
$result = $this->channel->send($notifiable, $notification);
$this->assertInstanceOf(DownstreamResponse::class, $result);
}
@@ -53,7 +54,7 @@ public function it_return_null_with_recipient_empty_array()
$message->to($to);
$args = $message->getArgs();
$this->sender->shouldNotReceive('sendTo');
- $this->events->shouldNotReceive('fire');
+ $this->events->shouldNotReceive('dispatch');
$result = $this->channel->send($notifiable, $notification);
$this->assertNull($result);
}
@@ -61,15 +62,15 @@ public function it_return_null_with_recipient_empty_array()
/** @test */
public function it_throw_could_not_send_notification_exception()
{
- $this->setExpectedException(CouldNotSendNotification::class);
+ $this->expectException(CouldNotSendNotification::class);
$notifiable = new TestNotifiableWithInvalidRecipient;
$notification = new TestNotification;
try {
$this->channel->send($notifiable, $notification);
} catch (CouldNotSendNotification $e) {
$this->assertEquals(
- 'Notification was not sent. You should specify device token(s), topic(s) or group(s) for sending notification.',
- $e->getMessage()
+ 'Notification was not sent. You should specify device token(s), topic(s) or group(s) for sending notification.',
+ $e->getMessage()
);
throw $e;
}
diff --git a/tests/FCMMessageTest.php b/tests/FCMMessageTest.php
index a42cf99..6868aa3 100644
--- a/tests/FCMMessageTest.php
+++ b/tests/FCMMessageTest.php
@@ -3,16 +3,17 @@
namespace NotificationChannels\FCM\Test;
use LaravelFCM\Message\Options;
-use LaravelFCM\Message\PayloadData;
use LaravelFCM\Message\OptionsBuilder;
-use NotificationChannels\FCM\FCMMessage;
use LaravelFCM\Message\OptionsPriorities;
+use LaravelFCM\Message\PayloadData;
use LaravelFCM\Message\PayloadDataBuilder;
use LaravelFCM\Message\PayloadNotification;
use LaravelFCM\Message\PayloadNotificationBuilder;
use NotificationChannels\FCM\Exceptions\InvalidArgumentException;
+use NotificationChannels\FCM\FCMMessage;
+use PHPUnit\Framework\TestCase;
-class FCMMessageTest extends \PHPUnit_Framework_TestCase
+class FCMMessageTest extends TestCase
{
/** @test */
public function it_construct_with_options_from_builder()
@@ -115,7 +116,7 @@ public function it_construct_with_options_merge_if_array()
/** @test */
public function it_construct_with_options_and_throw_exception()
{
- $this->setExpectedException(InvalidArgumentException::class);
+ $this->expectException(InvalidArgumentException::class);
try {
(new FCMMessage())->options('foo');
} catch (InvalidArgumentException $e) {
@@ -206,7 +207,7 @@ public function it_construct_with_data_merge_if_array()
/** @test */
public function it_construct_with_data_and_throw_exception()
{
- $this->setExpectedException(InvalidArgumentException::class);
+ $this->expectException(InvalidArgumentException::class);
try {
(new FCMMessage())->data('foo');
} catch (InvalidArgumentException $e) {
@@ -350,7 +351,7 @@ public function it_construct_with_notification_merge_if_array()
/** @test */
public function it_construct_with_notification_and_throw_exception()
{
- $this->setExpectedException(InvalidArgumentException::class);
+ $this->expectException(InvalidArgumentException::class);
try {
(new FCMMessage())->notification('foo');
} catch (InvalidArgumentException $e) {