Skip to content

Commit 6ae4b9d

Browse files
authored
use laravel Conditionable trait (laravel-notification-channels#139)
1 parent 1b8ef4c commit 6ae4b9d

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/Traits/HasSharedLogic.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
namespace NotificationChannels\Telegram\Traits;
44

5+
use Illuminate\Support\Traits\Conditionable;
6+
57
/**
68
* Trait HasSharedLogic.
79
*/
810
trait HasSharedLogic
911
{
12+
use Conditionable;
13+
1014
/** @var string Bot Token. */
1115
public $token;
1216

tests/TelegramMessageTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,25 @@ public function itCanReturnThePayloadAsAnArray(): void
100100

101101
$this->assertEquals($expected, $message->toArray());
102102
}
103+
104+
105+
/** @test */
106+
public function testLaravelConditionableTrait(): void
107+
{
108+
$message = new TelegramMessage();
109+
$message->button('Laravel', 'https://laravel.com');
110+
$message->when(true, fn($tg) => $tg->button('Github', 'https://github.com'));
111+
112+
$this->assertEquals(
113+
'{"inline_keyboard":[[{"text":"Laravel","url":"https:\/\/laravel.com"},{"text":"Github","url":"https:\/\/github.com"}]]}',
114+
$message->getPayloadValue('reply_markup')
115+
);
116+
117+
$message->when(false, fn($tg) => $tg->button('Google', 'https://google.com'));
118+
119+
$this->assertEquals(
120+
'{"inline_keyboard":[[{"text":"Laravel","url":"https:\/\/laravel.com"},{"text":"Github","url":"https:\/\/github.com"}]]}',
121+
$message->getPayloadValue('reply_markup')
122+
);
123+
}
103124
}

0 commit comments

Comments
 (0)