Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

L11 compatibility #54

Merged
merged 7 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 45 additions & 58 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,63 +1,50 @@
name: run-tests

on:
push:
pull_request:
branches: [main]
push:
pull_request:
branches:
- main

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.1, 8.0, 7.4]
laravel: [9.*, 8.*, 7.*, 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
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

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

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction

- name: Execute tests
run: vendor/bin/phpunit
test:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: [8.3, 8.2]
laravel: ['11.*', '10.*']
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 10.*
testbench: 8.*
- laravel: 11.*
testbench: 9.*

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

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction

- name: Execute tests
run: vendor/bin/phpunit
15 changes: 7 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@
}
],
"require": {
"php": "^8.0|^7.4",
"illuminate/contracts": "9.*|8.*|7.*|^10.0"
"php": "^8.2",
"illuminate/contracts": "11.*|10.*"
},
"require-dev": {
"orchestra/testbench": "^7.0|^6.24.1|^v5.20.0|^8.0",
"phpunit/phpunit": "^9.5.13|^8.3|^9.5.10",
"nunomaduro/collision": "^6.0|^5.0",
"nunomaduro/larastan": "^2.0|^1.0",
"pestphp/pest": "^1.21",
"pestphp/pest-plugin-laravel": "^1.1",
"orchestra/testbench": "^8.0|^9.0",
"nunomaduro/collision": "^8.0|^7.8|^6.0",
"larastan/larastan": "^2.0",
"pestphp/pest": "^2.34",
"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
12 changes: 2 additions & 10 deletions src/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Http\Response;
use Illuminate\Support\Str;
use InvalidArgumentException;

class Subscriber
{
Expand Down Expand Up @@ -176,22 +175,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