Skip to content

Commit

Permalink
improving test coverage
Browse files Browse the repository at this point in the history
Increase automated test coverage to 100% #28
Add click_action for ionic FCM plugin #35
  • Loading branch information
AndyGaskell committed Oct 18, 2020
1 parent 574ac42 commit 0bec69b
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Push/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Fcm\Push;

use Fcm\Exception\NotificationException;


trait Push
{
/**
Expand Down
74 changes: 73 additions & 1 deletion tests/PushTests/NotificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function it_can_not_have_a_recipient_and_topic()
$notification->getBody();
}


/** @test */
public function it_can_generate_a_notification_for_multiple_recipients()
{
Expand Down Expand Up @@ -164,6 +165,31 @@ public function it_can_generate_a_notification_with_data()
}


/** @test */
public function it_can_generate_a_notification_with_no_data()
{
$notification = new \Fcm\Push\Notification();
$notification
->setTitle('Test title')
->addRecipient('device');

$expected = [
'to' => 'device',
'notification' => [
'title' => 'Test title',
'body' => '',
'sound' => '',
'icon' => '',
'color' => '',
'tag' => '',
'subtitle' => '',
],
];

$this->assertSame($expected, $notification->getBody());
}


/** @test */
public function it_can_generate_a_notification_with_add_data_array()
{
Expand Down Expand Up @@ -201,6 +227,24 @@ public function it_can_generate_a_notification_with_add_data_array()
}


/**
* @test
*
* @expectedException \Fcm\Exception\NotificationException
* @expectedExceptionMessage Data must be an asscoiative array of ("key" => "value") pairs.
*/
public function it_will_throw_an_exception_if_data_is_not_an_asscoiative_array()
{
$notification = new \Fcm\Push\Notification();
$notification
->setTitle('Test title')
->addRecipient('device')
->addDataArray('array');

$notification->getBody();
}


/** @test */
public function it_can_generate_a_notification_with_add_data_array_twice()
{
Expand Down Expand Up @@ -453,7 +497,7 @@ public function it_generates_a_correct_notification_object_setting_icon()
}

/** @test */
public function it_generates_a_correct_notification_object_click_action()
public function it_generates_a_correct_notification_object_setting_click_action()
{
$notification = new \Fcm\Push\Notification();
$notification
Expand Down Expand Up @@ -482,4 +526,32 @@ public function it_generates_a_correct_notification_object_click_action()
$this->assertSame($expected, $notification->getBody());
}


/** @test */
public function it_generates_a_correct_notification_object_no_click_action()
{
$notification = new \Fcm\Push\Notification();
$notification
->setTitle('Test title')
->addRecipient('device')
->addData('key', 'value');

$expected = [
'to' => 'device',
'notification' => [
'title' => 'Test title',
'body' => '',
'sound' => '',
'icon' => '',
'color' => '',
'tag' => '',
'subtitle' => '',
],
'data' => [
'key' => 'value',
],
];
$this->assertSame($expected, $notification->getBody());
}

}

0 comments on commit 0bec69b

Please sign in to comment.