Skip to content

Commit 11b6ce7

Browse files
authored
Merge pull request #29 from laravel-notification-channels/laravel-12
Clean up repository for Laravel 12
2 parents 84f8496 + 10e90a5 commit 11b6ce7

File tree

11 files changed

+88
-271
lines changed

11 files changed

+88
-271
lines changed

.github/workflows/run-tests.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@ jobs:
1414
fail-fast: false
1515
matrix:
1616
os: [ubuntu-latest]
17-
php: [8.1, 8.2]
18-
laravel: ['9.*', '10.*', '11.*']
17+
php: [8.2, 8.3, 8.4]
18+
laravel: ['11.*', '12.*']
1919
dependency-version: [prefer-lowest, prefer-stable]
20-
exclude:
21-
- laravel: 11.*
22-
php: 8.1
2320

2421
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}
2522

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212
}
1313
],
1414
"require": {
15-
"php": ">=8.1",
15+
"php": ">=8.2",
1616
"aws/aws-sdk-php": "^3.69.11",
1717
"guzzlehttp/guzzle": "^6.2.1 || ^7.0",
18-
"illuminate/notifications": "^9.0|^10.0 || ^11.0",
19-
"illuminate/support": "^9.0|^10.0 || ^11.0"
18+
"illuminate/notifications": "^11.0||^12.0",
19+
"illuminate/support": "^11.0||^12.0"
2020
},
2121
"require-dev": {
22-
"mockery/mockery": "^1.5.1",
23-
"phpunit/phpunit": "^9.5.10 || ^10.5"
22+
"laravel/pint": "^1.20",
23+
"mockery/mockery": "^1.6",
24+
"phpunit/phpunit": "^11.0"
2425
},
2526
"autoload": {
2627
"psr-4": {

phpunit.xml.dist

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="vendor/autoload.php"
3-
backupGlobals="false"
4-
backupStaticAttributes="false"
2+
<phpunit backupGlobals="false"
3+
beStrictAboutTestsThatDoNotTestAnything="true"
4+
bootstrap="vendor/autoload.php"
55
colors="true"
6-
verbose="true"
7-
convertErrorsToExceptions="true"
8-
convertNoticesToExceptions="true"
9-
convertWarningsToExceptions="true"
106
processIsolation="false"
11-
stopOnFailure="false">
7+
stopOnError="false"
8+
stopOnFailure="false"
9+
>
1210
<testsuites>
13-
<testsuite name="AwsSns Test Suite">
14-
<directory>tests</directory>
11+
<testsuite name="Feature">
12+
<directory suffix="Test.php">./tests</directory>
1513
</testsuite>
1614
</testsuites>
17-
<filter>
18-
<whitelist>
19-
<directory suffix=".php">src/</directory>
20-
</whitelist>
21-
</filter>
22-
<logging>
23-
<log type="tap" target="build/report.tap"/>
24-
<log type="junit" target="build/report.junit.xml"/>
25-
<log type="coverage-html" target="build/coverage"/>
26-
<log type="coverage-text" target="build/coverage.txt"/>
27-
<log type="coverage-clover" target="build/logs/clover.xml"/>
28-
</logging>
2915
</phpunit>

src/Sns.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,25 @@
22

33
namespace NotificationChannels\AwsSns;
44

5-
use Aws\Exception\AwsException;
6-
use Aws\Sns\SnsClient as SnsService;
5+
use Aws\Result;
6+
use Aws\Sns\SnsClient;
77

88
class Sns
99
{
1010
/**
11-
* @var SnsService
11+
* Create a new instance of the class.
1212
*/
13-
protected $snsService;
14-
15-
public function __construct(SnsService $snsService)
13+
public function __construct(protected SnsClient $sns)
1614
{
17-
$this->snsService = $snsService;
15+
//
1816
}
1917

2018
/**
21-
* @param string $destination Phone number as described by the E.164 format.
22-
* @return \Aws\Result
19+
* Send the message to the given E.164 destination phone number.
2320
*
24-
* @throws AwsException
21+
* @throws Aws\Exception\AwsException
2522
*/
26-
public function send(SnsMessage $message, $destination)
23+
public function send(SnsMessage $message, string $destination): Result
2724
{
2825
$attributes = [
2926
'AWS.SNS.SMS.SMSType' => [
@@ -56,6 +53,6 @@ public function send(SnsMessage $message, $destination)
5653
'MessageAttributes' => $attributes,
5754
];
5855

59-
return $this->snsService->publish($parameters);
56+
return $this->sns->publish($parameters);
6057
}
6158
}

src/SnsChannel.php

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,39 @@
22

33
namespace NotificationChannels\AwsSns;
44

5+
use Aws\Result;
6+
use Exception;
57
use Illuminate\Contracts\Events\Dispatcher;
68
use Illuminate\Notifications\Events\NotificationFailed;
79
use Illuminate\Notifications\Notification;
810
use NotificationChannels\AwsSns\Exceptions\CouldNotSendNotification;
911

1012
class SnsChannel
1113
{
12-
/**
13-
* @var Sns
14-
*/
15-
protected $sns;
16-
17-
/**
18-
* @var Dispatcher
19-
*/
20-
protected $events;
21-
22-
public function __construct(Sns $sns, Dispatcher $events)
14+
public function __construct(protected Sns $sns, protected Dispatcher $events)
2315
{
24-
$this->sns = $sns;
25-
$this->events = $events;
16+
//
2617
}
2718

2819
/**
2920
* Send the given notification.
30-
*
31-
* @return \Aws\Result
3221
*/
33-
public function send($notifiable, Notification $notification)
22+
public function send($notifiable, Notification $notification): ?Result
3423
{
3524
try {
3625
$destination = $this->getDestination($notifiable, $notification);
3726
$message = $this->getMessage($notifiable, $notification);
3827

3928
return $this->sns->send($message, $destination);
40-
} catch (\Exception $e) {
41-
$event = new NotificationFailed(
29+
} catch (Exception $e) {
30+
$this->events->dispatch(new NotificationFailed(
4231
$notifiable,
4332
$notification,
4433
'sns',
4534
['message' => $e->getMessage(), 'exception' => $e]
46-
);
47-
$this->events->dispatch($event);
35+
));
36+
37+
return null;
4838
}
4939
}
5040

src/SnsServiceProvider.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ class SnsServiceProvider extends ServiceProvider
1313
*/
1414
public function boot()
1515
{
16-
$this->app->when(SnsChannel::class)
17-
->needs(Sns::class)
18-
->give(function () {
19-
return new Sns($this->app->make(SnsService::class));
20-
});
16+
$this->app->bind(Sns::class, function () {
17+
return new Sns($this->app->make(SnsService::class));
18+
});
2119

2220
$this->app->bind(SnsService::class, function () {
2321
$config = array_merge(['version' => 'latest'], $this->app['config']['services.sns']);

tests/SnsChannelTest.php

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@
1010
use NotificationChannels\AwsSns\Sns;
1111
use NotificationChannels\AwsSns\SnsChannel;
1212
use NotificationChannels\AwsSns\SnsMessage;
13-
use PHPUnit\Framework\TestCase;
1413

1514
class SnsChannelTest extends TestCase
1615
{
17-
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
18-
1916
/**
2017
* @var Mockery\LegacyMockInterface|Mockery\MockInterface|Sns
2118
*/
@@ -40,25 +37,24 @@ protected function setUp(): void
4037
$this->channel = new SnsChannel($this->sns, $this->dispatcher);
4138
}
4239

43-
/** @test */
44-
public function it_will_not_send_a_message_without_known_receiver()
40+
public function test_it_will_not_send_a_message_without_known_receiver()
4541
{
46-
$notifiable = new Notifiable();
42+
$notifiable = new Notifiable;
4743
$notification = Mockery::mock(Notification::class);
4844

4945
$this->dispatcher->shouldReceive('dispatch')
50-
->atLeast()->once()
46+
->atLeast()
47+
->once()
5148
->with(Mockery::type(NotificationFailed::class));
5249

5350
$result = $this->channel->send($notifiable, $notification);
5451

5552
$this->assertNull($result);
5653
}
5754

58-
/** @test */
59-
public function it_will_send_a_sms_message_to_the_result_of_the_route_method_of_the_notifiable()
55+
public function test_it_will_send_a_sms_message_to_the_result_of_the_route_method_of_the_notifiable()
6056
{
61-
$notifiable = new NotifiableWithMethod();
57+
$notifiable = new NotifiableWithMethod;
6258
$message = new SnsMessage('Message text');
6359

6460
$notification = Mockery::mock(Notification::class);
@@ -71,10 +67,9 @@ public function it_will_send_a_sms_message_to_the_result_of_the_route_method_of_
7167
$this->channel->send($notifiable, $notification);
7268
}
7369

74-
/** @test */
75-
public function it_will_make_a_call_to_the_phone_number_attribute_of_the_notifiable()
70+
public function test_it_will_make_a_call_to_the_phone_number_attribute_of_the_notifiable()
7671
{
77-
$notifiable = new NotifiableWithAttribute();
72+
$notifiable = new NotifiableWithAttribute;
7873
$message = new SnsMessage('Some content to send');
7974

8075
$notification = Mockery::mock(Notification::class);
@@ -87,10 +82,9 @@ public function it_will_make_a_call_to_the_phone_number_attribute_of_the_notifia
8782
$this->channel->send($notifiable, $notification);
8883
}
8984

90-
/** @test */
91-
public function it_will_convert_a_string_to_a_sms_message()
85+
public function test_it_will_convert_a_string_to_a_sms_message()
9286
{
93-
$notifiable = new NotifiableWithAttribute();
87+
$notifiable = new NotifiableWithAttribute;
9488

9589
$notification = Mockery::mock(Notification::class);
9690
$notification->shouldReceive('toSns')->andReturn('Message text');
@@ -102,10 +96,9 @@ public function it_will_convert_a_string_to_a_sms_message()
10296
$this->channel->send($notifiable, $notification);
10397
}
10498

105-
/** @test */
106-
public function it_will_dispatch_an_event_in_case_of_an_invalid_message()
99+
public function test_it_will_dispatch_an_event_in_case_of_an_invalid_message()
107100
{
108-
$notifiable = new NotifiableWithAttribute();
101+
$notifiable = new NotifiableWithAttribute;
109102

110103
$notification = Mockery::mock(Notification::class);
111104
$notification->shouldReceive('toSns')->andReturn(-1);
@@ -117,8 +110,7 @@ public function it_will_dispatch_an_event_in_case_of_an_invalid_message()
117110
$this->channel->send($notifiable, $notification);
118111
}
119112

120-
/** @test */
121-
public function it_will_send_a_sms_to_an_anonymous_notifiable()
113+
public function test_it_will_send_a_sms_to_an_anonymous_notifiable()
122114
{
123115
$notification = Mockery::mock(Notification::class);
124116
$notification->shouldReceive('toSns')->andReturn('Message text');
@@ -140,6 +132,7 @@ class Notifiable
140132

141133
public function routeNotificationFor()
142134
{
135+
//
143136
}
144137
}
145138

@@ -157,5 +150,6 @@ class NotifiableWithAttribute
157150

158151
public function routeNotificationFor()
159152
{
153+
//
160154
}
161155
}

0 commit comments

Comments
 (0)