-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a1b2947
commit 3040d9d
Showing
6 changed files
with
156 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace NotificationChannels\Fcm\Resources; | ||
|
||
abstract class FcmResource | ||
{ | ||
/** | ||
* @return static | ||
*/ | ||
public static function create(): static | ||
{ | ||
return new static; | ||
} | ||
|
||
/** | ||
* Map the resource to an array. | ||
*/ | ||
abstract public function toArray(): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace NotificationChannels\Fcm\Resources; | ||
|
||
class Notification extends FcmResource | ||
{ | ||
/** | ||
* The notification title. | ||
*/ | ||
public ?string $title = null; | ||
|
||
/** | ||
* The notification body. | ||
*/ | ||
public ?string $body = null; | ||
|
||
/** | ||
* The notification image. | ||
*/ | ||
public ?string $image = null; | ||
|
||
/** | ||
* Set the notification title. | ||
*/ | ||
public function title(?string $title): self | ||
{ | ||
$this->title = $title; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Set the notification body. | ||
*/ | ||
public function body(?string $body): self | ||
{ | ||
$this->body = $body; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Set the notification image. | ||
*/ | ||
public function image(?string $image): self | ||
{ | ||
$this->image = $image; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Map the resource to an array. | ||
*/ | ||
public function toArray(): array | ||
{ | ||
return array_filter([ | ||
'title' => $this->title, | ||
'body' => $this->body, | ||
'image' => $this->image, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace NotificationChannels\Fcm\Test\Resources; | ||
|
||
use NotificationChannels\Fcm\Resources\Notification; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class NotificationTest extends TestCase | ||
{ | ||
public function test_it_can_be_instantiated() | ||
{ | ||
$message = Notification::create(); | ||
|
||
$this->assertInstanceOf(Notification::class, $message); | ||
} | ||
|
||
public function test_it_can_set_title() | ||
{ | ||
$message = Notification::create()->title('title'); | ||
|
||
$this->assertEquals(['title' => 'title'], $message->toArray()); | ||
} | ||
|
||
public function test_it_can_set_body() | ||
{ | ||
$message = Notification::create()->body('body'); | ||
|
||
$this->assertEquals(['body' => 'body'], $message->toArray()); | ||
} | ||
|
||
public function test_it_can_set_image() | ||
{ | ||
$message = Notification::create()->image('image'); | ||
|
||
$this->assertEquals(['image' => 'image'], $message->toArray()); | ||
} | ||
} |