Skip to content

Commit

Permalink
Update for Laravel 11
Browse files Browse the repository at this point in the history
  • Loading branch information
peterfox committed Mar 19, 2024
1 parent b0247ca commit 6bfa3e3
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 62 deletions.
27 changes: 2 additions & 25 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,14 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
php: [7.4, 8.0, 8.1, '8.2']
laravel: ['7.*', '8.*', '9.*', '10.*', '11.*']
php: [8.3, 8.2]
laravel: ['11.*', '10.*']
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 10.*
testbench: 8.*
- laravel: 9.*
testbench: 7.*
- laravel: 8.*
testbench: ^6.24.1
- laravel: 7.*
testbench: ^5.20.0
- laravel: 11.*
testbench: 9.*
exclude:
- laravel: 10.*
php: 8.0
- laravel: 10.*
php: 7.4
- laravel: 9.*
php: 7.4
- laravel: 7.*
php: 8.0
- laravel: 7.*
php: 8.1
- laravel: 11.*
php: 7.4
- laravel: 11.*
php: 8.0
- laravel: 11.*
php: 8.1

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
}
],
"require": {
"php": "^8.0|^7.4",
"illuminate/contracts": "9.*|8.*|7.*|^10.0|^11.0"
"php": "^8.2",
"illuminate/contracts": "^10.0|^11.0"
},
"require-dev": {
"orchestra/testbench": "^7.0|^6.24.1|^v5.20.0|^8.0|^9.0",
"phpunit/phpunit": "^9.5.13|^8.3|^9.5.10|^10.5",
"nunomaduro/collision": "^6.0|^5.0|^8.0",
"nunomaduro/larastan": "^2.0|^1.0",
"orchestra/testbench": "^8.0|^9.0",
"phpunit/phpunit": "^9.5.10|^10.5",
"nunomaduro/collision": "^6.0|^8.0",
"larastan/larastan": "^2.0",
"pestphp/pest": "^1.21|^2.34",
"pestphp/pest-plugin-laravel": "^1.1|^2.3",
"pestphp/pest-plugin-laravel": "^2.3",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
Expand Down
11 changes: 5 additions & 6 deletions src/Channels/SubscriberMailChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ class SubscriberMailChannel extends MailChannel
*
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
*
* @return void
* @return \Illuminate\Mail\SentMessage|null
*/
public function send($notifiable, Notification $notification)
{
Expand All @@ -35,7 +34,7 @@ public function send($notifiable, Notification $notification)
$notification instanceof CheckNotifiableSubscriptionStatus &&
$notification->checkMailSubscriptionStatus() &&
! $notifiable->mailSubscriptionStatus($notification)) {
return;
return null;
}

if (method_exists($notification, 'toMail')) {
Expand All @@ -56,16 +55,16 @@ public function send($notifiable, Notification $notification)

if (! $notifiable->routeNotificationFor('mail', $notification) &&
! $message instanceof Mailable) {
return;
return null;
}

if ($message instanceof Mailable) {
$message->send($this->mailer);

return;
return null;
}

$this->mailer->mailer($message->mailer ?? null)->send(
return $this->mailer->mailer($message->mailer ?? null)->send(
$this->buildView($message),
array_merge($message->data(), $this->additionalMessageData($notification)),
$this->messageBuilder($notifiable, $notification, $message)
Expand Down
2 changes: 1 addition & 1 deletion src/Facades/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* @method static void routes()
* @method static string routeName()
* @method static userModel(string $model = null)
* @method static mixed userModel(string $model = null)
* @method static void onCompletion(callable|string $handler)
* @method static void onUnsubscribeFromMailingList(callable|string $handler)
* @method static void onUnsubscribeFromAllMailingLists(callable|string $handler)
Expand Down
4 changes: 3 additions & 1 deletion src/SubscribableApplicationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public function boot()
$this->loadRoutes();
}

\YlsIdeas\SubscribableNotifications\Facades\Subscriber::userModel($this->userModel());
\YlsIdeas\SubscribableNotifications\Facades\Subscriber::userModel(
$this->userModel()
);

\YlsIdeas\SubscribableNotifications\Facades\Subscriber::onUnsubscribeFromMailingList(
$this->onUnsubscribeFromMailingList()
Expand Down
11 changes: 2 additions & 9 deletions src/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,22 +176,15 @@ public function checkSubscriptionStatus($user, ?string $mailingList = null)
return (bool) call_user_func($this->onCheckSubscriptionStatusForAllMailingLists, $user);
}

/**
* @param string|callable $handler
* @return callable
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
protected function parseHandler($handler)
protected function parseHandler(string|callable$handler): callable
{
if (is_string($handler)) {
$parsed = Str::parseCallback($handler);
$parsed[0] = $this->app->make($parsed[0]);

return $parsed;
} elseif (is_callable($handler)) {
return $handler;
}

throw new InvalidArgumentException('Handler argument must be either a string or callable.');
return $handler;
}
}
13 changes: 0 additions & 13 deletions tests/SubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,19 +291,6 @@ public function it_handles_checking_subscription_status_of_all_mailing_lists_via
$this->assertTrue($subscriber->checkSubscriptionStatus($expectedUser));
}

/** @test */
public function it_handles_type_checks_for_a_callable_or_string_handler()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Handler argument must be either a string or callable.');

$subscriber = new Subscriber($this->app);

$subscriber->onCompletion(
new \stdClass()
);
}

/** @test */
public function it_can_provide_a_user_model()
{
Expand Down

0 comments on commit 6bfa3e3

Please sign in to comment.