From 37a859f81ea0bbbcb4c0c6fdb5cef6108877d7b0 Mon Sep 17 00:00:00 2001 From: ajcastro Date: Tue, 8 Jun 2021 22:25:31 +0800 Subject: [PATCH 01/25] Add enabled config --- config/twilio-notification-channel.php | 1 + src/TwilioChannel.php | 4 ++++ src/TwilioConfig.php | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/config/twilio-notification-channel.php b/config/twilio-notification-channel.php index 04e69c6..84b9681 100644 --- a/config/twilio-notification-channel.php +++ b/config/twilio-notification-channel.php @@ -1,6 +1,7 @@ env('TWILIO_ENABLED', true), 'username' => env('TWILIO_USERNAME'), // optional when using auth token 'password' => env('TWILIO_PASSWORD'), // optional when using auth token 'auth_token' => env('TWILIO_AUTH_TOKEN'), // optional when using username and password diff --git a/src/TwilioChannel.php b/src/TwilioChannel.php index e5cc8f9..94345b6 100755 --- a/src/TwilioChannel.php +++ b/src/TwilioChannel.php @@ -43,6 +43,10 @@ public function __construct(Twilio $twilio, Dispatcher $events) */ public function send($notifiable, Notification $notification) { + if (! $this->twilio->config->enabled()) { + return; + } + try { $to = $this->getTo($notifiable, $notification); $message = $notification->toTwilio($notifiable); diff --git a/src/TwilioConfig.php b/src/TwilioConfig.php index 5334258..63599ea 100644 --- a/src/TwilioConfig.php +++ b/src/TwilioConfig.php @@ -15,6 +15,11 @@ public function __construct(array $config) $this->config = $config; } + public function enabled() + { + return $this->config['enabled']; + } + public function usingUsernamePasswordAuth(): bool { return $this->getUsername() !== null && $this->getPassword() !== null && $this->getAccountSid() !== null; From 220c067df32b9a974823d3418d295d850b9bc7e0 Mon Sep 17 00:00:00 2001 From: ajcastro Date: Tue, 8 Jun 2021 23:00:37 +0800 Subject: [PATCH 02/25] Add test and fixes --- src/TwilioChannel.php | 16 +++++++++++++++- src/TwilioConfig.php | 2 +- tests/Integration/BaseIntegrationTest.php | 2 +- tests/Unit/TwilioChannelTest.php | 15 +++++++++++++++ 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/TwilioChannel.php b/src/TwilioChannel.php index 94345b6..7a8fc78 100755 --- a/src/TwilioChannel.php +++ b/src/TwilioChannel.php @@ -43,7 +43,7 @@ public function __construct(Twilio $twilio, Dispatcher $events) */ public function send($notifiable, Notification $notification) { - if (! $this->twilio->config->enabled()) { + if (! $this->isEnabled()) { return; } @@ -79,6 +79,20 @@ public function send($notifiable, Notification $notification) } } + /** + * Check if twilio is enabled. + * + * @return boolean + */ + protected function isEnabled() + { + if (is_null($this->twilio->config)) { + return true; + } + + return $this->twilio->config->enabled(); + } + /** * Get the address to send a notification to. * diff --git a/src/TwilioConfig.php b/src/TwilioConfig.php index 63599ea..3d839e1 100644 --- a/src/TwilioConfig.php +++ b/src/TwilioConfig.php @@ -17,7 +17,7 @@ public function __construct(array $config) public function enabled() { - return $this->config['enabled']; + return $this->config['enabled'] ?? true; } public function usingUsernamePasswordAuth(): bool diff --git a/tests/Integration/BaseIntegrationTest.php b/tests/Integration/BaseIntegrationTest.php index 698b4af..4d8093b 100644 --- a/tests/Integration/BaseIntegrationTest.php +++ b/tests/Integration/BaseIntegrationTest.php @@ -5,7 +5,7 @@ namespace NotificationChannels\Twilio\Tests\Integration; use NotificationChannels\Twilio\TwilioProvider; -use Orchestra\Testbench\TestCase; +use PHPUnit\Framework\TestCase; abstract class BaseIntegrationTest extends TestCase { diff --git a/tests/Unit/TwilioChannelTest.php b/tests/Unit/TwilioChannelTest.php index 54c1063..ce9b0c5 100644 --- a/tests/Unit/TwilioChannelTest.php +++ b/tests/Unit/TwilioChannelTest.php @@ -36,6 +36,21 @@ public function setUp(): void $this->channel = new TwilioChannel($this->twilio, $this->dispatcher); } + /** @test */ + public function it_will_not_send_a_message_if_not_enabled() + { + $notifiable = new Notifiable(); + $notification = Mockery::mock(Notification::class); + + $this->twilio->config = new TwilioConfig([ + 'enabled' => false, + ]); + + $result = $this->channel->send($notifiable, $notification); + + $this->assertNull($result); + } + /** @test */ public function it_will_not_send_a_message_without_known_receiver() { From 0b4a332d0d0d3b75217aa1c78d96fbb721948f20 Mon Sep 17 00:00:00 2001 From: ajcastro Date: Tue, 8 Jun 2021 23:05:37 +0800 Subject: [PATCH 03/25] Fix --- tests/Unit/TwilioChannelTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Unit/TwilioChannelTest.php b/tests/Unit/TwilioChannelTest.php index ce9b0c5..f5ce1f5 100644 --- a/tests/Unit/TwilioChannelTest.php +++ b/tests/Unit/TwilioChannelTest.php @@ -46,6 +46,8 @@ public function it_will_not_send_a_message_if_not_enabled() 'enabled' => false, ]); + $this->dispatcher->shouldNotReceive('dispatch'); + $result = $this->channel->send($notifiable, $notification); $this->assertNull($result); From 5daeb27126d3108dc37e3450133f08bdb915e399 Mon Sep 17 00:00:00 2001 From: ajcastro Date: Tue, 8 Jun 2021 23:06:43 +0800 Subject: [PATCH 04/25] Fix style --- src/TwilioChannel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TwilioChannel.php b/src/TwilioChannel.php index 7a8fc78..046172a 100755 --- a/src/TwilioChannel.php +++ b/src/TwilioChannel.php @@ -82,7 +82,7 @@ public function send($notifiable, Notification $notification) /** * Check if twilio is enabled. * - * @return boolean + * @return bool */ protected function isEnabled() { From a50563bf4c5e219abf1ec22197c62f6c35a4568e Mon Sep 17 00:00:00 2001 From: Matt Isenhower Date: Tue, 27 Jun 2023 15:31:39 -0700 Subject: [PATCH 05/25] Enable overriding the Twilio message source --- src/TwilioChannel.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/TwilioChannel.php b/src/TwilioChannel.php index e5cc8f9..0d2c8ba 100755 --- a/src/TwilioChannel.php +++ b/src/TwilioChannel.php @@ -45,7 +45,7 @@ public function send($notifiable, Notification $notification) { try { $to = $this->getTo($notifiable, $notification); - $message = $notification->toTwilio($notifiable); + $message = $this->getMessage($notifiable, $notification); $useSender = $this->canReceiveAlphanumericSender($notifiable); if (is_string($message)) { @@ -75,6 +75,19 @@ public function send($notifiable, Notification $notification) } } + /** + * Get the message to send. + * + * @param mixed $notifiable + * @param Notification $notification + * + * @return mixed + */ + protected function getMessage($notifiable, Notification $notification) + { + return $notification->toTwilio($notifiable); + } + /** * Get the address to send a notification to. * From 4abe9b091b8eaa41514c36bd8557bb39e1470a5c Mon Sep 17 00:00:00 2001 From: Philip Iezzi Date: Sun, 17 Nov 2024 22:22:10 +0100 Subject: [PATCH 06/25] Drop Laravel 7-10 Updated CI workflow (while testing is still greatly broken) --- .github/workflows/ci.yml | 44 +++++++++++++++++++++ .github/workflows/php.yml | 48 ----------------------- .gitignore | 3 ++ composer.json | 23 +++++------ tests/Integration/BaseIntegrationTest.php | 4 +- 5 files changed, 61 insertions(+), 61 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/php.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..29eac39 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,44 @@ +name: CI + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + max-parallel: 15 + fail-fast: false + matrix: + php: [8.3, 8.2] + laravel: [11.*] + stability: [prefer-lowest, prefer-stable] + include: + - laravel: 11.* + testbench: 9.* + + name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: mbstring, xdebug + coverage: xdebug + + - name: Install dependencies + run: | + composer require "illuminate/support:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update + composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-suggest + + - name: Lint composer.json + run: composer validate + + - name: Run Tests + run: composer test:unit + + - name: Run Integration Tests + run: composer test:integration diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml deleted file mode 100644 index a53e546..0000000 --- a/.github/workflows/php.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: PHP - -on: - - push - - pull_request - -jobs: - run: - runs-on: ubuntu-latest - - strategy: - max-parallel: 15 - fail-fast: false - matrix: - laravel-version: ['10.*', '11.0', ^8.0, ^9.0] - php-version: ['8.0', '8.1', '8.2'] - exclude: - - laravel-version: 11.* - php-version: '8.0' - - laravel-version: 11.* - php-version: '8.1' - - name: PHP ${{ matrix.php-version }} on Laravel ${{ matrix.laravel-version }} - - steps: - - name: Checkout - uses: actions/checkout@master - - - name: Setup PHP - uses: shivammathur/setup-php@master - with: - php-version: ${{ matrix.php-version }} - extension-csv: mbstring, xdebug - coverage: xdebug - - - name: Install dependencies - run: | - composer require --no-update --no-interaction "illuminate/support:${{ matrix.laravel-version }}" - composer update --no-interaction --prefer-dist --no-suggest - - - name: Lint composer.json - run: composer validate - - - name: Run Tests - run: composer test:unit - - - name: Run Integration Tests - run: composer test:integration diff --git a/.gitignore b/.gitignore index 9e22638..98352d0 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,6 @@ phpunit.phar # build build + +# laravel/pint +.pint.cache.json diff --git a/composer.json b/composer.json index 2724c12..c282693 100644 --- a/composer.json +++ b/composer.json @@ -29,17 +29,18 @@ } ], "require": { - "php": ">=7.2|^8.0", - "twilio/sdk": "~6.0|^7.16", - "illuminate/notifications": "^7.0 || ^8.0 || ^9.0 || ^10.0|^11.0", - "illuminate/support": "^7.0 || ^8.0 || ^9.0 || ^10.0|^11.0", - "illuminate/events": "^7.0 || ^8.0 || ^9.0 || ^10.0|^11.0", - "illuminate/queue": "^7.0 || ^8.0 || ^9.0 || ^10.0|^11.0" + "php": "^8.2", + "twilio/sdk": "^7.16", + "illuminate/notifications": "^11.0", + "illuminate/support": "^11.0", + "illuminate/events": "^11.0", + "illuminate/queue": "^11.0" }, "require-dev": { - "mockery/mockery": "^1.3", - "phpunit/phpunit": "^8.5|^9.5|^10.5", - "orchestra/testbench": "^5.0 || ^6.0 || ^7.0 || ^8.0|^9.0" + "laravel/pint": "^1.18", + "mockery/mockery": "^1.0", + "orchestra/testbench": "^9.0", + "phpunit/phpunit": "^10.5" }, "autoload": { "psr-4": { @@ -53,8 +54,8 @@ }, "scripts": { "test": "vendor/bin/phpunit", - "test:unit": "phpunit --verbose --testsuite Unit", - "test:integration": "phpunit --verbose --testsuite Integration" + "test:unit": "phpunit --testsuite Unit", + "test:integration": "phpunit --testsuite Integration" }, "config": { "sort-packages": true diff --git a/tests/Integration/BaseIntegrationTest.php b/tests/Integration/BaseIntegrationTest.php index 4d8093b..141844d 100644 --- a/tests/Integration/BaseIntegrationTest.php +++ b/tests/Integration/BaseIntegrationTest.php @@ -5,9 +5,9 @@ namespace NotificationChannels\Twilio\Tests\Integration; use NotificationChannels\Twilio\TwilioProvider; -use PHPUnit\Framework\TestCase; +use Orchestra\Testbench\TestCase; -abstract class BaseIntegrationTest extends TestCase +class BaseIntegrationTest extends TestCase { protected function getPackageProviders($app) { From 8759f4f2c9f6c89d869dd1d00984eecb7df7fc64 Mon Sep 17 00:00:00 2001 From: Philip Iezzi Date: Sun, 17 Nov 2024 22:43:10 +0100 Subject: [PATCH 07/25] Added Pint and fixed PHP syntax --- pint.json | 13 +++++++++++ src/Twilio.php | 28 +++++------------------- src/TwilioCallMessage.php | 7 ++---- src/TwilioChannel.php | 14 ++++-------- src/TwilioConfig.php | 3 --- src/TwilioMessage.php | 9 -------- src/TwilioMmsMessage.php | 1 - src/TwilioProvider.php | 6 +----- src/TwilioSmsMessage.php | 11 ---------- tests/Unit/IntegrationTest.php | 10 ++++----- tests/Unit/TwilioCallMessageTest.php | 2 +- tests/Unit/TwilioChannelTest.php | 32 +++++++++++----------------- tests/Unit/TwilioMmsMessageTest.php | 2 +- tests/Unit/TwilioSmsMessageTest.php | 2 +- tests/Unit/TwilioTest.php | 6 ++---- 15 files changed, 48 insertions(+), 98 deletions(-) create mode 100644 pint.json diff --git a/pint.json b/pint.json new file mode 100644 index 0000000..bc95b72 --- /dev/null +++ b/pint.json @@ -0,0 +1,13 @@ +{ + "preset": "laravel", + "rules": { + "blank_line_before_statement": false, + "binary_operator_spaces": false, + "phpdoc_separation": false, + "modernize_strpos": true + }, + "exclude": [ + "node_modules" + ], + "cache-file": ".pint.cache.json" +} diff --git a/src/Twilio.php b/src/Twilio.php index 76b6d62..ba5014e 100644 --- a/src/Twilio.php +++ b/src/Twilio.php @@ -25,9 +25,6 @@ public function __construct(TwilioService $twilioService, TwilioConfig $config) /** * Send a TwilioMessage to the a phone number. * - * @param TwilioMessage $message - * @param string|null $to - * @param bool $useAlphanumericSender * * @return mixed * @throws TwilioException @@ -53,10 +50,7 @@ public function sendMessage(TwilioMessage $message, ?string $to, bool $useAlphan /** * Send an sms message using the Twilio Service. * - * @param TwilioSmsMessage $message - * @param string|null $to * - * @return MessageInstance * @throws CouldNotSendNotification * @throws TwilioException */ @@ -64,7 +58,7 @@ protected function sendSmsMessage(TwilioSmsMessage $message, ?string $to): Messa { $debugTo = $this->config->getDebugTo(); - if (!empty($debugTo)) { + if (! empty($debugTo)) { $to = $debugTo; } @@ -77,7 +71,7 @@ protected function sendSmsMessage(TwilioSmsMessage $message, ?string $to): Messa } if ($this->config->isShortenUrlsEnabled()) { - $params['ShortenUrls'] = "true"; + $params['ShortenUrls'] = 'true'; } if ($from = $this->getFrom($message)) { @@ -110,10 +104,7 @@ protected function sendSmsMessage(TwilioSmsMessage $message, ?string $to): Messa /** * Make a call using the Twilio Service. * - * @param TwilioCallMessage $message - * @param string|null $to * - * @return CallInstance * @throws TwilioException * @throws CouldNotSendNotification */ @@ -151,9 +142,6 @@ protected function makeCall(TwilioCallMessage $message, ?string $to): CallInstan /** * Get the from address from message, or config. - * - * @param TwilioMessage $message - * @return string|null */ protected function getFrom(TwilioMessage $message): ?string { @@ -162,9 +150,6 @@ protected function getFrom(TwilioMessage $message): ?string /** * Get the messaging service SID from message, or config. - * - * @param TwilioSmsMessage $message - * @return string|null */ protected function getMessagingServiceSid(TwilioSmsMessage $message): ?string { @@ -173,8 +158,6 @@ protected function getMessagingServiceSid(TwilioSmsMessage $message): ?string /** * Get the alphanumeric sender from config, if one exists. - * - * @return string|null */ protected function getAlphanumericSender(): ?string { @@ -182,10 +165,9 @@ protected function getAlphanumericSender(): ?string } /** - * @param array $params - * @param TwilioMessage $message - * @param array $optionalParams - * @return Twilio + * @param array $params + * @param TwilioMessage $message + * @param array $optionalParams */ protected function fillOptionalParams(&$params, $message, $optionalParams): self { diff --git a/src/TwilioCallMessage.php b/src/TwilioCallMessage.php index da4b160..a47310d 100755 --- a/src/TwilioCallMessage.php +++ b/src/TwilioCallMessage.php @@ -5,6 +5,7 @@ class TwilioCallMessage extends TwilioMessage { public const STATUS_CANCELED = 'canceled'; + public const STATUS_COMPLETED = 'completed'; /** @@ -30,7 +31,6 @@ class TwilioCallMessage extends TwilioMessage /** * Set the message url. * - * @param string $url * @return $this */ public function url(string $url): self @@ -43,7 +43,7 @@ public function url(string $url): self /** * Set the message url request method. * - * @param string $method + * @param string $method * @return $this */ public function method($method): self @@ -56,7 +56,6 @@ public function method($method): self /** * Set the status for the current calls. * - * @param string $status * @return $this */ public function status(string $status): self @@ -69,7 +68,6 @@ public function status(string $status): self /** * Set the fallback url. * - * @param string $fallbackUrl * @return $this */ public function fallbackUrl(string $fallbackUrl): self @@ -82,7 +80,6 @@ public function fallbackUrl(string $fallbackUrl): self /** * Set the fallback url request method. * - * @param string $fallbackMethod * @return $this */ public function fallbackMethod(string $fallbackMethod): self diff --git a/src/TwilioChannel.php b/src/TwilioChannel.php index ea9d3b3..f5c77db 100755 --- a/src/TwilioChannel.php +++ b/src/TwilioChannel.php @@ -22,9 +22,6 @@ class TwilioChannel /** * TwilioChannel constructor. - * - * @param Twilio $twilio - * @param Dispatcher $events */ public function __construct(Twilio $twilio, Dispatcher $events) { @@ -35,8 +32,7 @@ public function __construct(Twilio $twilio, Dispatcher $events) /** * Send the given notification. * - * @param mixed $notifiable - * @param Notification $notification + * @param mixed $notifiable * * @return mixed * @throws Exception @@ -82,8 +78,7 @@ public function send($notifiable, Notification $notification) /** * Get the message to send. * - * @param mixed $notifiable - * @param Notification $notification + * @param mixed $notifiable * * @return mixed */ @@ -109,8 +104,8 @@ protected function isEnabled() /** * Get the address to send a notification to. * - * @param mixed $notifiable - * @param Notification|null $notification + * @param mixed $notifiable + * @param Notification|null $notification * * @return mixed * @throws CouldNotSendNotification @@ -133,7 +128,6 @@ protected function getTo($notifiable, $notification = null) /** * Get the alphanumeric sender. * - * @param $notifiable * * @return mixed|null * @throws CouldNotSendNotification diff --git a/src/TwilioConfig.php b/src/TwilioConfig.php index 175b6a7..6752f15 100644 --- a/src/TwilioConfig.php +++ b/src/TwilioConfig.php @@ -7,9 +7,6 @@ class TwilioConfig /** @var array */ private $config; - /** - * @param array $config - */ public function __construct(array $config) { $this->config = $config; diff --git a/src/TwilioMessage.php b/src/TwilioMessage.php index 8e44f8a..faf1d06 100755 --- a/src/TwilioMessage.php +++ b/src/TwilioMessage.php @@ -30,7 +30,6 @@ abstract class TwilioMessage /** * Create a message object. - * @param string $content * @return static */ public static function create(string $content = ''): self @@ -40,8 +39,6 @@ public static function create(string $content = ''): self /** * Create a new message instance. - * - * @param string $content */ public function __construct(string $content = '') { @@ -51,7 +48,6 @@ public function __construct(string $content = '') /** * Set the message content. * - * @param string $content * @return $this */ public function content(string $content): self @@ -64,7 +60,6 @@ public function content(string $content): self /** * Set the phone number the message should be sent from. * - * @param string $from * @return $this */ public function from(string $from): self @@ -76,8 +71,6 @@ public function from(string $from): self /** * Get the from address. - * - * @return string|null */ public function getFrom(): ?string { @@ -87,7 +80,6 @@ public function getFrom(): ?string /** * Set the status callback. * - * @param string $statusCallback * @return $this */ public function statusCallback(string $statusCallback): self @@ -100,7 +92,6 @@ public function statusCallback(string $statusCallback): self /** * Set the status callback request method. * - * @param string $statusCallbackMethod * @return $this */ public function statusCallbackMethod(string $statusCallbackMethod): self diff --git a/src/TwilioMmsMessage.php b/src/TwilioMmsMessage.php index 1bb2dd5..ae5d367 100755 --- a/src/TwilioMmsMessage.php +++ b/src/TwilioMmsMessage.php @@ -12,7 +12,6 @@ class TwilioMmsMessage extends TwilioSmsMessage /** * Set the message media url. * - * @param string $url * @return $this */ public function mediaUrl(string $url): self diff --git a/src/TwilioProvider.php b/src/TwilioProvider.php index 19020ef..2d827ea 100755 --- a/src/TwilioProvider.php +++ b/src/TwilioProvider.php @@ -14,9 +14,7 @@ class TwilioProvider extends ServiceProvider implements DeferrableProvider /** * Bootstrap the application services. */ - public function boot() - { - } + public function boot() {} /** * Register the application services. @@ -65,8 +63,6 @@ public function register() /** * Get the services provided by the provider. - * - * @return array */ public function provides(): array { diff --git a/src/TwilioSmsMessage.php b/src/TwilioSmsMessage.php index f97c258..619259d 100755 --- a/src/TwilioSmsMessage.php +++ b/src/TwilioSmsMessage.php @@ -41,8 +41,6 @@ class TwilioSmsMessage extends TwilioMessage /** * Get the from address of this message. - * - * @return null|string */ public function getFrom(): ?string { @@ -60,7 +58,6 @@ public function getFrom(): ?string /** * Set the messaging service SID. * - * @param string $messagingServiceSid * @return $this */ public function messagingServiceSid(string $messagingServiceSid): self @@ -72,8 +69,6 @@ public function messagingServiceSid(string $messagingServiceSid): self /** * Get the messaging service SID of this message. - * - * @return null|string */ public function getMessagingServiceSid(): ?string { @@ -83,7 +78,6 @@ public function getMessagingServiceSid(): ?string /** * Set the alphanumeric sender. * - * @param string $sender * @return $this */ public function sender(string $sender): self @@ -96,7 +90,6 @@ public function sender(string $sender): self /** * Set application SID for the message status callback. * - * @param string $applicationSid * @return $this */ public function applicationSid(string $applicationSid): self @@ -109,7 +102,6 @@ public function applicationSid(string $applicationSid): self /** * Set force delivery (Deliver message without validation). * - * @param bool $forceDelivery * @return $this */ public function forceDelivery(bool $forceDelivery): self @@ -122,7 +114,6 @@ public function forceDelivery(bool $forceDelivery): self /** * Set the max price (in USD dollars). * - * @param float $maxPrice * @return $this */ public function maxPrice(float $maxPrice): self @@ -135,7 +126,6 @@ public function maxPrice(float $maxPrice): self /** * Set the provide feedback option. * - * @param bool $provideFeedback * @return $this */ public function provideFeedback(bool $provideFeedback): self @@ -148,7 +138,6 @@ public function provideFeedback(bool $provideFeedback): self /** * Set the validity period (in seconds). * - * @param int $validityPeriodSeconds * * @return $this */ diff --git a/tests/Unit/IntegrationTest.php b/tests/Unit/IntegrationTest.php index f2fbcf9..27c248b 100644 --- a/tests/Unit/IntegrationTest.php +++ b/tests/Unit/IntegrationTest.php @@ -57,7 +57,7 @@ public function it_can_send_a_sms_message() 'body' => 'Message text', ]); - $channel->send(new NotifiableWithAttribute(), $this->notification); + $channel->send(new NotifiableWithAttribute, $this->notification); } /** @test */ @@ -79,7 +79,7 @@ public function it_can_send_a_sms_message_using_service() 'messagingServiceSid' => '0123456789', ]); - $channel->send(new NotifiableWithAttribute(), $this->notification); + $channel->send(new NotifiableWithAttribute, $this->notification); } /** @test */ @@ -101,7 +101,7 @@ public function it_can_send_a_sms_message_using_url_shortener() 'ShortenUrls' => 'true', ]); - $channel->send(new NotifiableWithAttribute(), $this->notification); + $channel->send(new NotifiableWithAttribute, $this->notification); } /** @test */ @@ -122,7 +122,7 @@ public function it_can_send_a_sms_message_using_alphanumeric_sender() 'body' => 'Message text', ]); - $channel->send(new NotifiableWithAlphanumericSender(), $this->notification); + $channel->send(new NotifiableWithAlphanumericSender, $this->notification); } /** @test */ @@ -141,7 +141,7 @@ public function it_can_make_a_call() 'url' => 'http://example.com', ]); - $channel->send(new NotifiableWithAttribute(), $this->notification); + $channel->send(new NotifiableWithAttribute, $this->notification); } protected function smsMessageWillBeSentToTwilioWith(...$args) diff --git a/tests/Unit/TwilioCallMessageTest.php b/tests/Unit/TwilioCallMessageTest.php index 38ee9f7..c4f65e2 100644 --- a/tests/Unit/TwilioCallMessageTest.php +++ b/tests/Unit/TwilioCallMessageTest.php @@ -13,7 +13,7 @@ public function setUp(): void { parent::setUp(); - $this->message = new TwilioCallMessage(); + $this->message = new TwilioCallMessage; } /** @test */ diff --git a/tests/Unit/TwilioChannelTest.php b/tests/Unit/TwilioChannelTest.php index f5ce1f5..9890a44 100644 --- a/tests/Unit/TwilioChannelTest.php +++ b/tests/Unit/TwilioChannelTest.php @@ -39,7 +39,7 @@ public function setUp(): void /** @test */ public function it_will_not_send_a_message_if_not_enabled() { - $notifiable = new Notifiable(); + $notifiable = new Notifiable; $notification = Mockery::mock(Notification::class); $this->twilio->config = new TwilioConfig([ @@ -56,7 +56,7 @@ public function it_will_not_send_a_message_if_not_enabled() /** @test */ public function it_will_not_send_a_message_without_known_receiver() { - $notifiable = new Notifiable(); + $notifiable = new Notifiable; $notification = Mockery::mock(Notification::class); $this->twilio->config = new TwilioConfig([ @@ -77,7 +77,7 @@ public function it_will_not_send_a_message_without_known_receiver() /** @test */ public function it_will_send_a_sms_message_to_the_result_of_the_route_method_of_the_notifiable() { - $notifiable = new NotifiableWithMethod(); + $notifiable = new NotifiableWithMethod; $notification = Mockery::mock(Notification::class); $message = new TwilioSmsMessage('Message text'); @@ -93,7 +93,7 @@ public function it_will_send_a_sms_message_to_the_result_of_the_route_method_of_ /** @test */ public function it_will_make_a_call_to_the_phone_number_attribute_of_the_notifiable() { - $notifiable = new NotifiableWithAttribute(); + $notifiable = new NotifiableWithAttribute; $notification = Mockery::mock(Notification::class); $message = new TwilioCallMessage('http://example.com'); @@ -109,7 +109,7 @@ public function it_will_make_a_call_to_the_phone_number_attribute_of_the_notifia /** @test */ public function it_will_convert_a_string_to_a_sms_message() { - $notifiable = new NotifiableWithAttribute(); + $notifiable = new NotifiableWithAttribute; $notification = Mockery::mock(Notification::class); $notification->shouldReceive('toTwilio')->andReturn('Message text'); @@ -124,7 +124,7 @@ public function it_will_convert_a_string_to_a_sms_message() /** @test */ public function it_will_fire_an_event_in_case_of_an_invalid_message() { - $notifiable = new NotifiableWithAttribute(); + $notifiable = new NotifiableWithAttribute; $notification = Mockery::mock(Notification::class); $this->twilio->config = new TwilioConfig([ @@ -146,7 +146,7 @@ public function it_will_fire_an_event_in_case_of_an_invalid_message() /** @test */ public function it_will_ignore_specific_error_codes() { - $notifiable = new NotifiableWithAttribute(); + $notifiable = new NotifiableWithAttribute; $notification = Mockery::mock(Notification::class); $this->twilio->config = new TwilioConfig([ @@ -170,7 +170,7 @@ public function it_will_ignore_specific_error_codes() /** @test */ public function it_will_rethrow_non_ignored_error_codes() { - $notifiable = new NotifiableWithAttribute(); + $notifiable = new NotifiableWithAttribute; $notification = Mockery::mock(Notification::class); $this->twilio->config = new TwilioConfig([ @@ -196,7 +196,7 @@ public function it_will_rethrow_non_ignored_error_codes() /** @test */ public function it_will_ignore_all_error_codes() { - $notifiable = new NotifiableWithAttribute(); + $notifiable = new NotifiableWithAttribute; $notification = Mockery::mock(Notification::class); $this->twilio->config = new TwilioConfig([ @@ -218,7 +218,7 @@ public function it_will_ignore_all_error_codes() /** @test */ public function it_will_send_using_alphanumeric_if_notifiable_can_receive() { - $notifiable = new NotifiableWithAlphanumericSender(); + $notifiable = new NotifiableWithAlphanumericSender; $notification = Mockery::mock(Notification::class); $message = new TwilioSmsMessage('Message text'); @@ -236,9 +236,7 @@ class Notifiable { public $phone_number = null; - public function routeNotificationFor() - { - } + public function routeNotificationFor() {} } class NotifiableWithMethod @@ -253,18 +251,14 @@ class NotifiableWithAttribute { public $phone_number = '+22222222222'; - public function routeNotificationFor() - { - } + public function routeNotificationFor() {} } class NotifiableWithAlphanumericSender { public $phone_number = '+33333333333'; - public function routeNotificationFor() - { - } + public function routeNotificationFor() {} public function canReceiveAlphanumericSender() { diff --git a/tests/Unit/TwilioMmsMessageTest.php b/tests/Unit/TwilioMmsMessageTest.php index c004f5c..4cd5056 100644 --- a/tests/Unit/TwilioMmsMessageTest.php +++ b/tests/Unit/TwilioMmsMessageTest.php @@ -10,7 +10,7 @@ public function setUp(): void { parent::setUp(); - $this->message = new TwilioMmsMessage(); + $this->message = new TwilioMmsMessage; } /** @test */ diff --git a/tests/Unit/TwilioSmsMessageTest.php b/tests/Unit/TwilioSmsMessageTest.php index 84d719d..a6d6062 100644 --- a/tests/Unit/TwilioSmsMessageTest.php +++ b/tests/Unit/TwilioSmsMessageTest.php @@ -10,7 +10,7 @@ public function setUp(): void { parent::setUp(); - $this->message = new TwilioSmsMessage(); + $this->message = new TwilioSmsMessage; } /** @test */ diff --git a/tests/Unit/TwilioTest.php b/tests/Unit/TwilioTest.php index b32ae2c..60c9c23 100644 --- a/tests/Unit/TwilioTest.php +++ b/tests/Unit/TwilioTest.php @@ -246,7 +246,7 @@ public function it_will_throw_an_exception_in_case_of_an_unrecognized_message_ob $this->expectException(CouldNotSendNotification::class); $this->expectExceptionMessage('Notification was not sent. Message object class'); - $this->twilio->sendMessage(new InvalidMessage(), null); + $this->twilio->sendMessage(new InvalidMessage, null); } /** @test */ @@ -292,6 +292,4 @@ public function it_should_use_universal_to() } } -class InvalidMessage extends TwilioMessage -{ -} +class InvalidMessage extends TwilioMessage {} From 21649880252465a3a2024e4be2ebfac12d879bf5 Mon Sep 17 00:00:00 2001 From: Philip Iezzi Date: Sun, 17 Nov 2024 23:08:17 +0100 Subject: [PATCH 08/25] Use modern syntax: Constructor property promotion, improved types --- config/twilio-notification-channel.php | 4 +-- src/Twilio.php | 28 ++++----------- src/TwilioCallMessage.php | 33 +++-------------- src/TwilioChannel.php | 40 +++++---------------- src/TwilioConfig.php | 14 +++----- src/TwilioMessage.php | 41 +++++---------------- src/TwilioMmsMessage.php | 7 +--- src/TwilioProvider.php | 2 +- src/TwilioSmsMessage.php | 50 ++++---------------------- 9 files changed, 44 insertions(+), 175 deletions(-) diff --git a/config/twilio-notification-channel.php b/config/twilio-notification-channel.php index 33f5d11..c6a322c 100644 --- a/config/twilio-notification-channel.php +++ b/config/twilio-notification-channel.php @@ -1,7 +1,7 @@ env('TWILIO_ENABLED', true), + 'enabled' => (bool) env('TWILIO_ENABLED', true), 'username' => env('TWILIO_USERNAME'), // optional when using auth token 'password' => env('TWILIO_PASSWORD'), // optional when using auth token 'auth_token' => env('TWILIO_AUTH_TOKEN'), // optional when using username and password @@ -9,7 +9,7 @@ 'from' => env('TWILIO_FROM'), // optional 'alphanumeric_sender' => env('TWILIO_ALPHA_SENDER'), - 'shorten_urls' => env('TWILIO_SHORTEN_URLS', false), // optional, enable twilio URL shortener + 'shorten_urls' => (bool) env('TWILIO_SHORTEN_URLS', false), // optional, enable twilio URL shortener /** * See https://www.twilio.com/docs/sms/services. diff --git a/src/Twilio.php b/src/Twilio.php index ba5014e..a764712 100644 --- a/src/Twilio.php +++ b/src/Twilio.php @@ -10,27 +10,18 @@ class Twilio { - /** @var TwilioService */ - protected $twilioService; - - /** @var TwilioConfig */ - public $config; - - public function __construct(TwilioService $twilioService, TwilioConfig $config) - { - $this->twilioService = $twilioService; - $this->config = $config; - } + public function __construct( + protected TwilioService $twilioService, + public TwilioConfig $config + ) {} /** - * Send a TwilioMessage to the a phone number. + * Send a TwilioMessage to a phone number. * - * - * @return mixed * @throws TwilioException * @throws CouldNotSendNotification */ - public function sendMessage(TwilioMessage $message, ?string $to, bool $useAlphanumericSender = false) + public function sendMessage(TwilioMessage $message, ?string $to, bool $useAlphanumericSender = false): CallInstance|MessageInstance { if ($message instanceof TwilioSmsMessage) { if ($useAlphanumericSender && $sender = $this->getAlphanumericSender()) { @@ -164,12 +155,7 @@ protected function getAlphanumericSender(): ?string return $this->config->getAlphanumericSender(); } - /** - * @param array $params - * @param TwilioMessage $message - * @param array $optionalParams - */ - protected function fillOptionalParams(&$params, $message, $optionalParams): self + protected function fillOptionalParams(array &$params, TwilioMessage $message, array $optionalParams): self { foreach ($optionalParams as $optionalParam) { if ($message->$optionalParam) { diff --git a/src/TwilioCallMessage.php b/src/TwilioCallMessage.php index a47310d..2d81eeb 100755 --- a/src/TwilioCallMessage.php +++ b/src/TwilioCallMessage.php @@ -8,30 +8,16 @@ class TwilioCallMessage extends TwilioMessage public const STATUS_COMPLETED = 'completed'; - /** - * @var null|string - */ - public $method; + public ?string $method = null; - /** - * @var null|string - */ - public $status; + public ?string $status = null; - /** - * @var null|string - */ - public $fallbackUrl; + public ?string $fallbackUrl = null; - /** - * @var null|string - */ - public $fallbackMethod; + public ?string $fallbackMethod = null; /** * Set the message url. - * - * @return $this */ public function url(string $url): self { @@ -42,11 +28,8 @@ public function url(string $url): self /** * Set the message url request method. - * - * @param string $method - * @return $this */ - public function method($method): self + public function method(string $method): self { $this->method = $method; @@ -55,8 +38,6 @@ public function method($method): self /** * Set the status for the current calls. - * - * @return $this */ public function status(string $status): self { @@ -67,8 +48,6 @@ public function status(string $status): self /** * Set the fallback url. - * - * @return $this */ public function fallbackUrl(string $fallbackUrl): self { @@ -79,8 +58,6 @@ public function fallbackUrl(string $fallbackUrl): self /** * Set the fallback url request method. - * - * @return $this */ public function fallbackMethod(string $fallbackMethod): self { diff --git a/src/TwilioChannel.php b/src/TwilioChannel.php index f5c77db..f7c9dbc 100755 --- a/src/TwilioChannel.php +++ b/src/TwilioChannel.php @@ -10,34 +10,18 @@ class TwilioChannel { - /** - * @var Twilio - */ - protected $twilio; - - /** - * @var Dispatcher - */ - protected $events; - - /** - * TwilioChannel constructor. - */ - public function __construct(Twilio $twilio, Dispatcher $events) - { - $this->twilio = $twilio; - $this->events = $events; - } + public function __construct( + protected Twilio $twilio, + protected Dispatcher $events + ) {} /** * Send the given notification. * - * @param mixed $notifiable - * * @return mixed * @throws Exception */ - public function send($notifiable, Notification $notification) + public function send(mixed $notifiable, Notification $notification) { if (! $this->isEnabled()) { return; @@ -78,27 +62,19 @@ public function send($notifiable, Notification $notification) /** * Get the message to send. * - * @param mixed $notifiable - * * @return mixed */ - protected function getMessage($notifiable, Notification $notification) + protected function getMessage(mixed $notifiable, Notification $notification) { return $notification->toTwilio($notifiable); } /** * Check if twilio is enabled. - * - * @return bool */ - protected function isEnabled() + protected function isEnabled(): bool { - if (is_null($this->twilio->config)) { - return true; - } - - return $this->twilio->config->enabled(); + return $this->twilio->config->enabled() ?? true; } /** diff --git a/src/TwilioConfig.php b/src/TwilioConfig.php index 6752f15..2e2bd5e 100644 --- a/src/TwilioConfig.php +++ b/src/TwilioConfig.php @@ -2,17 +2,13 @@ namespace NotificationChannels\Twilio; -class TwilioConfig +readonly class TwilioConfig { - /** @var array */ - private $config; + public function __construct( + private array $config + ) {} - public function __construct(array $config) - { - $this->config = $config; - } - - public function enabled() + public function enabled(): bool { return $this->config['enabled'] ?? true; } diff --git a/src/TwilioMessage.php b/src/TwilioMessage.php index faf1d06..5e317b1 100755 --- a/src/TwilioMessage.php +++ b/src/TwilioMessage.php @@ -4,51 +4,32 @@ abstract class TwilioMessage { - /** - * The message content. - * - * @var string - */ - public $content; - /** * The phone number the message should be sent from. - * - * @var string */ - public $from; + public ?string $from = null; - /** - * @var null|string - */ - public $statusCallback; + public ?string $statusCallback = null; + + public ?string $statusCallbackMethod = null; /** - * @var null|string + * Create a new message instance. */ - public $statusCallbackMethod; + public function __construct( + public string $content = '' + ) {} /** * Create a message object. - * @return static */ public static function create(string $content = ''): self { return new static($content); } - /** - * Create a new message instance. - */ - public function __construct(string $content = '') - { - $this->content = $content; - } - /** * Set the message content. - * - * @return $this */ public function content(string $content): self { @@ -59,8 +40,6 @@ public function content(string $content): self /** * Set the phone number the message should be sent from. - * - * @return $this */ public function from(string $from): self { @@ -79,8 +58,6 @@ public function getFrom(): ?string /** * Set the status callback. - * - * @return $this */ public function statusCallback(string $statusCallback): self { @@ -91,8 +68,6 @@ public function statusCallback(string $statusCallback): self /** * Set the status callback request method. - * - * @return $this */ public function statusCallbackMethod(string $statusCallbackMethod): self { diff --git a/src/TwilioMmsMessage.php b/src/TwilioMmsMessage.php index ae5d367..3e10bde 100755 --- a/src/TwilioMmsMessage.php +++ b/src/TwilioMmsMessage.php @@ -4,15 +4,10 @@ class TwilioMmsMessage extends TwilioSmsMessage { - /** - * @var string|null - */ - public $mediaUrl; + public ?string $mediaUrl = null; /** * Set the message media url. - * - * @return $this */ public function mediaUrl(string $url): self { diff --git a/src/TwilioProvider.php b/src/TwilioProvider.php index 2d827ea..4555c0d 100755 --- a/src/TwilioProvider.php +++ b/src/TwilioProvider.php @@ -19,7 +19,7 @@ public function boot() {} /** * Register the application services. */ - public function register() + public function register(): void { $this->mergeConfigFrom(__DIR__.'/../config/twilio-notification-channel.php', 'twilio-notification-channel'); diff --git a/src/TwilioSmsMessage.php b/src/TwilioSmsMessage.php index 619259d..5479bb1 100755 --- a/src/TwilioSmsMessage.php +++ b/src/TwilioSmsMessage.php @@ -4,40 +4,19 @@ class TwilioSmsMessage extends TwilioMessage { - /** - * @var null|string - */ - public $alphaNumSender; + public ?string $alphaNumSender = null; - /** - * @var null|string - */ - public $messagingServiceSid; + public ?string $messagingServiceSid = null; - /** - * @var null|string - */ - public $applicationSid; + public ?string $applicationSid = null; - /** - * @var null|bool - */ - public $forceDelivery; + public ?bool $forceDelivery = null; - /** - * @var null|float - */ - public $maxPrice; + public ?float $maxPrice = null; - /** - * @var null|bool - */ - public $provideFeedback; + public ?bool $provideFeedback = null; - /** - * @var null|int - */ - public $validityPeriod; + public ?int $validityPeriod = null; /** * Get the from address of this message. @@ -57,8 +36,6 @@ public function getFrom(): ?string /** * Set the messaging service SID. - * - * @return $this */ public function messagingServiceSid(string $messagingServiceSid): self { @@ -77,8 +54,6 @@ public function getMessagingServiceSid(): ?string /** * Set the alphanumeric sender. - * - * @return $this */ public function sender(string $sender): self { @@ -89,8 +64,6 @@ public function sender(string $sender): self /** * Set application SID for the message status callback. - * - * @return $this */ public function applicationSid(string $applicationSid): self { @@ -101,8 +74,6 @@ public function applicationSid(string $applicationSid): self /** * Set force delivery (Deliver message without validation). - * - * @return $this */ public function forceDelivery(bool $forceDelivery): self { @@ -113,8 +84,6 @@ public function forceDelivery(bool $forceDelivery): self /** * Set the max price (in USD dollars). - * - * @return $this */ public function maxPrice(float $maxPrice): self { @@ -125,8 +94,6 @@ public function maxPrice(float $maxPrice): self /** * Set the provide feedback option. - * - * @return $this */ public function provideFeedback(bool $provideFeedback): self { @@ -137,9 +104,6 @@ public function provideFeedback(bool $provideFeedback): self /** * Set the validity period (in seconds). - * - * - * @return $this */ public function validityPeriod(int $validityPeriodSeconds): self { From b68f87c6034fa03497924e302e08f0f050cffa5c Mon Sep 17 00:00:00 2001 From: Philip Iezzi Date: Mon, 18 Nov 2024 00:06:48 +0100 Subject: [PATCH 09/25] Bump twilio/sdk to 8.3 Updated CHANGELOG --- CHANGELOG.md | 12 +++++++++++- README.md | 4 ++++ composer.json | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 881b3ec..189b934 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,16 @@ # Changelog -All notable changes to `twilio` will be documented in this file +All notable changes to `laravel-notification-channels/twilio` will be documented in this file + +## 4.0.0 + +- Bump `twilio/sdk` to 8.3 +- Improved types and use constructor property promotion everywhere. +- Added Pint and fixed PHP syntax. +- Drop support for PHP < 8.2 **BREAKING CHANGE** +- Drop support for Laravel 7.x, 8.x, 9.x, and 10.x **BREAKING CHANGE** +- Enable overriding the Twilio message source [#142](https://github.com/laravel-notification-channels/twilio/pull/142) +- Add enabled config option (`TWILIO_ENABLED`) to disable the channel [#21](https://github.com/laravel-notification-channels/twilio/pull/121) ## 3.0.0 diff --git a/README.md b/README.md index 1eebad4..d42c8b5 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,10 @@ Twilio recommends always using a [Messaging Service](https://www.twilio.com/docs Having issues with SMS? Check Twilio's [best practices](https://www.twilio.com/docs/sms/services/services-best-practices). +## Upgrading from 3.x to 4.x + +We have dropped support for PHP < 8.2 and the minimum Laravel version is now 11. Other than that, there are no breaking changes. + ## Upgrading from 2.x to 3.x If you're upgrading from version `2.x`, you'll need to make sure that your set environment variables match those above diff --git a/composer.json b/composer.json index c282693..643bf95 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ ], "require": { "php": "^8.2", - "twilio/sdk": "^7.16", + "twilio/sdk": "^7.16 || ^8.3", "illuminate/notifications": "^11.0", "illuminate/support": "^11.0", "illuminate/events": "^11.0", From 0df706299fefe4db35901f09ea0427c8357970be Mon Sep 17 00:00:00 2001 From: Philip Iezzi Date: Mon, 18 Nov 2024 11:47:33 +0100 Subject: [PATCH 10/25] Fixing Twilio and TwilioChannel tests --- src/TwilioConfig.php | 4 ++-- tests/Unit/TwilioChannelTest.php | 1 + tests/Unit/TwilioTest.php | 28 ++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/TwilioConfig.php b/src/TwilioConfig.php index 2e2bd5e..653dc08 100644 --- a/src/TwilioConfig.php +++ b/src/TwilioConfig.php @@ -2,10 +2,10 @@ namespace NotificationChannels\Twilio; -readonly class TwilioConfig +class TwilioConfig { public function __construct( - private array $config + private readonly array $config ) {} public function enabled(): bool diff --git a/tests/Unit/TwilioChannelTest.php b/tests/Unit/TwilioChannelTest.php index 9890a44..a5c0495 100644 --- a/tests/Unit/TwilioChannelTest.php +++ b/tests/Unit/TwilioChannelTest.php @@ -31,6 +31,7 @@ public function setUp(): void parent::setUp(); $this->twilio = Mockery::mock(Twilio::class); + $this->twilio->config = new TwilioConfig([]); $this->dispatcher = Mockery::mock(Dispatcher::class); $this->channel = new TwilioChannel($this->twilio, $this->dispatcher); diff --git a/tests/Unit/TwilioTest.php b/tests/Unit/TwilioTest.php index 60c9c23..35f4b49 100644 --- a/tests/Unit/TwilioTest.php +++ b/tests/Unit/TwilioTest.php @@ -67,6 +67,10 @@ public function it_can_send_a_sms_message_to_twilio() ->once() ->andReturn(null); + $this->config->shouldReceive('isShortenUrlsEnabled') + ->once() + ->andReturn(false); + $this->config->shouldReceive('getServiceSid') ->once() ->andReturn(null); @@ -104,6 +108,10 @@ public function it_can_send_a_mms_message_to_twilio() ->once() ->andReturn('+1234567890'); + $this->config->shouldReceive('isShortenUrlsEnabled') + ->once() + ->andReturn(false); + $this->config->shouldReceive('getServiceSid') ->once() ->andReturn(null); @@ -141,6 +149,10 @@ public function it_can_send_a_sms_message_to_twilio_with_alphanumeric_sender() $this->config->shouldNotReceive('getFrom'); + $this->config->shouldReceive('isShortenUrlsEnabled') + ->once() + ->andReturn(false); + $this->config->shouldReceive('getServiceSid') ->once() ->andReturn(null); @@ -169,6 +181,10 @@ public function it_can_send_a_sms_message_to_twilio_with_messaging_service() ->once() ->andReturn('+1234567890'); + $this->config->shouldReceive('isShortenUrlsEnabled') + ->once() + ->andReturn(false); + $this->config->shouldReceive('getServiceSid') ->once() ->andReturn('service_sid'); @@ -201,6 +217,10 @@ public function it_can_send_a_call_to_twilio() $message->fallbackUrl('http://example.com'); $message->fallbackMethod('PUT'); + $this->config->shouldReceive('getDebugTo') + ->once() + ->andReturn('+1111111111'); + $this->twilioService->calls->shouldReceive('create') ->atLeast()->once() ->with('+1111111111', '+2222222222', [ @@ -233,6 +253,10 @@ public function it_will_throw_an_exception_in_case_of_a_missing_from_number() ->once() ->andReturn(null); + $this->config->shouldReceive('isShortenUrlsEnabled') + ->once() + ->andReturn(false); + $this->config->shouldReceive('getServiceSid') ->once() ->andReturn(null); @@ -270,6 +294,10 @@ public function it_should_use_universal_to() ->once() ->andReturn($debugTo); + $this->config->shouldReceive('isShortenUrlsEnabled') + ->once() + ->andReturn(false); + $this->config->shouldReceive('getServiceSid') ->once() ->andReturn(null); From ea628cfdc7b3d51804f8171dd358c918287bea4b Mon Sep 17 00:00:00 2001 From: Philip Iezzi Date: Mon, 18 Nov 2024 12:13:11 +0100 Subject: [PATCH 11/25] Fix more tests --- tests/Integration/TwilioProviderTest.php | 3 ++- .../BaseIntegrationTest.php => IntegrationTestCase.php} | 4 ++-- tests/Unit/IntegrationTest.php | 2 +- tests/Unit/TwilioCallMessageTest.php | 2 +- .../Unit/{TwilioMessageTest.php => TwilioMessageTestCase.php} | 2 +- tests/Unit/TwilioMmsMessageTest.php | 2 +- tests/Unit/TwilioSmsMessageTest.php | 2 +- 7 files changed, 9 insertions(+), 8 deletions(-) rename tests/{Integration/BaseIntegrationTest.php => IntegrationTestCase.php} (68%) rename tests/Unit/{TwilioMessageTest.php => TwilioMessageTestCase.php} (94%) diff --git a/tests/Integration/TwilioProviderTest.php b/tests/Integration/TwilioProviderTest.php index f98f638..ff5a1da 100644 --- a/tests/Integration/TwilioProviderTest.php +++ b/tests/Integration/TwilioProviderTest.php @@ -5,9 +5,10 @@ namespace NotificationChannels\Twilio\Tests\Integration; use NotificationChannels\Twilio\Exceptions\InvalidConfigException; +use NotificationChannels\Twilio\Tests\IntegrationTestCase; use NotificationChannels\Twilio\TwilioChannel; -class TwilioProviderTest extends BaseIntegrationTest +class TwilioProviderTest extends IntegrationTestCase { public function testThatApplicationCannotCreateChannelWithoutConfig() { diff --git a/tests/Integration/BaseIntegrationTest.php b/tests/IntegrationTestCase.php similarity index 68% rename from tests/Integration/BaseIntegrationTest.php rename to tests/IntegrationTestCase.php index 141844d..087ad9a 100644 --- a/tests/Integration/BaseIntegrationTest.php +++ b/tests/IntegrationTestCase.php @@ -2,12 +2,12 @@ declare(strict_types=1); -namespace NotificationChannels\Twilio\Tests\Integration; +namespace NotificationChannels\Twilio\Tests; use NotificationChannels\Twilio\TwilioProvider; use Orchestra\Testbench\TestCase; -class BaseIntegrationTest extends TestCase +class IntegrationTestCase extends TestCase { protected function getPackageProviders($app) { diff --git a/tests/Unit/IntegrationTest.php b/tests/Unit/IntegrationTest.php index 27c248b..46013e0 100644 --- a/tests/Unit/IntegrationTest.php +++ b/tests/Unit/IntegrationTest.php @@ -90,7 +90,7 @@ public function it_can_send_a_sms_message_using_url_shortener() $config = new TwilioConfig([ 'from' => '+31612345678', - 'ShortenUrls' => true, + 'shorten_urls' => true, ]); $twilio = new Twilio($this->twilioService, $config); $channel = new TwilioChannel($twilio, $this->events); diff --git a/tests/Unit/TwilioCallMessageTest.php b/tests/Unit/TwilioCallMessageTest.php index c4f65e2..988182b 100644 --- a/tests/Unit/TwilioCallMessageTest.php +++ b/tests/Unit/TwilioCallMessageTest.php @@ -4,7 +4,7 @@ use NotificationChannels\Twilio\TwilioCallMessage; -class TwilioCallMessageTest extends TwilioMessageTest +class TwilioCallMessageTest extends TwilioMessageTestCase { /** @var TwilioCallMessage */ protected $message; diff --git a/tests/Unit/TwilioMessageTest.php b/tests/Unit/TwilioMessageTestCase.php similarity index 94% rename from tests/Unit/TwilioMessageTest.php rename to tests/Unit/TwilioMessageTestCase.php index 95902ed..628e852 100644 --- a/tests/Unit/TwilioMessageTest.php +++ b/tests/Unit/TwilioMessageTestCase.php @@ -5,7 +5,7 @@ use Mockery\Adapter\Phpunit\MockeryTestCase; use NotificationChannels\Twilio\TwilioMessage; -abstract class TwilioMessageTest extends MockeryTestCase +abstract class TwilioMessageTestCase extends MockeryTestCase { /** @var TwilioMessage */ protected $message; diff --git a/tests/Unit/TwilioMmsMessageTest.php b/tests/Unit/TwilioMmsMessageTest.php index 4cd5056..e1d7ea1 100644 --- a/tests/Unit/TwilioMmsMessageTest.php +++ b/tests/Unit/TwilioMmsMessageTest.php @@ -4,7 +4,7 @@ use NotificationChannels\Twilio\TwilioMmsMessage; -class TwilioMmsMessageTest extends TwilioMessageTest +class TwilioMmsMessageTest extends TwilioMessageTestCase { public function setUp(): void { diff --git a/tests/Unit/TwilioSmsMessageTest.php b/tests/Unit/TwilioSmsMessageTest.php index a6d6062..e273c34 100644 --- a/tests/Unit/TwilioSmsMessageTest.php +++ b/tests/Unit/TwilioSmsMessageTest.php @@ -4,7 +4,7 @@ use NotificationChannels\Twilio\TwilioSmsMessage; -class TwilioSmsMessageTest extends TwilioMessageTest +class TwilioSmsMessageTest extends TwilioMessageTestCase { public function setUp(): void { From a1ac7631d3e18ff30a168da252180da4277171b2 Mon Sep 17 00:00:00 2001 From: Philip Iezzi Date: Mon, 18 Nov 2024 12:20:37 +0100 Subject: [PATCH 12/25] Migrated legacy phpunit.xml.dist configuration schema --- phpunit.xml.dist | 55 +++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index cc5cee4..939c8fb 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,33 +1,26 @@ - - - - tests/Unit - - - tests/Integration - - - - - src/ - - - - - - - - - - + + + + + + + + + + + tests/Unit + + + tests/Integration + + + + + + + + src/ + + From 0871af1360e4d01038a5589ed430e64344a45575 Mon Sep 17 00:00:00 2001 From: Philip Iezzi Date: Mon, 18 Nov 2024 12:23:36 +0100 Subject: [PATCH 13/25] Added PhpUnit 10.5 to CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 189b934..1a18dff 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ All notable changes to `laravel-notification-channels/twilio` will be documented ## 4.0.0 +- Update PhpUnit to 10.5 and fixed all tests. - Bump `twilio/sdk` to 8.3 - Improved types and use constructor property promotion everywhere. - Added Pint and fixed PHP syntax. From 983b372c1fa763ef437a441f4abcbd17cadfd7c5 Mon Sep 17 00:00:00 2001 From: Philip Iezzi Date: Mon, 18 Nov 2024 12:34:13 +0100 Subject: [PATCH 14/25] Updated Build Status badge in README, removed broken StyleCI badge/link --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d42c8b5..511b07a 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,14 @@ [![Latest Version on Packagist](https://img.shields.io/packagist/v/laravel-notification-channels/twilio.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/twilio) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) -[![Build Status](https://img.shields.io/github/workflow/status/laravel-notification-channels/twilio/PHP?style=flat-square)](https://travis-ci.org/laravel-notification-channels/twilio) -[![StyleCI](https://styleci.io/repos/65543339/shield)](https://styleci.io/repos/65543339) +[![Build Status](https://github.com/onlime/laravel-notification-channels-twilio/actions/workflows/ci.yml/badge.svg)](https://github.com/onlime/laravel-notification-channels-twilio/actions/workflows/ci.yml) [![Quality Score](https://img.shields.io/scrutinizer/g/laravel-notification-channels/twilio.svg?style=flat-square)](https://scrutinizer-ci.com/g/laravel-notification-channels/twilio) [![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/laravel-notification-channels/twilio/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/laravel-notification-channels/twilio/?branch=master) [![Total Downloads](https://img.shields.io/packagist/dt/laravel-notification-channels/twilio.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/twilio) -This package makes it easy to send [Twilio notifications](https://documentation.twilio.com/docs) with Laravel 5.5+, 6.x, 7.x, 8.x & 9.x +This package makes it easy to send [Twilio notifications](https://documentation.twilio.com/docs) with Laravel 11.x -You are viewing the `3.x` documentation. [Click here](https://github.com/laravel-notification-channels/twilio/tree/2.x) to view the `2.x` documentation. +You are viewing the `4.x` documentation. [Click here](https://github.com/laravel-notification-channels/twilio/tree/master) to view the `3.x` documentation. ## Contents @@ -200,6 +199,7 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details. ## Credits +- [Philip Iezzi (Pipo)](https://github.com/onlime) - [Gregorio Hernández Caso](https://github.com/gregoriohc) - [atymic](https://github.com/atymic) - [All Contributors](../../contributors) From a18719ea8cb9ec00ab3bf4e2bf67b2f6f968f8c3 Mon Sep 17 00:00:00 2001 From: Philip Iezzi Date: Wed, 20 Nov 2024 23:28:31 +0100 Subject: [PATCH 15/25] rebranding to onlime/laravel-twilio --- CHANGELOG.md | 1 + README.md | 18 +++++++++--------- composer.json | 6 ++++++ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a18dff..e543857 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ All notable changes to `laravel-notification-channels/twilio` will be documented ## 4.0.0 +- Rebranded abandoned [`laravel-notification-channels/twilio`](https://github.com/laravel-notification-channels/twilio) to [`onlime/laravel-twilio`](https://github.com/onlime/laravel-twilio) - Update PhpUnit to 10.5 and fixed all tests. - Bump `twilio/sdk` to 8.3 - Improved types and use constructor property promotion everywhere. diff --git a/README.md b/README.md index 511b07a..f1a365e 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ # Twilio notifications channel for Laravel -[![Latest Version on Packagist](https://img.shields.io/packagist/v/laravel-notification-channels/twilio.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/twilio) +[![Latest Version on Packagist](https://img.shields.io/packagist/v/onlime/laravel-twilio.svg?style=flat-square)](https://packagist.org/packages/onlime/laravel-twilio) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) [![Build Status](https://github.com/onlime/laravel-notification-channels-twilio/actions/workflows/ci.yml/badge.svg)](https://github.com/onlime/laravel-notification-channels-twilio/actions/workflows/ci.yml) -[![Quality Score](https://img.shields.io/scrutinizer/g/laravel-notification-channels/twilio.svg?style=flat-square)](https://scrutinizer-ci.com/g/laravel-notification-channels/twilio) -[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/laravel-notification-channels/twilio/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/laravel-notification-channels/twilio/?branch=master) -[![Total Downloads](https://img.shields.io/packagist/dt/laravel-notification-channels/twilio.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/twilio) +[![Quality Score](https://img.shields.io/scrutinizer/g/onlime/laravel-twilio.svg?style=flat-square)](https://scrutinizer-ci.com/g/onlime/laravel-twilio) +[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/onlime/laravel-twilio/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/onlime/laravel-twilio/?branch=master) +[![Total Downloads](https://img.shields.io/packagist/dt/onlime/laravel-twilio.svg?style=flat-square)](https://packagist.org/packages/onlime/laravel-twilio) This package makes it easy to send [Twilio notifications](https://documentation.twilio.com/docs) with Laravel 11.x @@ -25,10 +25,10 @@ You are viewing the `4.x` documentation. [Click here](https://github.com/laravel ## Installation -You can install the package via composer: +You can install the package via Composer: ``` bash -composer require laravel-notification-channels/twilio +$ composer require onlime/laravel-twilio ``` ### Configuration @@ -79,9 +79,9 @@ If you're upgrading from version `2.x`, you'll need to make sure that your set e in the config section. None of the environment variable names have changed, but if you used different keys in your `services.php` config then you'll need to update them to match the above, or publish the config file and change the `env` key. - + You should also remove the old entry for `twilio` from your `services.php` config, since it's no longer used. - + The main breaking change between `2.x` and `3.x` is that failed notification will now throw an exception unless they are in the list of ignored error codes (publish the config file to edit these). @@ -191,7 +191,7 @@ $ composer test ## Security -If you discover any security related issues, please email gregoriohc@gmail.com instead of using the issue tracker. +If you discover any security related issues, please email pipo@onlime.ch instead of using the issue tracker. ## Contributing diff --git a/composer.json b/composer.json index 643bf95..5737a5b 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,12 @@ "source": "https://github.com/laravel-notification-channels/twilio" }, "authors": [ + { + "name": "Philip Iezzi", + "email": "pipo@onlime.ch", + "homepage": "https://github.com/onlime", + "role": "Developer" + }, { "name": "Gregorio Hernández Caso", "email": "gregoriohc@gmail.com", From b74ac9c9453914f894ec67a16fea0358dcd7635c Mon Sep 17 00:00:00 2001 From: Pascal Baljet Date: Thu, 21 Nov 2024 12:20:23 +0100 Subject: [PATCH 16/25] Added test for `TwilioConfig` class --- tests/Unit/TwilioConfigTest.php | 124 ++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 tests/Unit/TwilioConfigTest.php diff --git a/tests/Unit/TwilioConfigTest.php b/tests/Unit/TwilioConfigTest.php new file mode 100644 index 0000000..8ab041e --- /dev/null +++ b/tests/Unit/TwilioConfigTest.php @@ -0,0 +1,124 @@ +assertTrue($this->config()->enabled()); // defaults to true + $this->assertTrue($this->config(['enabled' => true])->enabled()); + $this->assertFalse($this->config(['enabled' => false])->enabled()); + } + + /** @test */ + public function it_defaults_to_null_for_config_keys_with_a_string_return_type() + { + $config = $this->config(); + + $this->assertNull($config->getAuthToken()); + $this->assertNull($config->getUsername()); + $this->assertNull($config->getPassword()); + $this->assertNull($config->getAccountSid()); + $this->assertNull($config->getFrom()); + $this->assertNull($config->getAlphanumericSender()); + $this->assertNull($config->getServiceSid()); + $this->assertNull($config->getDebugTo()); + } + + /** @test */ + public function it_returns_a_string_for_config_keys_with_a_string_return_type() + { + $config = $this->config([ + 'auth_token' => 'valid-auth-token', + 'username' => 'valid-username', + 'password' => 'valid-password', + 'account_sid' => 'valid-account-sid', + 'from' => 'valid-from', + 'alphanumeric_sender' => 'valid-alphanumeric-sender', + 'sms_service_sid' => 'valid-sms-service-sid', + 'debug_to' => 'valid-debug-to', + ]); + + $this->assertEquals('valid-auth-token', $config->getAuthToken()); + $this->assertEquals('valid-username', $config->getUsername()); + $this->assertEquals('valid-password', $config->getPassword()); + $this->assertEquals('valid-account-sid', $config->getAccountSid()); + $this->assertEquals('valid-from', $config->getFrom()); + $this->assertEquals('valid-alphanumeric-sender', $config->getAlphanumericSender()); + $this->assertEquals('valid-sms-service-sid', $config->getServiceSid()); + $this->assertEquals('valid-debug-to', $config->getDebugTo()); + } + + /** @test */ + public function it_returns_an_array_of_ignored_codes() + { + $this->assertEquals([], $this->config()->getIgnoredErrorCodes()); // defaults to empty array + $this->assertEquals([1, 2], $this->config(['ignored_error_codes' => [1, 2]])->getIgnoredErrorCodes()); + } + + /** @test */ + public function it_returns_a_boolean_wether_the_error_code_is_ignored_or_not() + { + $config = $this->config(['ignored_error_codes' => [1, 2]]); + $this->assertTrue($config->isIgnoredErrorCode(1)); + $this->assertTrue($config->isIgnoredErrorCode(2)); + $this->assertFalse($config->isIgnoredErrorCode(3)); + + $config = $this->config(['ignored_error_codes' => ['*']]); + $this->assertTrue($config->isIgnoredErrorCode(1)); + $this->assertTrue($config->isIgnoredErrorCode(2)); + $this->assertTrue($config->isIgnoredErrorCode(3)); + } + + /** @test */ + public function it_returns_a_boolean_wether_shorten_urls_is_enabled_or_not() + { + $this->assertFalse($this->config()->isShortenUrlsEnabled()); // defaults to false + $this->assertTrue($this->config(['shorten_urls' => true])->isShortenUrlsEnabled()); + $this->assertFalse($this->config(['shorten_urls' => false])->isShortenUrlsEnabled()); + } + + /** @test */ + public function it_returns_a_boolean_wether_token_auth_is_used_or_not() + { + // No values set... + $this->assertFalse($this->config()->usingTokenAuth()); + + // One value set... + $this->assertFalse($this->config(['auth_token' => 'valid'])->usingTokenAuth()); + $this->assertFalse($this->config(['account_sid' => 'valid'])->usingTokenAuth()); + + // Both values set... + $this->assertTrue($this->config(['auth_token' => 'valid', 'account_sid' => 'valid'])->usingTokenAuth()); + } + + /** @test */ + public function it_returns_a_boolean_wether_username_password_auth_is_used_or_not() + { + // No values set... + $this->assertFalse($this->config()->usingUsernamePasswordAuth()); + + // One value set... + $this->assertFalse($this->config(['username' => 'valid'])->usingUsernamePasswordAuth()); + $this->assertFalse($this->config(['password' => 'valid'])->usingUsernamePasswordAuth()); + $this->assertFalse($this->config(['account_sid' => 'valid'])->usingUsernamePasswordAuth()); + + // Two values set... + $this->assertFalse($this->config(['username' => 'valid', 'password' => 'valid'])->usingUsernamePasswordAuth()); + $this->assertFalse($this->config(['username' => 'valid', 'account_sid' => 'valid'])->usingUsernamePasswordAuth()); + $this->assertFalse($this->config(['password' => 'valid', 'account_sid' => 'valid'])->usingUsernamePasswordAuth()); + + // All values set... + $this->assertTrue($this->config(['username' => 'valid', 'password' => 'valid', 'account_sid' => 'valid'])->usingUsernamePasswordAuth()); + } +} From 5cef1deaecb412b72ba9face076c419e20c05173 Mon Sep 17 00:00:00 2001 From: Pascal Baljet Date: Thu, 21 Nov 2024 12:25:37 +0100 Subject: [PATCH 17/25] Updated and improved `TwilioProviderTest` --- src/TwilioProvider.php | 2 +- tests/Integration/TwilioProviderTest.php | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/TwilioProvider.php b/src/TwilioProvider.php index 4555c0d..8f3b4b8 100755 --- a/src/TwilioProvider.php +++ b/src/TwilioProvider.php @@ -67,9 +67,9 @@ public function register(): void public function provides(): array { return [ + TwilioChannel::class, TwilioConfig::class, TwilioService::class, - TwilioChannel::class, ]; } } diff --git a/tests/Integration/TwilioProviderTest.php b/tests/Integration/TwilioProviderTest.php index ff5a1da..297b1bd 100644 --- a/tests/Integration/TwilioProviderTest.php +++ b/tests/Integration/TwilioProviderTest.php @@ -7,17 +7,22 @@ use NotificationChannels\Twilio\Exceptions\InvalidConfigException; use NotificationChannels\Twilio\Tests\IntegrationTestCase; use NotificationChannels\Twilio\TwilioChannel; +use NotificationChannels\Twilio\TwilioConfig; +use NotificationChannels\Twilio\TwilioProvider; +use Twilio\Rest\Client; class TwilioProviderTest extends IntegrationTestCase { - public function testThatApplicationCannotCreateChannelWithoutConfig() + /** @test */ + public function it_cannot_create_the_application_without_config() { $this->expectException(InvalidConfigException::class); $this->app->get(TwilioChannel::class); } - public function testThatApplicationCannotCreateChannelWithoutSid() + /** @test */ + public function it_cannot_create_the_application_without_sid() { $this->app['config']->set('twilio-notification-channel.username', 'test'); $this->app['config']->set('twilio-notification-channel.username', 'password'); @@ -26,7 +31,8 @@ public function testThatApplicationCannotCreateChannelWithoutSid() $this->app->get(TwilioChannel::class); } - public function testThatApplicationCreatesChannelWithConfig() + /** @test */ + public function it_can_create_the_application_with_sid() { $this->app['config']->set('twilio-notification-channel.username', 'test'); $this->app['config']->set('twilio-notification-channel.password', 'password'); @@ -34,4 +40,14 @@ public function testThatApplicationCreatesChannelWithConfig() $this->assertInstanceOf(TwilioChannel::class, $this->app->get(TwilioChannel::class)); } + + /** @test */ + public function it_provides_three_classes() + { + $provides = (new TwilioProvider($this->app))->provides(); + + $this->assertTrue(in_array(TwilioChannel::class, $provides)); + $this->assertTrue(in_array(TwilioConfig::class, $provides)); + $this->assertTrue(in_array(Client::class, $provides)); + } } From 96e7113a5dd17980f3ec373415737fa81650cf1a Mon Sep 17 00:00:00 2001 From: Pascal Baljet Date: Thu, 21 Nov 2024 12:44:06 +0100 Subject: [PATCH 18/25] Additional tests to achieve 100% code coverage --- src/Exceptions/CouldNotSendNotification.php | 7 ------ tests/Integration/TwilioProviderTest.php | 9 +++++++ tests/Unit/IntegrationTest.php | 25 +++++++++++++++++- tests/Unit/TwilioChannelTest.php | 28 ++++++++++++++++++++- tests/Unit/TwilioSmsMessageTest.php | 11 +++++++- 5 files changed, 70 insertions(+), 10 deletions(-) diff --git a/src/Exceptions/CouldNotSendNotification.php b/src/Exceptions/CouldNotSendNotification.php index 8428450..a94bd60 100644 --- a/src/Exceptions/CouldNotSendNotification.php +++ b/src/Exceptions/CouldNotSendNotification.php @@ -30,11 +30,4 @@ public static function invalidReceiver(): self method or a phone_number attribute to your notifiable.' ); } - - public static function missingAlphaNumericSender(): self - { - return new static( - 'Notification was not sent. Missing `alphanumeric_sender` in config' - ); - } } diff --git a/tests/Integration/TwilioProviderTest.php b/tests/Integration/TwilioProviderTest.php index 297b1bd..5c526b9 100644 --- a/tests/Integration/TwilioProviderTest.php +++ b/tests/Integration/TwilioProviderTest.php @@ -41,6 +41,15 @@ public function it_can_create_the_application_with_sid() $this->assertInstanceOf(TwilioChannel::class, $this->app->get(TwilioChannel::class)); } + /** @test */ + public function it_can_create_the_application_with_token_auth() + { + $this->app['config']->set('twilio-notification-channel.auth_token', 'token'); + $this->app['config']->set('twilio-notification-channel.account_sid', '1234'); + + $this->assertInstanceOf(TwilioChannel::class, $this->app->get(TwilioChannel::class)); + } + /** @test */ public function it_provides_three_classes() { diff --git a/tests/Unit/IntegrationTest.php b/tests/Unit/IntegrationTest.php index 46013e0..abffcdf 100644 --- a/tests/Unit/IntegrationTest.php +++ b/tests/Unit/IntegrationTest.php @@ -3,9 +3,11 @@ namespace NotificationChannels\Twilio\Tests\Unit; use Illuminate\Contracts\Events\Dispatcher; +use Illuminate\Notifications\Events\NotificationFailed; use Illuminate\Notifications\Notification; use Mockery; use Mockery\Adapter\Phpunit\MockeryTestCase; +use NotificationChannels\Twilio\Exceptions\CouldNotSendNotification; use NotificationChannels\Twilio\Twilio; use NotificationChannels\Twilio\TwilioCallMessage; use NotificationChannels\Twilio\TwilioChannel; @@ -28,7 +30,7 @@ class IntegrationTest extends MockeryTestCase /** @var Dispatcher */ protected $events; - public function setUp(): void + protected function setUp(): void { parent::setUp(); @@ -144,6 +146,27 @@ public function it_can_make_a_call() $channel->send(new NotifiableWithAttribute, $this->notification); } + /** @test */ + public function it_cant_make_a_call_when_the_from_config_is_missing() + { + $message = TwilioCallMessage::create('http://example.com'); + $this->notification->shouldReceive('toTwilio')->andReturn($message); + + $config = new TwilioConfig([]); + $twilio = new Twilio($this->twilioService, $config); + $channel = new TwilioChannel($twilio, $this->events); + + $this->twilioService->calls->shouldNotReceive('create'); + + $this->events->shouldReceive('dispatch') + ->atLeast()->once() + ->with(Mockery::type(NotificationFailed::class)); + + $this->expectException(CouldNotSendNotification::class); + + $channel->send(new NotifiableWithAttribute, $this->notification); + } + protected function smsMessageWillBeSentToTwilioWith(...$args) { $this->twilioService->messages->shouldReceive('create') diff --git a/tests/Unit/TwilioChannelTest.php b/tests/Unit/TwilioChannelTest.php index a5c0495..cf04cd0 100644 --- a/tests/Unit/TwilioChannelTest.php +++ b/tests/Unit/TwilioChannelTest.php @@ -26,7 +26,7 @@ class TwilioChannelTest extends MockeryTestCase /** @var Dispatcher */ protected $dispatcher; - public function setUp(): void + protected function setUp(): void { parent::setUp(); @@ -91,6 +91,22 @@ public function it_will_send_a_sms_message_to_the_result_of_the_route_method_of_ $this->channel->send($notifiable, $notification); } + /** @test */ + public function it_will_send_a_sms_message_to_the_result_of_the_route_method_of_the_notifiable_if_it_uses_the_twilio_channel_explicitly() + { + $notifiable = new NotifiableWithTwilioChannel; + $notification = Mockery::mock(Notification::class); + + $message = new TwilioSmsMessage('Message text'); + $notification->shouldReceive('toTwilio')->andReturn($message); + + $this->twilio->shouldReceive('sendMessage') + ->atLeast()->once() + ->with($message, '+1111111111', false); + + $this->channel->send($notifiable, $notification); + } + /** @test */ public function it_will_make_a_call_to_the_phone_number_attribute_of_the_notifiable() { @@ -240,6 +256,16 @@ class Notifiable public function routeNotificationFor() {} } +class NotifiableWithTwilioChannel +{ + public function routeNotificationFor(string $channel) + { + if ($channel === 'twilio') { + return '+1111111111'; + } + } +} + class NotifiableWithMethod { public function routeNotificationFor() diff --git a/tests/Unit/TwilioSmsMessageTest.php b/tests/Unit/TwilioSmsMessageTest.php index e273c34..1e919bc 100644 --- a/tests/Unit/TwilioSmsMessageTest.php +++ b/tests/Unit/TwilioSmsMessageTest.php @@ -6,7 +6,7 @@ class TwilioSmsMessageTest extends TwilioMessageTestCase { - public function setUp(): void + protected function setUp(): void { parent::setUp(); @@ -47,6 +47,15 @@ public function it_can_return_the_alphanumeric_sender_if_set() $this->assertEquals('TestSender', $message->getFrom()); } + /** @test */ + public function it_can_return_the_messaging_service_sid_if_set() + { + $message = TwilioSmsMessage::create('myMessage'); + $message->messagingServiceSid('TestSid'); + + $this->assertEquals('TestSid', $message->getMessagingServiceSid()); + } + /** @test */ public function it_can_set_optional_parameters() { From fd9b344a8c76c133d848e847ed95d7bba167edde Mon Sep 17 00:00:00 2001 From: Pascal Baljet Date: Thu, 21 Nov 2024 12:45:03 +0100 Subject: [PATCH 19/25] Only use Laravel Pint styling --- .scrutinizer.yml | 21 --------------------- .styleci.yml | 1 - tests/Unit/TwilioCallMessageTest.php | 2 +- tests/Unit/TwilioMmsMessageTest.php | 2 +- tests/Unit/TwilioTest.php | 2 +- 5 files changed, 3 insertions(+), 25 deletions(-) delete mode 100644 .scrutinizer.yml delete mode 100644 .styleci.yml diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index 6fad5be..0000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,21 +0,0 @@ -filter: - excluded_paths: [tests/*] - -checks: - php: - remove_extra_empty_lines: true - remove_php_closing_tag: true - remove_trailing_whitespace: true - fix_use_statements: - remove_unused: true - preserve_multiple: false - preserve_blanklines: true - order_alphabetically: true - fix_php_opening_tag: true - fix_linefeed: true - fix_line_ending: true - fix_identation_4spaces: true - fix_doc_comments: true - -tools: - external_code_coverage: true diff --git a/.styleci.yml b/.styleci.yml deleted file mode 100644 index c3bb259..0000000 --- a/.styleci.yml +++ /dev/null @@ -1 +0,0 @@ -preset: laravel \ No newline at end of file diff --git a/tests/Unit/TwilioCallMessageTest.php b/tests/Unit/TwilioCallMessageTest.php index 988182b..19de9ad 100644 --- a/tests/Unit/TwilioCallMessageTest.php +++ b/tests/Unit/TwilioCallMessageTest.php @@ -9,7 +9,7 @@ class TwilioCallMessageTest extends TwilioMessageTestCase /** @var TwilioCallMessage */ protected $message; - public function setUp(): void + protected function setUp(): void { parent::setUp(); diff --git a/tests/Unit/TwilioMmsMessageTest.php b/tests/Unit/TwilioMmsMessageTest.php index e1d7ea1..148b1d5 100644 --- a/tests/Unit/TwilioMmsMessageTest.php +++ b/tests/Unit/TwilioMmsMessageTest.php @@ -6,7 +6,7 @@ class TwilioMmsMessageTest extends TwilioMessageTestCase { - public function setUp(): void + protected function setUp(): void { parent::setUp(); diff --git a/tests/Unit/TwilioTest.php b/tests/Unit/TwilioTest.php index 35f4b49..53dde58 100644 --- a/tests/Unit/TwilioTest.php +++ b/tests/Unit/TwilioTest.php @@ -34,7 +34,7 @@ class TwilioTest extends MockeryTestCase */ protected $config; - public function setUp(): void + protected function setUp(): void { parent::setUp(); From 3f632bb77a10ab62636ec73367931869c5358528 Mon Sep 17 00:00:00 2001 From: Pascal Baljet Date: Thu, 21 Nov 2024 12:47:34 +0100 Subject: [PATCH 20/25] Remove scrutinizer badges --- .gitattributes | 2 -- README.md | 12 +++++------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/.gitattributes b/.gitattributes index 08747e8..4577aeb 100644 --- a/.gitattributes +++ b/.gitattributes @@ -7,7 +7,5 @@ /.gitignore export-ignore /.travis.yml export-ignore /phpunit.xml.dist export-ignore -/.scrutinizer.yml export-ignore -/.styleci.yml export-ignore /.editorconfig export-ignore /tests export-ignore diff --git a/README.md b/README.md index 511b07a..d4f0fcb 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,6 @@ [![Latest Version on Packagist](https://img.shields.io/packagist/v/laravel-notification-channels/twilio.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/twilio) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) [![Build Status](https://github.com/onlime/laravel-notification-channels-twilio/actions/workflows/ci.yml/badge.svg)](https://github.com/onlime/laravel-notification-channels-twilio/actions/workflows/ci.yml) -[![Quality Score](https://img.shields.io/scrutinizer/g/laravel-notification-channels/twilio.svg?style=flat-square)](https://scrutinizer-ci.com/g/laravel-notification-channels/twilio) -[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/laravel-notification-channels/twilio/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/laravel-notification-channels/twilio/?branch=master) [![Total Downloads](https://img.shields.io/packagist/dt/laravel-notification-channels/twilio.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/twilio) This package makes it easy to send [Twilio notifications](https://documentation.twilio.com/docs) with Laravel 11.x @@ -57,7 +55,7 @@ Run `php artisan vendor:publish --provider="NotificationChannels\Twilio\TwilioPr #### Suppressing specific errors or all errors Publish the config using the above command, and edit the `ignored_error_codes` array. You can get the list of -exception codes from [the documentation](https://www.twilio.com/docs/api/errors). +exception codes from [the documentation](https://www.twilio.com/docs/api/errors). If you want to suppress all errors, you can set the option to `['*']`. The errors will not be logged but notification failed events will still be emitted. @@ -75,13 +73,13 @@ We have dropped support for PHP < 8.2 and the minimum Laravel version is now 11. ## Upgrading from 2.x to 3.x -If you're upgrading from version `2.x`, you'll need to make sure that your set environment variables match those above -in the config section. None of the environment variable names have changed, but if you used different keys in your +If you're upgrading from version `2.x`, you'll need to make sure that your set environment variables match those above +in the config section. None of the environment variable names have changed, but if you used different keys in your `services.php` config then you'll need to update them to match the above, or publish the config file and change the `env` key. - + You should also remove the old entry for `twilio` from your `services.php` config, since it's no longer used. - + The main breaking change between `2.x` and `3.x` is that failed notification will now throw an exception unless they are in the list of ignored error codes (publish the config file to edit these). From cf2e7faa2c246587b7b1241acd22535e236d515a Mon Sep 17 00:00:00 2001 From: Philip Iezzi Date: Thu, 21 Nov 2024 13:22:04 +0100 Subject: [PATCH 21/25] Added PHP Linting (Pint) to CI workflow --- .github/workflows/ci.yml | 21 ++++++++++++++++++++- CHANGELOG.md | 2 ++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 29eac39..4c5d3f8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,6 +3,25 @@ name: CI on: [push, pull_request] jobs: + phplint: + runs-on: ubuntu-latest + + name: PHP Linting (Pint) + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: "laravel-pint" + uses: aglipanci/laravel-pint-action@latest + with: + preset: laravel + verboseMode: true + testMode: true + configPath: "pint.json" + pintVersion: 1.18.2 + onlyDirty: true + test: runs-on: ubuntu-latest strategy: @@ -16,7 +35,7 @@ jobs: - laravel: 11.* testbench: 9.* - name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} + name: PHP${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} steps: - name: Checkout diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a18dff..a69a31a 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ All notable changes to `laravel-notification-channels/twilio` will be documented ## 4.0.0 +- Added PHP Linting (Pint) to CI workflow +- Additional tests to achieve 100% code coverage by @pascalbaljet - Update PhpUnit to 10.5 and fixed all tests. - Bump `twilio/sdk` to 8.3 - Improved types and use constructor property promotion everywhere. From 9a464aee5c1d84a77b7b242d7640cfdf9ed325f0 Mon Sep 17 00:00:00 2001 From: Philip Iezzi Date: Thu, 21 Nov 2024 13:28:42 +0100 Subject: [PATCH 22/25] Added Pascal to contributors --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5e8314c..7686017 100644 --- a/README.md +++ b/README.md @@ -198,6 +198,7 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details. ## Credits - [Philip Iezzi (Pipo)](https://github.com/onlime) +- [Pascal Baljet](https://github.com/pascalbaljet) - [Gregorio Hernández Caso](https://github.com/gregoriohc) - [atymic](https://github.com/atymic) - [All Contributors](../../contributors) From 3e6f0169cf1e0620d8fee78128b2db3c4b0aa2a9 Mon Sep 17 00:00:00 2001 From: Philip Iezzi Date: Thu, 21 Nov 2024 13:36:16 +0100 Subject: [PATCH 23/25] more onlime/laravel-twilio rebranding fixes --- CHANGELOG.md | 2 +- README.md | 2 +- composer.json | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb2209b..b4430d1 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -All notable changes to `laravel-notification-channels/twilio` will be documented in this file +All notable changes to `onlime/laravel-twilio` will be documented in this file ## 4.0.0 diff --git a/README.md b/README.md index 7686017..b4990cc 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Latest Version on Packagist](https://img.shields.io/packagist/v/onlime/laravel-twilio.svg?style=flat-square)](https://packagist.org/packages/onlime/laravel-twilio) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) [![Build Status](https://github.com/onlime/laravel-twilio/actions/workflows/ci.yml/badge.svg)](https://github.com/onlime/laravel-twilio/actions/workflows/ci.yml) -[![Total Downloads](https://img.shields.io/packagist/dt/laravel-notification-channels/twilio.svg?style=flat-square)](https://packagist.org/packages/onlime/laravel-twilio) +[![Total Downloads](https://img.shields.io/packagist/dt/onlime/laravel-twilio.svg?style=flat-square)](https://packagist.org/packages/onlime/laravel-twilio) This package makes it easy to send [Twilio notifications](https://documentation.twilio.com/docs) with Laravel 11.x diff --git a/composer.json b/composer.json index 5737a5b..11a9fda 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "laravel-notification-channels/twilio", + "name": "onlime/laravel-twilio", "description": "Provides Twilio notification channel for Laravel", "keywords": [ "laravel", @@ -11,8 +11,8 @@ ], "license": "MIT", "support": { - "issues": "https://github.com/laravel-notification-channels/twilio/issues", - "source": "https://github.com/laravel-notification-channels/twilio" + "issues": "https://github.com/onlime/laravel-twilio/issues", + "source": "https://github.com/onlime/laravel-twilio" }, "authors": [ { From 310888dca480280ed704d370c7793e3749848ed4 Mon Sep 17 00:00:00 2001 From: Philip Iezzi Date: Thu, 21 Nov 2024 13:49:28 +0100 Subject: [PATCH 24/25] rounded badges --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b4990cc..4877233 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # Twilio notifications channel for Laravel -[![Latest Version on Packagist](https://img.shields.io/packagist/v/onlime/laravel-twilio.svg?style=flat-square)](https://packagist.org/packages/onlime/laravel-twilio) -[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) +[![Latest Version on Packagist](https://img.shields.io/packagist/v/onlime/laravel-twilio.svg)](https://packagist.org/packages/onlime/laravel-twilio) +[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE.md) [![Build Status](https://github.com/onlime/laravel-twilio/actions/workflows/ci.yml/badge.svg)](https://github.com/onlime/laravel-twilio/actions/workflows/ci.yml) -[![Total Downloads](https://img.shields.io/packagist/dt/onlime/laravel-twilio.svg?style=flat-square)](https://packagist.org/packages/onlime/laravel-twilio) +[![Total Downloads](https://img.shields.io/packagist/dt/onlime/laravel-twilio.svg)](https://packagist.org/packages/onlime/laravel-twilio) This package makes it easy to send [Twilio notifications](https://documentation.twilio.com/docs) with Laravel 11.x From f90ab6257ef404f358515d4766d41f0e2a57e76c Mon Sep 17 00:00:00 2001 From: Philip Iezzi Date: Sat, 23 Nov 2024 14:36:54 +0100 Subject: [PATCH 25/25] Revert the rebranding froma 18719e & 3e6f016 back to laravel-notification-channels/twilio --- CHANGELOG.md | 7 +++---- README.md | 10 ++++------ composer.json | 6 +++--- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4430d1..98b6146 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,9 @@ # Changelog -All notable changes to `onlime/laravel-twilio` will be documented in this file +All notable changes to `laravel-notification-channels/twilio` will be documented in this file. ## 4.0.0 -- Rebranded abandoned [`laravel-notification-channels/twilio`](https://github.com/laravel-notification-channels/twilio) to [`onlime/laravel-twilio`](https://github.com/onlime/laravel-twilio) - Added PHP Linting (Pint) to CI workflow - Additional tests to achieve 100% code coverage by @pascalbaljet - Update PhpUnit to 10.5 and fixed all tests. @@ -13,8 +12,8 @@ All notable changes to `onlime/laravel-twilio` will be documented in this file - Added Pint and fixed PHP syntax. - Drop support for PHP < 8.2 **BREAKING CHANGE** - Drop support for Laravel 7.x, 8.x, 9.x, and 10.x **BREAKING CHANGE** -- Enable overriding the Twilio message source [#142](https://github.com/laravel-notification-channels/twilio/pull/142) -- Add enabled config option (`TWILIO_ENABLED`) to disable the channel [#21](https://github.com/laravel-notification-channels/twilio/pull/121) +- Enable overriding the Twilio message source #142 +- Add enabled config option (`TWILIO_ENABLED`) to disable the channel #21 ## 3.0.0 diff --git a/README.md b/README.md index 4877233..7710444 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,12 @@ # Twilio notifications channel for Laravel -[![Latest Version on Packagist](https://img.shields.io/packagist/v/onlime/laravel-twilio.svg)](https://packagist.org/packages/onlime/laravel-twilio) +[![Latest Version on Packagist](https://img.shields.io/packagist/v/laravel-notification-channels/twilio.svg)](https://packagist.org/packages/laravel-notification-channels/twilio) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE.md) -[![Build Status](https://github.com/onlime/laravel-twilio/actions/workflows/ci.yml/badge.svg)](https://github.com/onlime/laravel-twilio/actions/workflows/ci.yml) -[![Total Downloads](https://img.shields.io/packagist/dt/onlime/laravel-twilio.svg)](https://packagist.org/packages/onlime/laravel-twilio) +[![Build Status](https://github.com/laravel-notification-channels/twilio/actions/workflows/ci.yml/badge.svg)](https://github.com/laravel-notification-channels/twilio/actions/workflows/ci.yml) +[![Total Downloads](https://img.shields.io/packagist/dt/laravel-notification-channels/twilio.svg)](https://packagist.org/packages/laravel-notification-channels/twilio) This package makes it easy to send [Twilio notifications](https://documentation.twilio.com/docs) with Laravel 11.x -You are viewing the `4.x` documentation. [Click here](https://github.com/laravel-notification-channels/twilio/tree/master) to view the `3.x` documentation. - ## Contents - [Installation](#installation) @@ -26,7 +24,7 @@ You are viewing the `4.x` documentation. [Click here](https://github.com/laravel You can install the package via Composer: ``` bash -$ composer require onlime/laravel-twilio +$ composer require laravel-notification-channels/twilio ``` ### Configuration diff --git a/composer.json b/composer.json index 11a9fda..5737a5b 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "onlime/laravel-twilio", + "name": "laravel-notification-channels/twilio", "description": "Provides Twilio notification channel for Laravel", "keywords": [ "laravel", @@ -11,8 +11,8 @@ ], "license": "MIT", "support": { - "issues": "https://github.com/onlime/laravel-twilio/issues", - "source": "https://github.com/onlime/laravel-twilio" + "issues": "https://github.com/laravel-notification-channels/twilio/issues", + "source": "https://github.com/laravel-notification-channels/twilio" }, "authors": [ {