Skip to content
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
18 changes: 16 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
jobs:
lint:
runs-on: ubuntu-24.04

timeout-minutes: 5

env:
Expand All @@ -20,6 +21,7 @@ jobs:
pint: 1

name: Lint

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -60,6 +62,7 @@ jobs:

static-analysis:
runs-on: ubuntu-24.04

timeout-minutes: 5

env:
Expand All @@ -73,6 +76,7 @@ jobs:
pint: 1

name: Static Analysis

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -113,19 +117,24 @@ jobs:

tests:
runs-on: ubuntu-24.04

timeout-minutes: 5

needs: [lint, static-analysis]
needs:
- lint
- static-analysis

strategy:
fail-fast: true
matrix:
php: [8.3, 8.4]
laravel: [11, 12]
laravel: [11, 12, 13]
filament: [4, 5]
exclude:
- laravel: 11
filament: 5
- laravel: 13
filament: 4
include:
- laravel: 11
testbench: 9
Expand All @@ -135,6 +144,10 @@ jobs:
testbench: 10
larastan: 3
pint: 1
- laravel: 13
testbench: 11
larastan: 3
pint: 1
- filament: 4
livewire: 3
pest: 3
Expand All @@ -143,6 +156,7 @@ jobs:
pest: 4

name: Tests - PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - Filament ${{ matrix.filament }}

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"require": {
"spatie/laravel-package-tools": "^1.18",
"league/html-to-markdown": "^5.1",
"illuminate/support": "^11.0|^12.0",
"illuminate/database": "^11.0|^12.0",
"illuminate/support": "^11.0|^12.0|^13.0",
"illuminate/database": "^11.0|^12.0|^13.0",
"livewire/livewire": "^3.5|^4.0",
"filament/support": "^3.2|^4.0|^5.0",
"filament/notifications": "^3.2|^4.0|^5.0",
Expand All @@ -39,8 +39,8 @@
},
"require-dev": {
"pestphp/pest": "^3.7|^4.0",
"illuminate/auth": "^11.0|^12.0",
"orchestra/testbench": "^9.9|^10.0",
"illuminate/auth": "^11.0|^12.0|^13.0",
"orchestra/testbench": "^9.9|^10.0|^11.0",
"pestphp/pest-plugin-laravel": "^3.1|^4.0",
"pestphp/pest-plugin-livewire": "^3.0|^4.0",
"laravel/pint": "^1.21",
Expand Down
16 changes: 11 additions & 5 deletions config/commentions.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?php

use App\Models\User;
use Kirschbaum\Commentions\Comment;
use Kirschbaum\Commentions\Listeners\SendUserMentionedNotification;
use Kirschbaum\Commentions\Notifications\UserMentionedInComment;
use Kirschbaum\Commentions\Policies\CommentPolicy;

return [
/*
|--------------------------------------------------------------------------
Expand All @@ -18,7 +24,7 @@
|--------------------------------------------------------------------------
*/
'commenter' => [
'model' => \App\Models\User::class,
'model' => User::class,
],

/*
Expand All @@ -27,8 +33,8 @@
|--------------------------------------------------------------------------
*/
'comment' => [
'model' => \Kirschbaum\Commentions\Comment::class,
'policy' => \Kirschbaum\Commentions\Policies\CommentPolicy::class,
'model' => Comment::class,
'policy' => CommentPolicy::class,
],

/*
Expand Down Expand Up @@ -74,8 +80,8 @@

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

'listener' => \Kirschbaum\Commentions\Listeners\SendUserMentionedNotification::class,
'notification' => \Kirschbaum\Commentions\Notifications\UserMentionedInComment::class,
'listener' => SendUserMentionedNotification::class,
'notification' => UserMentionedInComment::class,

'mail' => [
'subject' => env('COMMENTIONS_NOTIFICATIONS_MENTIONS_MAIL_SUBJECT', 'You were mentioned in a comment'),
Expand Down
2 changes: 1 addition & 1 deletion database/factories/CommentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Kirschbaum\Commentions\Contracts\Commenter;

/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Comment>
* @extends Factory<\App\Models\Comment>
*/
class CommentFactory extends Factory
{
Expand Down
8 changes: 7 additions & 1 deletion src/Livewire/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,17 @@ class Comments extends Component
#[Renderless]
public function save()
{
$user = Config::resolveAuthenticatedUser();

if (! $user) {
return;
}

$this->validate();

SaveComment::run(
$this->record,
Config::resolveAuthenticatedUser(),
$user,
$this->commentBody
);

Expand Down
3 changes: 2 additions & 1 deletion tests/CommentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Kirschbaum\Commentions\Events\UserWasMentionedEvent;
use Tests\Models\Post;
use Tests\Models\User;
use Tests\Policies\BlockedCommentPolicy;

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

\Gate::policy(Comment::class, \Tests\Policies\BlockedCommentPolicy::class);
\Gate::policy(Comment::class, BlockedCommentPolicy::class);

expect(fn () => $post->comment('This is a test comment', $user))
->toThrow(AuthorizationException::class)
Expand Down
7 changes: 4 additions & 3 deletions tests/Livewire/CommentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Kirschbaum\Commentions\RenderableComment;
use Tests\Models\Post;
use Tests\Models\User;
use Tests\Policies\BlockedCommentPolicy;

use function Pest\Laravel\actingAs;
use function Pest\Livewire\livewire;
Expand Down Expand Up @@ -63,7 +64,7 @@
$user = User::factory()->create();
actingAs($user);

\Gate::policy(Comment::class, \Tests\Policies\BlockedCommentPolicy::class);
Gate::policy(Comment::class, BlockedCommentPolicy::class);

$post = Post::factory()->create();
$comment = CommentModel::factory()->author($user)->commentable($post)->create();
Expand Down Expand Up @@ -141,7 +142,7 @@
$user = User::factory()->create();
actingAs($user);

\Gate::policy(Comment::class, \Tests\Policies\BlockedCommentPolicy::class);
Gate::policy(Comment::class, BlockedCommentPolicy::class);

$post = Post::factory()->create();
$comment = CommentModel::factory()->author($user)->commentable($post)->create([
Expand Down Expand Up @@ -211,7 +212,7 @@
$user = User::factory()->create();
actingAs($user);

\Gate::policy(Comment::class, \Tests\Policies\BlockedCommentPolicy::class);
Gate::policy(Comment::class, BlockedCommentPolicy::class);

$post = Post::factory()->create();
$comment = CommentModel::factory()->author($user)->commentable($post)->create();
Expand Down
3 changes: 2 additions & 1 deletion tests/Livewire/CommentsSubscriptionTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Event;
use Kirschbaum\Commentions\CommentSubscription;
Expand Down Expand Up @@ -56,7 +57,7 @@
livewire(Comments::class, [
'record' => $post,
])->assertSet('isSubscribed', false)
->assertSet('subscribers', fn ($subscribers) => $subscribers instanceof \Illuminate\Support\Collection && $subscribers->isEmpty());
->assertSet('subscribers', fn ($subscribers) => $subscribers instanceof Collection && $subscribers->isEmpty());

$post->subscribe($user);

Expand Down
12 changes: 5 additions & 7 deletions tests/Livewire/CommentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,11 @@

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

expect(function () use ($post) {
livewire(Comments::class, [
'record' => $post,
])
->set('commentBody', 'This is a test comment')
->call('save');
})->toThrow(TypeError::class);
livewire(Comments::class, [
'record' => $post,
])
->set('commentBody', 'This is a test comment')
->call('save');

$this->assertDatabaseMissing('comments', [
'body' => 'This is a test comment',
Expand Down
3 changes: 2 additions & 1 deletion tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Tests\TestCase;

/*
|--------------------------------------------------------------------------
Expand All @@ -14,7 +15,7 @@
|
*/

pest()->extend(Tests\TestCase::class);
pest()->extend(TestCase::class);

/*
|--------------------------------------------------------------------------
Expand Down
Loading