Skip to content

Commit 48302c2

Browse files
authored
Merge pull request #13 from bmitch/tests
Added a couple tests
2 parents 9965b96 + 4a9bcba commit 48302c2

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
},
2727
"require-dev": {
2828
"mockery/mockery": "^0.9.5",
29-
"phpunit/phpunit": "5.*"
29+
"phpunit/phpunit": "5.*",
30+
"orchestra/testbench": "3.3.x-dev"
3031
},
3132
"autoload": {
3233
"psr-4": {

tests/TelegramChannelTest.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
namespace NotificationChannels\Telegram\Test;
4+
5+
use Mockery;
6+
use Illuminate\Notifications\Notification;
7+
use NotificationChannels\Telegram\Exceptions\CouldNotSendNotification;
8+
use NotificationChannels\Telegram\TelegramChannel;
9+
use NotificationChannels\Telegram\Telegram;
10+
use NotificationChannels\Telegram\TelegramMessage;
11+
use Orchestra\Testbench\TestCase;
12+
13+
class ChannelTest extends TestCase
14+
{
15+
/** @var Mockery\Mock */
16+
protected $telegram;
17+
18+
/** @var \NotificationChannels\Telegram\TelegramChannel */
19+
protected $channel;
20+
21+
public function setUp()
22+
{
23+
parent::setUp();
24+
$this->telegram = Mockery::mock(Telegram::class);
25+
$this->channel = new TelegramChannel($this->telegram);
26+
}
27+
28+
/** @test */
29+
public function it_can_send_a_message()
30+
{
31+
$this->telegram->shouldReceive('sendMessage')->once()->with([
32+
'text' => 'Laravel Notification Channels are awesome!',
33+
'parse_mode' => 'Markdown',
34+
'chat_id' => 12345,
35+
]);
36+
$this->channel->send(new TestNotifiable(), new TestNotification());
37+
}
38+
39+
/** @test */
40+
public function it_throws_an_exception_when_it_could_not_send_the_notification_because_no_chat_id_provided()
41+
{
42+
$this->setExpectedException(CouldNotSendNotification::class);
43+
$this->channel->send(new TestNotifiable(), new TestNotificationNoChatId());
44+
}
45+
46+
}
47+
48+
class TestNotifiable
49+
{
50+
use \Illuminate\Notifications\Notifiable;
51+
/**
52+
* @return int
53+
*/
54+
public function routeNotificationForTelegram()
55+
{
56+
return false;
57+
}
58+
}
59+
60+
class TestNotification extends Notification
61+
{
62+
public function toTelegram($notifiable)
63+
{
64+
return TelegramMessage::create('Laravel Notification Channels are awesome!')->to(12345);
65+
}
66+
}
67+
68+
class TestNotificationNoChatId extends Notification
69+
{
70+
public function toTelegram($notifiable)
71+
{
72+
return TelegramMessage::create();
73+
}
74+
}

0 commit comments

Comments
 (0)