Skip to content

Commit d67a429

Browse files
committed
- Updated min. required php version to 7.4
- Added support for laravel 9 - CS & Typehinting
1 parent 02ca50c commit d67a429

File tree

5 files changed

+56
-59
lines changed

5 files changed

+56
-59
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
}
1717
],
1818
"require": {
19-
"php": "^7.3|^8.0",
20-
"illuminate/notifications": "^6.0|^7.0|^8.0",
19+
"php": "^7.4|^8.0",
20+
"illuminate/notifications": "^6.0|^7.0|^8.0|^9.0",
2121
"hebinet/websmscom-php": "^1.0.7"
2222
},
2323
"require-dev": {
2424
"mockery/mockery": "^1.0",
25-
"phpunit/phpunit": "^8.0"
25+
"phpunit/phpunit": "^9.5"
2626
},
2727
"autoload": {
2828
"psr-4": {

phpunit.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
beStrictAboutTestsThatDoNotTestAnything="true"
5+
bootstrap="vendor/autoload.php"
6+
colors="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnError="false"
12+
stopOnFailure="false"
13+
verbose="true"
14+
>
15+
<testsuites>
16+
<testsuite name="WebSMS Channel Test Suite">
17+
<directory suffix="Test.php">./tests</directory>
18+
</testsuite>
19+
</testsuites>
20+
<filter>
21+
<whitelist processUncoveredFilesFromWhitelist="true">
22+
<directory suffix=".php">./src</directory>
23+
</whitelist>
24+
</filter>
25+
</phpunit>

src/Channels/WebSmsChannel.php

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
use Hebinet\Notifications\Events\WebSmsFailed;
66
use Hebinet\Notifications\Events\WebSmsSending;
77
use Hebinet\Notifications\Events\WebSmsSent;
8-
use Illuminate\Notifications\Events\NotificationFailed;
9-
use Illuminate\Notifications\Events\NotificationSending;
10-
use Illuminate\Notifications\Events\NotificationSent;
118
use Illuminate\Notifications\Notification;
129
use Illuminate\Support\Arr;
1310
use WebSms\Client;
@@ -22,38 +19,22 @@ class WebSmsChannel
2219
* @var Client
2320
*/
2421
protected $client;
25-
/**
26-
* @var string
27-
*/
28-
private $channelName = 'websms';
2922

30-
/**
31-
* Create a new WebSms channel instance.
32-
*
33-
* @param Client $client
34-
*
35-
* @return void
36-
*/
23+
private string $channelName = 'websms';
24+
3725
public function __construct(Client $client)
3826
{
3927
$this->client = $client;
4028
}
4129

4230
/**
43-
* Send the given notification.
44-
*
45-
* @param mixed $notifiable
46-
* @param \Illuminate\Notifications\Notification $notification
47-
*
48-
* @return Response|null
49-
*
5031
* @throws \WebSms\Exception\ApiException
5132
* @throws \WebSms\Exception\AuthorizationFailedException
5233
* @throws \WebSms\Exception\HttpConnectionException
5334
* @throws \WebSms\Exception\ParameterValidationException
5435
* @throws \WebSms\Exception\UnknownResponseException
5536
*/
56-
public function send($notifiable, Notification $notification)
37+
public function send($notifiable, Notification $notification): ?Response
5738
{
5839
$to = $notifiable->phone_number ?? null;
5940
$routeTo = $notifiable->routeNotificationFor($this->channelName, $notification);
@@ -102,11 +83,6 @@ public function send($notifiable, Notification $notification)
10283
return $response;
10384
}
10485

105-
/**
106-
* @param string $message
107-
*
108-
* @return int
109-
*/
11086
public function getSmsCount(string $message): int
11187
{
11288
$length = strlen(trim($message));
@@ -117,11 +93,6 @@ public function getSmsCount(string $message): int
11793
return 1;
11894
}
11995

120-
/**
121-
* @param $key
122-
*
123-
* @return mixed
124-
*/
12596
private function getConfig($key)
12697
{
12798
return config('websms')[$key];

src/WebSmsChannelServiceProvider.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,20 @@
1010

1111
class WebSmsChannelServiceProvider extends ServiceProvider
1212
{
13-
public function boot()
13+
public function boot(): void
1414
{
15-
if ($this->app->runningInConsole()) {
16-
$this->publishes([
17-
__DIR__ . '/../config/websms.php' => config_path('websms.php'),
18-
], 'config');
15+
if ( ! $this->app->runningInConsole()) {
16+
return;
1917
}
18+
19+
$this->publishes([
20+
__DIR__.'/../config/websms.php' => config_path('websms.php'),
21+
], 'config');
2022
}
2123

22-
/**
23-
* Register the service provider.
24-
*
25-
* @return void
26-
*/
27-
public function register()
24+
public function register(): void
2825
{
29-
$this->mergeConfigFrom(__DIR__ . '/../config/websms.php', 'websms');
26+
$this->mergeConfigFrom(__DIR__.'/../config/websms.php', 'websms');
3027

3128
Notification::resolved(function (ChannelManager $service) {
3229
$service->extend('websms', function ($app) {

tests/NotificationWebSmsChannelTest.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,23 @@ public function testSmsIsSentViaWebsms()
4848
$client = m::mock(Client::class)
4949
);
5050

51-
self::$functions->shouldReceive('config')->with('websms')->twice()->andReturns([
52-
'test' => false,
53-
'verbose' => false
54-
]);
55-
56-
$client->shouldReceive('send')->withArgs(function ($message, $count) {
57-
if ($message instanceof TextMessage && is_int($count)) {
58-
return true;
59-
}
60-
return false;
61-
})->once();
51+
self::$functions->shouldReceive('config')
52+
->with('websms')
53+
->twice()
54+
->andReturns([
55+
'test' => false,
56+
'verbose' => false,
57+
]);
58+
59+
$client->shouldReceive('send')
60+
->withArgs(function ($message, $count) {
61+
return $message instanceof TextMessage && is_int($count);
62+
})
63+
->once();
6264

6365
$channel->send($notifiable, $notification);
66+
67+
$this->assertEquals('this is the way', $notification->toWebsms($notifiable));
6468
}
6569

6670
public function testSmsCount()
@@ -88,7 +92,7 @@ class NotificationWebsmsChannelTestNotification extends Notification
8892
{
8993
public function toWebsms($notifiable)
9094
{
91-
return 'this is my message';
95+
return 'this is the way';
9296
}
9397
}
9498
}

0 commit comments

Comments
 (0)