Skip to content

Commit 868ec3e

Browse files
Laravel 13.x Compatibility (#91)
* Bump dependencies for Laravel 13 * Update GitHub Actions for Laravel 13 * Fix CI matrix for Laravel 13: add testbench mapping and Filament 4 exclusion * because we want to return early on that returns early for unauthenticated users * styles matter --------- Co-authored-by: Babacar Cissé DIA <bcdbuddy@outlook.com>
1 parent 2d17e9b commit 868ec3e

10 files changed

Lines changed: 54 additions & 26 deletions

File tree

.github/workflows/ci.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
jobs:
88
lint:
99
runs-on: ubuntu-24.04
10+
1011
timeout-minutes: 5
1112

1213
env:
@@ -20,6 +21,7 @@ jobs:
2021
pint: 1
2122

2223
name: Lint
24+
2325
steps:
2426
- name: Checkout code
2527
uses: actions/checkout@v4
@@ -60,6 +62,7 @@ jobs:
6062

6163
static-analysis:
6264
runs-on: ubuntu-24.04
65+
6366
timeout-minutes: 5
6467

6568
env:
@@ -73,6 +76,7 @@ jobs:
7376
pint: 1
7477

7578
name: Static Analysis
79+
7680
steps:
7781
- name: Checkout code
7882
uses: actions/checkout@v4
@@ -113,19 +117,24 @@ jobs:
113117

114118
tests:
115119
runs-on: ubuntu-24.04
120+
116121
timeout-minutes: 5
117122

118-
needs: [lint, static-analysis]
123+
needs:
124+
- lint
125+
- static-analysis
119126

120127
strategy:
121128
fail-fast: true
122129
matrix:
123130
php: [8.3, 8.4]
124-
laravel: [11, 12]
131+
laravel: [11, 12, 13]
125132
filament: [4, 5]
126133
exclude:
127134
- laravel: 11
128135
filament: 5
136+
- laravel: 13
137+
filament: 4
129138
include:
130139
- laravel: 11
131140
testbench: 9
@@ -135,6 +144,10 @@ jobs:
135144
testbench: 10
136145
larastan: 3
137146
pint: 1
147+
- laravel: 13
148+
testbench: 11
149+
larastan: 3
150+
pint: 1
138151
- filament: 4
139152
livewire: 3
140153
pest: 3
@@ -143,6 +156,7 @@ jobs:
143156
pest: 4
144157

145158
name: Tests - PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - Filament ${{ matrix.filament }}
159+
146160
steps:
147161
- name: Checkout code
148162
uses: actions/checkout@v4

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
"require": {
2424
"spatie/laravel-package-tools": "^1.18",
2525
"league/html-to-markdown": "^5.1",
26-
"illuminate/support": "^11.0|^12.0",
27-
"illuminate/database": "^11.0|^12.0",
26+
"illuminate/support": "^11.0|^12.0|^13.0",
27+
"illuminate/database": "^11.0|^12.0|^13.0",
2828
"livewire/livewire": "^3.5|^4.0",
2929
"filament/support": "^3.2|^4.0|^5.0",
3030
"filament/notifications": "^3.2|^4.0|^5.0",
@@ -39,8 +39,8 @@
3939
},
4040
"require-dev": {
4141
"pestphp/pest": "^3.7|^4.0",
42-
"illuminate/auth": "^11.0|^12.0",
43-
"orchestra/testbench": "^9.9|^10.0",
42+
"illuminate/auth": "^11.0|^12.0|^13.0",
43+
"orchestra/testbench": "^9.9|^10.0|^11.0",
4444
"pestphp/pest-plugin-laravel": "^3.1|^4.0",
4545
"pestphp/pest-plugin-livewire": "^3.0|^4.0",
4646
"laravel/pint": "^1.21",

config/commentions.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<?php
22

3+
use App\Models\User;
4+
use Kirschbaum\Commentions\Comment;
5+
use Kirschbaum\Commentions\Listeners\SendUserMentionedNotification;
6+
use Kirschbaum\Commentions\Notifications\UserMentionedInComment;
7+
use Kirschbaum\Commentions\Policies\CommentPolicy;
8+
39
return [
410
/*
511
|--------------------------------------------------------------------------
@@ -18,7 +24,7 @@
1824
|--------------------------------------------------------------------------
1925
*/
2026
'commenter' => [
21-
'model' => \App\Models\User::class,
27+
'model' => User::class,
2228
],
2329

2430
/*
@@ -27,8 +33,8 @@
2733
|--------------------------------------------------------------------------
2834
*/
2935
'comment' => [
30-
'model' => \Kirschbaum\Commentions\Comment::class,
31-
'policy' => \Kirschbaum\Commentions\Policies\CommentPolicy::class,
36+
'model' => Comment::class,
37+
'policy' => CommentPolicy::class,
3238
],
3339

3440
/*
@@ -74,8 +80,8 @@
7480

7581
'channels' => explode(',', env('COMMENTIONS_NOTIFICATIONS_MENTIONS_CHANNELS', 'mail')),
7682

77-
'listener' => \Kirschbaum\Commentions\Listeners\SendUserMentionedNotification::class,
78-
'notification' => \Kirschbaum\Commentions\Notifications\UserMentionedInComment::class,
83+
'listener' => SendUserMentionedNotification::class,
84+
'notification' => UserMentionedInComment::class,
7985

8086
'mail' => [
8187
'subject' => env('COMMENTIONS_NOTIFICATIONS_MENTIONS_MAIL_SUBJECT', 'You were mentioned in a comment'),

database/factories/CommentFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Kirschbaum\Commentions\Contracts\Commenter;
99

1010
/**
11-
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Comment>
11+
* @extends Factory<\App\Models\Comment>
1212
*/
1313
class CommentFactory extends Factory
1414
{

src/Livewire/Comments.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,17 @@ class Comments extends Component
3333
#[Renderless]
3434
public function save()
3535
{
36+
$user = Config::resolveAuthenticatedUser();
37+
38+
if (! $user) {
39+
return;
40+
}
41+
3642
$this->validate();
3743

3844
SaveComment::run(
3945
$this->record,
40-
Config::resolveAuthenticatedUser(),
46+
$user,
4147
$this->commentBody
4248
);
4349

tests/CommentTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Kirschbaum\Commentions\Events\UserWasMentionedEvent;
1010
use Tests\Models\Post;
1111
use Tests\Models\User;
12+
use Tests\Policies\BlockedCommentPolicy;
1213

1314
test('it can save a comment', function () {
1415
$user = User::factory()->create();
@@ -29,7 +30,7 @@
2930
$user = User::factory()->create();
3031
$post = Post::factory()->create();
3132

32-
\Gate::policy(Comment::class, \Tests\Policies\BlockedCommentPolicy::class);
33+
\Gate::policy(Comment::class, BlockedCommentPolicy::class);
3334

3435
expect(fn () => $post->comment('This is a test comment', $user))
3536
->toThrow(AuthorizationException::class)

tests/Livewire/CommentTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Kirschbaum\Commentions\RenderableComment;
88
use Tests\Models\Post;
99
use Tests\Models\User;
10+
use Tests\Policies\BlockedCommentPolicy;
1011

1112
use function Pest\Laravel\actingAs;
1213
use function Pest\Livewire\livewire;
@@ -63,7 +64,7 @@
6364
$user = User::factory()->create();
6465
actingAs($user);
6566

66-
\Gate::policy(Comment::class, \Tests\Policies\BlockedCommentPolicy::class);
67+
Gate::policy(Comment::class, BlockedCommentPolicy::class);
6768

6869
$post = Post::factory()->create();
6970
$comment = CommentModel::factory()->author($user)->commentable($post)->create();
@@ -141,7 +142,7 @@
141142
$user = User::factory()->create();
142143
actingAs($user);
143144

144-
\Gate::policy(Comment::class, \Tests\Policies\BlockedCommentPolicy::class);
145+
Gate::policy(Comment::class, BlockedCommentPolicy::class);
145146

146147
$post = Post::factory()->create();
147148
$comment = CommentModel::factory()->author($user)->commentable($post)->create([
@@ -211,7 +212,7 @@
211212
$user = User::factory()->create();
212213
actingAs($user);
213214

214-
\Gate::policy(Comment::class, \Tests\Policies\BlockedCommentPolicy::class);
215+
Gate::policy(Comment::class, BlockedCommentPolicy::class);
215216

216217
$post = Post::factory()->create();
217218
$comment = CommentModel::factory()->author($user)->commentable($post)->create();

tests/Livewire/CommentsSubscriptionTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use Illuminate\Support\Collection;
34
use Illuminate\Support\Facades\Auth;
45
use Illuminate\Support\Facades\Event;
56
use Kirschbaum\Commentions\CommentSubscription;
@@ -56,7 +57,7 @@
5657
livewire(Comments::class, [
5758
'record' => $post,
5859
])->assertSet('isSubscribed', false)
59-
->assertSet('subscribers', fn ($subscribers) => $subscribers instanceof \Illuminate\Support\Collection && $subscribers->isEmpty());
60+
->assertSet('subscribers', fn ($subscribers) => $subscribers instanceof Collection && $subscribers->isEmpty());
6061

6162
$post->subscribe($user);
6263

tests/Livewire/CommentsTest.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,11 @@
6868

6969
$post = Post::factory()->create();
7070

71-
expect(function () use ($post) {
72-
livewire(Comments::class, [
73-
'record' => $post,
74-
])
75-
->set('commentBody', 'This is a test comment')
76-
->call('save');
77-
})->toThrow(TypeError::class);
71+
livewire(Comments::class, [
72+
'record' => $post,
73+
])
74+
->set('commentBody', 'This is a test comment')
75+
->call('save');
7876

7977
$this->assertDatabaseMissing('comments', [
8078
'body' => 'This is a test comment',

tests/Pest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use Illuminate\Database\Eloquent\Model;
44
use Illuminate\Support\Collection;
5+
use Tests\TestCase;
56

67
/*
78
|--------------------------------------------------------------------------
@@ -14,7 +15,7 @@
1415
|
1516
*/
1617

17-
pest()->extend(Tests\TestCase::class);
18+
pest()->extend(TestCase::class);
1819

1920
/*
2021
|--------------------------------------------------------------------------

0 commit comments

Comments
 (0)