Skip to content

Commit 220c067

Browse files
committed
Add test and fixes
1 parent 37a859f commit 220c067

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

src/TwilioChannel.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(Twilio $twilio, Dispatcher $events)
4343
*/
4444
public function send($notifiable, Notification $notification)
4545
{
46-
if (! $this->twilio->config->enabled()) {
46+
if (! $this->isEnabled()) {
4747
return;
4848
}
4949

@@ -79,6 +79,20 @@ public function send($notifiable, Notification $notification)
7979
}
8080
}
8181

82+
/**
83+
* Check if twilio is enabled.
84+
*
85+
* @return boolean
86+
*/
87+
protected function isEnabled()
88+
{
89+
if (is_null($this->twilio->config)) {
90+
return true;
91+
}
92+
93+
return $this->twilio->config->enabled();
94+
}
95+
8296
/**
8397
* Get the address to send a notification to.
8498
*

src/TwilioConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function __construct(array $config)
1717

1818
public function enabled()
1919
{
20-
return $this->config['enabled'];
20+
return $this->config['enabled'] ?? true;
2121
}
2222

2323
public function usingUsernamePasswordAuth(): bool

tests/Integration/BaseIntegrationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace NotificationChannels\Twilio\Tests\Integration;
66

77
use NotificationChannels\Twilio\TwilioProvider;
8-
use Orchestra\Testbench\TestCase;
8+
use PHPUnit\Framework\TestCase;
99

1010
abstract class BaseIntegrationTest extends TestCase
1111
{

tests/Unit/TwilioChannelTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ public function setUp(): void
3636
$this->channel = new TwilioChannel($this->twilio, $this->dispatcher);
3737
}
3838

39+
/** @test */
40+
public function it_will_not_send_a_message_if_not_enabled()
41+
{
42+
$notifiable = new Notifiable();
43+
$notification = Mockery::mock(Notification::class);
44+
45+
$this->twilio->config = new TwilioConfig([
46+
'enabled' => false,
47+
]);
48+
49+
$result = $this->channel->send($notifiable, $notification);
50+
51+
$this->assertNull($result);
52+
}
53+
3954
/** @test */
4055
public function it_will_not_send_a_message_without_known_receiver()
4156
{

0 commit comments

Comments
 (0)