Skip to content

Commit 88f2572

Browse files
committed
Merge remote-tracking branch 'origin/v4' into 142-totwilio-override
2 parents a50563b + 0cd8604 commit 88f2572

File tree

7 files changed

+66
-10
lines changed

7 files changed

+66
-10
lines changed

.github/workflows/php.yml

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,48 @@
11
name: PHP
22

3-
on: [push, pull_request]
3+
on:
4+
- push
5+
- pull_request
46

57
jobs:
68
run:
79
runs-on: ubuntu-latest
10+
811
strategy:
912
max-parallel: 15
1013
fail-fast: false
1114
matrix:
12-
laravel-version: ['^8.0', '^9.0', 10.*]
15+
laravel-version: ['10.*', '11.0', ^8.0, ^9.0]
1316
php-version: ['8.0', '8.1', '8.2']
17+
exclude:
18+
- laravel-version: 11.*
19+
php-version: '8.0'
20+
- laravel-version: 11.*
21+
php-version: '8.1'
22+
1423
name: PHP ${{ matrix.php-version }} on Laravel ${{ matrix.laravel-version }}
24+
1525
steps:
1626
- name: Checkout
1727
uses: actions/checkout@master
28+
1829
- name: Setup PHP
1930
uses: shivammathur/setup-php@master
2031
with:
2132
php-version: ${{ matrix.php-version }}
2233
extension-csv: mbstring, xdebug
2334
coverage: xdebug
35+
2436
- name: Install dependencies
2537
run: |
2638
composer require --no-update --no-interaction "illuminate/support:${{ matrix.laravel-version }}"
2739
composer update --no-interaction --prefer-dist --no-suggest
40+
2841
- name: Lint composer.json
2942
run: composer validate
43+
3044
- name: Run Tests
3145
run: composer test:unit
46+
3247
- name: Run Integration Tests
3348
run: composer test:integration

composer.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@
3030
],
3131
"require": {
3232
"php": ">=7.2|^8.0",
33-
"twilio/sdk": "~6.0",
34-
"illuminate/notifications": "^7.0 || ^8.0 || ^9.0 || ^10.0",
35-
"illuminate/support": "^7.0 || ^8.0 || ^9.0 || ^10.0",
36-
"illuminate/events": "^7.0 || ^8.0 || ^9.0 || ^10.0",
37-
"illuminate/queue": "^7.0 || ^8.0 || ^9.0 || ^10.0"
33+
"twilio/sdk": "~6.0|^7.16",
34+
"illuminate/notifications": "^7.0 || ^8.0 || ^9.0 || ^10.0|^11.0",
35+
"illuminate/support": "^7.0 || ^8.0 || ^9.0 || ^10.0|^11.0",
36+
"illuminate/events": "^7.0 || ^8.0 || ^9.0 || ^10.0|^11.0",
37+
"illuminate/queue": "^7.0 || ^8.0 || ^9.0 || ^10.0|^11.0"
3838
},
3939
"require-dev": {
4040
"mockery/mockery": "^1.3",
41-
"phpunit/phpunit": "^8.5|^9.5",
42-
"orchestra/testbench": "^5.0 || ^6.0 || ^7.0 || ^8.0"
41+
"phpunit/phpunit": "^8.5|^9.5|^10.5",
42+
"orchestra/testbench": "^5.0 || ^6.0 || ^7.0 || ^8.0|^9.0"
4343
},
4444
"autoload": {
4545
"psr-4": {

config/twilio-notification-channel.php

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
return [
4+
'enabled' => env('TWILIO_ENABLED', true),
45
'username' => env('TWILIO_USERNAME'), // optional when using auth token
56
'password' => env('TWILIO_PASSWORD'), // optional when using auth token
67
'auth_token' => env('TWILIO_AUTH_TOKEN'), // optional when using username and password

src/TwilioChannel.php

+18
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public function __construct(Twilio $twilio, Dispatcher $events)
4343
*/
4444
public function send($notifiable, Notification $notification)
4545
{
46+
if (! $this->isEnabled()) {
47+
return;
48+
}
49+
4650
try {
4751
$to = $this->getTo($notifiable, $notification);
4852
$message = $this->getMessage($notifiable, $notification);
@@ -88,6 +92,20 @@ protected function getMessage($notifiable, Notification $notification)
8892
return $notification->toTwilio($notifiable);
8993
}
9094

95+
/**
96+
* Check if twilio is enabled.
97+
*
98+
* @return bool
99+
*/
100+
protected function isEnabled()
101+
{
102+
if (is_null($this->twilio->config)) {
103+
return true;
104+
}
105+
106+
return $this->twilio->config->enabled();
107+
}
108+
91109
/**
92110
* Get the address to send a notification to.
93111
*

src/TwilioConfig.php

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ public function __construct(array $config)
1515
$this->config = $config;
1616
}
1717

18+
public function enabled()
19+
{
20+
return $this->config['enabled'] ?? true;
21+
}
22+
1823
public function usingUsernamePasswordAuth(): bool
1924
{
2025
return $this->getUsername() !== null && $this->getPassword() !== null && $this->getAccountSid() !== null;

tests/Integration/BaseIntegrationTest.php

+1-1
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

+17
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,23 @@ 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+
$this->dispatcher->shouldNotReceive('dispatch');
50+
51+
$result = $this->channel->send($notifiable, $notification);
52+
53+
$this->assertNull($result);
54+
}
55+
3956
/** @test */
4057
public function it_will_not_send_a_message_without_known_receiver()
4158
{

0 commit comments

Comments
 (0)