lc-generate-test
Generate feature/unit tests for a model, controller, action, or component by analyzing its code.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Generate feature/unit tests for a model, controller, action, or component by analyzing its code.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Create a Larascraper scraper (v2 or v3) for a target website, chaining browser actions (click, type, wait, scroll), conditional flow (when/repeatUntil), captcha solving, and file/PDF downloads. Detects the installed major and generates the matching style.
Add or edit a Laracrate file collection in config/laracrate.php with the correct anatomy (disk, access, types, variants, previews, extract/embed, flags, per-model scoping).
Runtime-verified Laravel inspection using the Laravel Boost MCP server (Tinker, Database Query/Schema, Last Error) instead of static grep. Falls back to Docker/Tinker if Boost is not installed.
Scaffold spatie/laravel-permission setup - add the HasRoles trait to a model and generate a roles & permissions seeder.
Audit spatie/laravel-permission usage - permissions used in code but undefined, defined but unused, unprotected routes, guard mismatches, and cache pitfalls.
Extract business logic from a controller or Livewire component method into a Laractions Action class.
| name | lc:generate-test |
| description | Generate feature/unit tests for a model, controller, action, or component by analyzing its code. |
| argument-hint | [ModelName | ControllerName | path/to/file] |
| user-invocable | true |
| allowed-tools | Read Grep Bash Edit Write Glob |
Generate PHPUnit or Pest test files for a given model, controller, action, or component by analyzing its code and identifying testable behaviors.
| Subcommand | Description |
|---|---|
| (no argument) | Prompt for the class or file to generate tests for. |
[ModelName] | Generate tests for the specified model (searches in app/Models/). |
[ControllerName] | Generate tests for the specified controller (searches in app/Http/Controllers/). |
[path/to/file] | Generate tests for the file at the given path. |
This is a generator skill -- it always creates files.
Read to load the file directly.app/Models/ for model matchesapp/Http/Controllers/ for controller matchesapp/Actions/ for action matchesresources/views/livewire/ for Volt component matchescomposer.json for test dependencies:
pestphp/pest -> use Pest syntaxphpunit/phpunit -> use PHPUnit syntaxtests/ to match the project's style.Read to examine 1-2 existing test files for patterns:
actingAs(), factory patterns)RefreshDatabase, DatabaseTransactions)Use Read to load the target file and extract:
database/factories/{Model}Factory.php)$dispatch() callsCreate the test file at the appropriate location:
tests/Feature/{path matching source}/{ClassName}Test.php
tests/Unit/{path matching source}/{ClassName}Test.php
<?php
namespace Tests\Feature;
use App\Models\Property;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class PropertyControllerTest extends TestCase
{
use RefreshDatabase;
public function test_index_returns_properties_for_authenticated_user(): void
{
$user = User::factory()->create();
$property = Property::factory()->create(['organization_id' => $user->organization_id]);
$response = $this->actingAs($user)->get(route('properties.index'));
$response->assertOk();
$response->assertSee($property->name);
}
public function test_store_validates_required_fields(): void
{
$user = User::factory()->create();
$response = $this->actingAs($user)->post(route('properties.store'), []);
$response->assertSessionHasErrors(['name', 'address']);
}
public function test_unauthenticated_user_is_redirected(): void
{
$response = $this->get(route('properties.index'));
$response->assertRedirect(route('login'));
}
}
For each testable method, generate tests for:
Write to create the test file.php -l via Bash (Docker-aware).After generating:
TEST FILE GENERATED
====================
File: tests/Feature/Models/PropertyTest.php
Test cases: 12
Tests generated:
- test_belongs_to_organization
- test_belongs_to_office
- test_has_many_operations
- test_scope_active_filters_correctly
- test_fillable_fields_are_protected
- test_soft_delete_works
- test_accessor_full_address
- test_toggle_showcase_action
...
Run with: docker exec {container} php artisan test --filter=PropertyTest
Model::create() with explicit attributes instead.RefreshDatabase trait for tests that modify the database.Livewire::test() syntax.actingAs() with the appropriate guard.