Files
relaticle-comments/tests/TestCase.php
manukminasyan fd5bc5271b refactor: rename for Laravel conventions and better DX
- Rename IsCommenter trait to CanComment, Commenter interface to Commentator
- Move models to Models/ namespace (Comment, Reaction, Attachment, Subscription)
- Rename user_type/user_id polymorphic columns to commenter_type/commenter_id
- Rename Config class to CommentsConfig, update config key tables->table_names
- Rename getCommentName() to getCommentDisplayName() on commentator models
- Add column_names config section for commenter morph customization
- Add table_names config with all 5 tables individually configurable
- Expand translation file with structured i18n groups
- Update all Blade views, Livewire components, events, listeners, and tests
2026-03-27 14:53:12 +04:00

134 lines
4.6 KiB
PHP

<?php
namespace Relaticle\Comments\Tests;
use Filament\FilamentServiceProvider;
use Filament\Support\SupportServiceProvider;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Livewire\LivewireServiceProvider;
use Livewire\Mechanisms\DataStore;
use Orchestra\Testbench\TestCase as Orchestra;
use Relaticle\Comments\CommentsServiceProvider;
use Relaticle\Comments\Tests\Models\User;
abstract class TestCase extends Orchestra
{
protected function setUp(): void
{
parent::setUp();
$this->app->singleton(DataStore::class);
}
/** @return array<int, class-string> */
protected function getPackageProviders($app): array
{
return [
LivewireServiceProvider::class,
SupportServiceProvider::class,
FilamentServiceProvider::class,
CommentsServiceProvider::class,
];
}
protected function defineDatabaseMigrations(): void
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email');
$table->string('password');
$table->timestamps();
});
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->timestamps();
});
Schema::create(config('comments.table_names.comments', 'comments'), function (Blueprint $table) {
$table->id();
$table->morphs('commentable');
$table->morphs('commenter');
$table->foreignId('parent_id')
->nullable()
->constrained(config('comments.table_names.comments', 'comments'))
->cascadeOnDelete();
$table->text('body');
$table->timestamp('edited_at')->nullable();
$table->softDeletes();
$table->timestamps();
$table->index(['commentable_type', 'commentable_id', 'parent_id']);
});
Schema::create('comment_mentions', function (Blueprint $table) {
$table->id();
$table->foreignId('comment_id')
->constrained(config('comments.table_names.comments', 'comments'))
->cascadeOnDelete();
$table->morphs('commenter');
$table->timestamps();
$table->unique(['comment_id', 'commenter_id', 'commenter_type']);
});
Schema::create('comment_reactions', function (Blueprint $table) {
$table->id();
$table->foreignId('comment_id')
->constrained(config('comments.table_names.comments', 'comments'))
->cascadeOnDelete();
$table->morphs('commenter');
$table->string('reaction');
$table->timestamps();
$table->unique(['comment_id', 'commenter_id', 'commenter_type', 'reaction']);
});
Schema::create('comment_attachments', function (Blueprint $table) {
$table->id();
$table->foreignId('comment_id')
->constrained(config('comments.table_names.comments', 'comments'))
->cascadeOnDelete();
$table->string('file_path');
$table->string('original_name');
$table->string('mime_type');
$table->unsignedBigInteger('size');
$table->string('disk');
$table->timestamps();
});
Schema::create('notifications', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('type');
$table->morphs('notifiable');
$table->text('data');
$table->timestamp('read_at')->nullable();
$table->timestamps();
});
Schema::create('comment_subscriptions', function (Blueprint $table) {
$table->id();
$table->morphs('commentable');
$table->morphs('commenter');
$table->timestamp('created_at')->nullable();
$table->unique(['commentable_type', 'commentable_id', 'commenter_type', 'commenter_id'], 'comment_subscriptions_unique');
});
}
protected function getEnvironmentSetUp($app): void
{
$app['config']->set('app.key', 'base64:'.base64_encode(random_bytes(32)));
$app['config']->set('database.default', 'testing');
$app['config']->set('database.connections.testing', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]);
$app['config']->set('comments.commenter.model', User::class);
}
}