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