[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7B2MTQGHBAHY5TG9JZKPZPQ":3,"skill-same:01M7B2MTQGHBAHY5TG9JZKPZPQ":50},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":26,"commitSha":27,"skillDirectory":28,"forksCount":29,"repositoryHtmlUrl":30,"repositoryHomepageUrl":31,"ownerHtmlUrl":32,"ownerBlogUrl":33,"ownerDescription":34,"updatedAt":35,"install":36,"resources":49},"01M7B2MTQGHBAHY5TG9JZKPZPQ","laravel-tdd",null,"Laravel testing strategies with PHPUnit, Pest, model factories, HTTP tests, Sanctum authentication testing, mocking, and coverage. Use when writing Laravel tests with PHPUnit or Pest, or driving a Laravel feature test-first.","lytong760-cell\u002Fcompiler_ko","lytong760-cell","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F289977458?v=4","01M7B1YD239K88PFQRD4PVC9DW","Nguyên Games","01M7B1YD2RM70TZ71QNQ0XTN4R",2,"MIT","https:\u002F\u002Fgithub.com\u002Flytong760-cell\u002Fcompiler_ko\u002Fblob\u002Fmain\u002F.kilo\u002Fskills\u002Flaravel-tdd\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: laravel-tdd\ndescription: Laravel testing strategies with PHPUnit, Pest, model factories, HTTP tests, Sanctum authentication testing, mocking, and coverage. Use when writing Laravel tests with PHPUnit or Pest, or driving a Laravel feature test-first.\nmetadata:\n  origin: ECC\n---\n\n# Laravel Testing with TDD\n\nTest-driven development for Laravel applications using PHPUnit, Pest, Laravel factories, and testing helpers.\n\n## When to Activate\n\n- Writing new Laravel applications or features\n- Implementing API endpoints with Sanctum or Passport authentication\n- Testing Eloquent models, relationships, scopes, and accessors\n- Setting up testing infrastructure for Laravel projects\n- Writing feature tests for HTTP controllers and form requests\n- Mocking external services (queues, mail, notifications, HTTP)\n\n## TDD Workflow for Laravel\n\n### Red-Green-Refactor Cycle\n\n```php\n\u002F\u002F Step 1: RED — Write a failing test\npublic function test_a_product_can_be_created(): void\n{\n    $product = Product::factory()->create(['name' => 'Test Product']);\n    $this->assertDatabaseHas('products', ['name' => 'Test Product']);\n}\n\n\u002F\u002F Step 2: GREEN — Write the migration, model, and factory\n\u002F\u002F Step 3: REFACTOR — Improve while keeping tests green\n```\n\n## Setup\n\n### PHPUnit Configuration\n\n```xml\n\u003C?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\u003Cphpunit xmlns:xsi=\"http:\u002F\u002Fwww.w3.org\u002F2001\u002FXMLSchema-instance\"\n         xsi:noNamespaceSchemaLocation=\"vendor\u002Fphpunit\u002Fphpunit\u002Fphpunit.xsd\"\n         bootstrap=\"vendor\u002Fautoload.php\"\n         colors=\"true\">\n    \u003Ctestsuites>\n        \u003Ctestsuite name=\"Unit\">\n            \u003Cdirectory suffix=\"Test.php\">tests\u002FUnit\u003C\u002Fdirectory>\n        \u003C\u002Ftestsuite>\n        \u003Ctestsuite name=\"Feature\">\n            \u003Cdirectory suffix=\"Test.php\">tests\u002FFeature\u003C\u002Fdirectory>\n        \u003C\u002Ftestsuite>\n    \u003C\u002Ftestsuites>\n    \u003Cphp>\n        \u003Cenv name=\"APP_ENV\" value=\"testing\"\u002F>\n        \u003Cenv name=\"BCRYPT_ROUNDS\" value=\"4\"\u002F>\n        \u003Cenv name=\"CACHE_STORE\" value=\"array\"\u002F>\n        \u003Cenv name=\"DB_CONNECTION\" value=\"sqlite\"\u002F>\n        \u003Cenv name=\"DB_DATABASE\" value=\":memory:\"\u002F>\n        \u003Cenv name=\"MAIL_MAILER\" value=\"array\"\u002F>\n        \u003Cenv name=\"QUEUE_CONNECTION\" value=\"sync\"\u002F>\n        \u003Cenv name=\"SESSION_DRIVER\" value=\"array\"\u002F>\n    \u003C\u002Fphp>\n\u003C\u002Fphpunit>\n```\n\n### Base TestCase Setup\n\n```php\nnamespace Tests;\n\nuse Illuminate\\Foundation\\Testing\\TestCase as BaseTestCase;\n\nabstract class TestCase extends BaseTestCase\n{\n    protected function setUp(): void\n    {\n        parent::setUp();\n        \u002F\u002F Call $this->withoutExceptionHandling() only in tests that\n        \u002F\u002F test non-HTTP exceptions; it suppresses assertStatus() etc.\n    }\n\n    \u002F\u002F Helper: Authenticate and return user\n    protected function actingAsUser(): mixed\n    {\n        $user = \\App\\Models\\User::factory()->create();\n        $this->actingAs($user);\n        return $user;\n    }\n\n    protected function actingAsAdmin(): mixed\n    {\n        $admin = \\App\\Models\\User::factory()->admin()->create();\n        $this->actingAs($admin);\n        return $admin;\n    }\n}\n```\n\n## Model Factories\n\n```php\n\u002F\u002F database\u002Ffactories\u002FUserFactory.php\nclass UserFactory extends Factory\n{\n    protected static ?string $password = null;\n\n    public function definition(): array\n    {\n        return [\n            'name' => fake()->name(),\n            'email' => fake()->unique()->safeEmail(),\n            'email_verified_at' => now(),\n            'password' => static::$password ??= Hash::make('password'),\n            'remember_token' => Str::random(10),\n            'role' => 'user',\n        ];\n    }\n\n    public function admin(): static\n    {\n        return $this->state(fn (array $attributes) => ['role' => 'admin']);\n    }\n\n    public function unverified(): static\n    {\n        return $this->state(fn (array $attributes) => ['email_verified_at' => null]);\n    }\n}\n\n\u002F\u002F database\u002Ffactories\u002FProductFactory.php\nclass ProductFactory extends Factory\n{\n    public function definition(): array\n    {\n        return [\n            'name' => fake()->unique()->words(3, true),\n            'slug' => fn (array $attrs) => Str::slug($attrs['name']),\n            'description' => fake()->paragraph(),\n            'price' => fake()->numberBetween(100, 100000),\n            'stock' => fake()->numberBetween(0, 100),\n            'is_active' => true,\n            'user_id' => UserFactory::new(),\n        ];\n    }\n\n    public function outOfStock(): static\n    {\n        return $this->state(fn (array $attributes) => ['stock' => 0]);\n    }\n}\n```\n\n### Using Factories\n\n```php\n$user = User::factory()->create();\n$admin = User::factory()->admin()->create();\n$product = Product::factory()->create(['user_id' => $user->id]);\n$products = Product::factory()->count(10)->create();\n$draft = Product::factory()->make(); \u002F\u002F Not persisted\n\n\u002F\u002F With relationships\n$user = User::factory()->has(Product::factory()->count(3))->create();\n\n\u002F\u002F Sequences\nUser::factory()->count(3)->sequence(\n    ['role' => 'admin'], ['role' => 'editor'], ['role' => 'user'],\n)->create();\n```\n\n## Model Testing\n\n```php\nnamespace Tests\\Unit\\Models;\n\nuse App\\Models\\User;\nuse App\\Models\\Product;\nuse Illuminate\\Foundation\\Testing\\RefreshDatabase;\nuse Tests\\TestCase;\n\nclass UserTest extends TestCase\n{\n    use RefreshDatabase;\n\n    public function test_it_hides_sensitive_attributes(): void\n    {\n        $user = User::factory()->create();\n        $this->assertArrayNotHasKey('password', $user->toArray());\n    }\n\n    public function test_admin_scope_returns_only_admins(): void\n    {\n        User::factory()->admin()->create();\n        User::factory()->count(3)->create();\n\n        $this->assertCount(1, User::admin()->get());\n    }\n}\n\nclass ProductTest extends TestCase\n{\n    use RefreshDatabase;\n\n    public function test_active_scope_filters_correctly(): void\n    {\n        Product::factory()->count(3)->create(['is_active' => true]);\n        Product::factory()->count(2)->create(['is_active' => false]);\n\n        $this->assertCount(3, Product::active()->get());\n    }\n\n    public function test_it_belongs_to_a_user(): void\n    {\n        $user = User::factory()->create();\n        $product = Product::factory()->create(['user_id' => $user->id]);\n\n        $this->assertTrue($product->user->is($user));\n    }\n}\n```\n\n## Feature \u002F HTTP Testing\n\n```php\nnamespace Tests\\Feature\\Http\\Controllers;\n\nuse App\\Models\\Product;\nuse App\\Models\\User;\nuse Illuminate\\Foundation\\Testing\\RefreshDatabase;\nuse Tests\\TestCase;\n\nclass ProductControllerTest extends TestCase\n{\n    use RefreshDatabase;\n\n    public function test_guests_are_redirected_to_login(): void\n    {\n        $this->get(route('products.create'))->assertRedirect(route('login'));\n    }\n\n    public function test_it_stores_a_new_product(): void\n    {\n        $user = User::factory()->create();\n        $this->actingAs($user);\n\n        $response = $this->post(route('products.store'), [\n            'name' => 'New Product',\n            'description' => 'Description',\n            'price' => 2999,\n            'stock' => 10,\n        ]);\n\n        $response->assertRedirect(route('products.index'));\n        $this->assertDatabaseHas('products', [\n            'name' => 'New Product',\n            'user_id' => $user->id,\n        ]);\n    }\n\n    public function test_it_validates_required_fields(): void\n    {\n        $this->actingAs(User::factory()->create());\n        $this->post(route('products.store'), [])\n            ->assertSessionHasErrors(['name', 'price']);\n    }\n\n    public function test_users_cannot_modify_others_products(): void\n    {\n        $owner = User::factory()->create();\n        $attacker = User::factory()->create();\n        $product = Product::factory()->create(['user_id' => $owner->id]);\n\n        $this->actingAs($attacker)\n            ->delete(route('products.destroy', $product))\n            ->assertForbidden();\n    }\n}\n```\n\n## JSON API Testing\n\n```php\nnamespace Tests\\Feature\\Http\\Controllers\\Api;\n\nuse App\\Models\\Product;\nuse App\\Models\\User;\nuse Illuminate\\Foundation\\Testing\\RefreshDatabase;\nuse Tests\\TestCase;\n\nclass ProductApiTest extends TestCase\n{\n    use RefreshDatabase;\n\n    public function test_unauthenticated_requests_are_rejected(): void\n    {\n        $this->getJson('\u002Fapi\u002Fproducts')->assertUnauthorized();\n    }\n\n    public function test_it_lists_paginated_products(): void\n    {\n        $user = User::factory()->create();\n        Product::factory()->count(5)->create(['user_id' => $user->id]);\n\n        $response = $this->actingAs($user)->getJson('\u002Fapi\u002Fproducts');\n\n        $response->assertOk();\n        $response->assertJsonCount(5, 'data');\n        $response->assertJsonStructure([\n            'data' => [['id', 'name', 'price']],\n            'meta' => ['current_page', 'last_page', 'total'],\n        ]);\n    }\n\n    public function test_it_creates_a_product(): void\n    {\n        $user = User::factory()->create();\n\n        $response = $this->actingAs($user)->postJson('\u002Fapi\u002Fproducts', [\n            'name' => 'API Product',\n            'price' => 4999,\n        ]);\n\n        $response->assertCreated();\n        $response->assertJsonPath('data.name', 'API Product');\n    }\n\n    public function test_users_cannot_delete_others_products(): void\n    {\n        $owner = User::factory()->create();\n        $attacker = User::factory()->create();\n        $product = Product::factory()->create(['user_id' => $owner->id]);\n\n        $this->actingAs($attacker)\n            ->deleteJson(\"\u002Fapi\u002Fproducts\u002F{$product->id}\")\n            ->assertForbidden();\n    }\n}\n```\n\n## Sanctum API Auth Testing\n\n```php\nnamespace Tests\\Feature\\Http\\Controllers\\Api;\n\nuse App\\Models\\User;\nuse Illuminate\\Foundation\\Testing\\RefreshDatabase;\nuse Illuminate\\Support\\Facades\\Hash;\nuse Tests\\TestCase;\n\nclass AuthControllerTest extends TestCase\n{\n    use RefreshDatabase;\n\n    public function test_users_can_register(): void\n    {\n        $response = $this->postJson('\u002Fapi\u002Fregister', [\n            'name' => 'Test User',\n            'email' => 'test@example.com',\n            'password' => 'Password123!',\n            'password_confirmation' => 'Password123!',\n        ]);\n\n        $response->assertCreated();\n        $response->assertJsonStructure(['data' => ['user', 'token']]);\n    }\n\n    public function test_users_can_login(): void\n    {\n        User::factory()->create([\n            'email' => 'test@example.com',\n            'password' => Hash::make('Password123!'),\n        ]);\n\n        $response = $this->postJson('\u002Fapi\u002Flogin', [\n            'email' => 'test@example.com',\n            'password' => 'Password123!',\n        ]);\n\n        $response->assertOk();\n        $response->assertJsonStructure(['data' => ['token']]);\n    }\n\n    public function test_users_cannot_login_with_wrong_password(): void\n    {\n        User::factory()->create(['email' => 'test@example.com']);\n\n        $this->postJson('\u002Fapi\u002Flogin', [\n            'email' => 'test@example.com',\n            'password' => 'wrong',\n        ])->assertUnprocessable();\n    }\n\n    public function test_token_bearer_authenticates_requests(): void\n    {\n        $user = User::factory()->create();\n        $token = $user->createToken('test')->plainTextToken;\n\n        $this->withToken($token)\n            ->getJson('\u002Fapi\u002Fuser')\n            ->assertOk()\n            ->assertJsonPath('data.email', $user->email);\n    }\n}\n```\n\n## Mocking and Fakes\n\n### HTTP Fake\n\n```php\nuse Illuminate\\Support\\Facades\\Http;\n\npublic function test_it_handles_successful_payment(): void\n{\n    Http::fake([\n        'api.stripe.com\u002F*' => Http::response(['id' => 'pi_123', 'status' => 'succeeded'], 200),\n    ]);\n\n    $result = (new PaymentService())->charge(2999);\n    $this->assertTrue($result->success);\n}\n\npublic function test_it_handles_gateway_failure(): void\n{\n    Http::fake([\n        'api.stripe.com\u002F*' => Http::response(['error' => 'card_declined'], 402),\n    ]);\n\n    $this->expectException(PaymentFailedException::class);\n    (new PaymentService())->charge(2999);\n}\n\npublic function test_it_retries_on_timeout(): void\n{\n    Http::fake([\n        'api.stripe.com\u002F*' => Http::sequence()\n            ->pushStatus(408)\n            ->pushStatus(200),\n    ]);\n\n    $this->assertTrue((new PaymentService())->charge(2999)->success);\n}\n```\n\n### Mail Fake\n\n```php\nMail::fake();\n\n$order->sendConfirmation();\n\nMail::assertSent(OrderConfirmation::class, function ($mail) use ($order) {\n    return $mail->hasTo($order->user->email);\n});\n```\n\n### Notification Fake\n\n```php\nNotification::fake();\n\n$user->notify(new WelcomeUser());\n\nNotification::assertSentTo($user, WelcomeUser::class);\n```\n\n### Queue Fake\n\n```php\nQueue::fake();\n\nProcessImage::dispatch($product);\n\nQueue::assertPushed(ProcessImage::class, function ($job) use ($product) {\n    return $job->product->id === $product->id;\n});\n```\n\n### Storage Fake\n\n```php\nStorage::fake('public');\n\n$file = UploadedFile::fake()->image('photo.jpg', 200, 200);\n\n$response = $this->actingAs($user)->post('\u002Favatar', [\n    'avatar' => $file,\n]);\n\n$response->assertSessionHasNoErrors();\nStorage::disk('public')->assertExists('avatars\u002F' . $file->hashName());\n```\n\n### Event Fake\n\n```php\nEvent::fake();\n\n$order->markAsShipped();\n\nEvent::assertDispatched(OrderShipped::class, function ($event) use ($order) {\n    return $event->order->id === $order->id;\n});\n```\n\n## Artisan Command Tests\n\n```php\npublic function test_it_sends_newsletters(): void\n{\n    Mail::fake();\n    User::factory()->count(5)->create(['subscribed' => true]);\n\n    $this->artisan('newsletter:send')\n        ->expectsOutput('Sending newsletter to 5 subscribers...')\n        ->assertExitCode(0);\n\n    Mail::assertSent(NewsletterMail::class, 5);\n}\n\npublic function test_it_handles_no_subscribers(): void\n{\n    $this->artisan('newsletter:send')\n        ->expectsOutput('No subscribers found.')\n        ->assertExitCode(0);\n}\n```\n\n## Authorization Tests\n\n```php\npublic function test_users_can_update_own_posts(): void\n{\n    $user = User::factory()->create();\n    $post = Post::factory()->create(['user_id' => $user->id]);\n\n    $this->actingAs($user)\n        ->put(route('posts.update', $post), ['title' => 'Updated'])\n        ->assertRedirect();\n}\n\npublic function test_users_cannot_update_others_posts(): void\n{\n    $post = Post::factory()->create();\n    $this->actingAs(User::factory()->create())\n        ->put(route('posts.update', $post), ['title' => 'Hacked'])\n        ->assertForbidden();\n}\n\npublic function test_gate_before_grants_super_admin_full_access(): void\n{\n    $super = User::factory()->create(['role' => 'super-admin']);\n    $post = Post::factory()->create();\n\n    $this->actingAs($super)\n        ->delete(route('posts.destroy', $post))\n        ->assertRedirect();\n\n    $this->assertSoftDeleted($post);\n}\n```\n\n## Pest Feature Tests\n\n```php\n\u003C?php\n\nuse App\\Models\\Product;\nuse App\\Models\\User;\n\nuses(\\Illuminate\\Foundation\\Testing\\RefreshDatabase::class);\n\nbeforeEach(function () {\n    $this->user = User::factory()->create();\n    $this->actingAs($this->user);\n});\n\nit('lists products', function () {\n    Product::factory()->count(3)->create(['user_id' => $this->user->id]);\n\n    $this->get(route('products.index'))\n        ->assertOk()\n        ->assertViewHas('products');\n});\n\nit('creates a product with valid data', function () {\n    $this->post(route('products.store'), [\n        'name' => 'Test Product', 'price' => 1999,\n    ])->assertRedirect();\n\n    $this->assertDatabaseHas('products', ['name' => 'Test Product']);\n});\n\nit('fails validation without required fields', function () {\n    $this->post(route('products.store'), [])\n        ->assertSessionHasErrors(['name', 'price']);\n});\n\nit('authorizes updates', function () {\n    $other = User::factory()->create();\n    $product = Product::factory()->create(['user_id' => $other->id]);\n\n    $this->put(route('products.update', $product), ['name' => 'Hacked'])\n        ->assertForbidden();\n});\n```\n\n## Coverage\n\n```bash\n# PHPUnit (use clover output for CI threshold checks)\nvendor\u002Fbin\u002Fphpunit --coverage-html coverage --coverage-clover clover.xml\n\n# Pest (built-in threshold support)\nvendor\u002Fbin\u002Fpest --coverage --min=80\n```\n\n### Coverage Goals\n\n| Component | Target |\n|-----------|--------|\n| Models | 95%+ |\n| Actions\u002FServices | 90%+ |\n| Form Requests | 90%+ |\n| Controllers | 85%+ |\n| Policies | 95%+ |\n| Overall | 80%+ |\n\n## Testing Best Practices\n\n### DO\n\n- Use factories over manual `create()` calls\n- One logical assertion per test\n- Descriptive names: `test_guests_cannot_create_products`\n- Test edge cases and authorization boundaries\n- Mock external services with `Http::fake()`, `Mail::fake()`\n- Use `RefreshDatabase` for clean state\n\n### DON'T\n\n- Don't test Laravel internals (trust the framework)\n- Don't make tests dependent on each other\n- Don't over-mock — mock only service boundaries\n- Don't test private methods — test through the public interface\n- Don't couple tests to HTML structure\n\n## Quick Reference\n\n| Pattern | Usage |\n|---------|-------|\n| `RefreshDatabase` | Reset database between tests |\n| `$this->actingAs($user)` | Authenticate as user |\n| `$this->withToken($token)` | Bearer token auth for APIs |\n| `Model::factory()->create()` | Create model with factory |\n| `Model::factory()->count(5)->create()` | Create multiple records |\n| `Http::fake([...])` | Mock HTTP calls |\n| `Mail::fake()` | Trap sent mail |\n| `Notification::fake()` | Trap sent notifications |\n| `Queue::fake()` | Trap queued jobs |\n| `Event::fake()` | Trap dispatched events |\n| `Storage::fake('public')` | Trap file operations |\n| `assertDatabaseHas` | Assert DB row exists |\n| `assertSoftDeleted` | Assert soft-delete |\n| `assertSessionHasErrors` | Assert validation errors |\n| `assertForbidden` | Assert 403 status |\n\n## Related Skills\n\n- `laravel-patterns` — Laravel architecture, Eloquent, routing, and API patterns\n- `laravel-security` — Laravel authentication, authorization, and secure coding\n- `tdd-workflow` — The repo-wide RED -> GREEN -> REFACTOR loop\n- `backend-patterns` — General backend API and database patterns\n","# Laravel Testing with TDD\n\nTest-driven development for Laravel applications using PHPUnit, Pest, Laravel factories, and testing helpers.\n\n## When to Activate\n\n- Writing new Laravel applications or features\n- Implementing API endpoints with Sanctum or Passport authentication\n- Testing Eloquent models, relationships, scopes, and accessors\n- Setting up testing infrastructure for Laravel projects\n- Writing feature tests for HTTP controllers and form requests\n- Mocking external services (queues, mail, notifications, HTTP)\n\n## TDD Workflow for Laravel\n\n### Red-Green-Refactor Cycle\n\n```php\n\u002F\u002F Step 1: RED — Write a failing test\npublic function test_a_product_can_be_created(): void\n{\n    $product = Product::factory()->create(['name' => 'Test Product']);\n    $this->assertDatabaseHas('products', ['name' => 'Test Product']);\n}\n\n\u002F\u002F Step 2: GREEN — Write the migration, model, and factory\n\u002F\u002F Step 3: REFACTOR — Improve while keeping tests green\n```\n\n## Setup\n\n### PHPUnit Configuration\n\n```xml\n\u003C?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\u003Cphpunit xmlns:xsi=\"http:\u002F\u002Fwww.w3.org\u002F2001\u002FXMLSchema-instance\"\n         xsi:noNamespaceSchemaLocation=\"vendor\u002Fphpunit\u002Fphpunit\u002Fphpunit.xsd\"\n         bootstrap=\"vendor\u002Fautoload.php\"\n         colors=\"true\">\n    \u003Ctestsuites>\n        \u003Ctestsuite name=\"Unit\">\n            \u003Cdirectory suffix=\"Test.php\">tests\u002FUnit\u003C\u002Fdirectory>\n        \u003C\u002Ftestsuite>\n        \u003Ctestsuite name=\"Feature\">\n            \u003Cdirectory suffix=\"Test.php\">tests\u002FFeature\u003C\u002Fdirectory>\n        \u003C\u002Ftestsuite>\n    \u003C\u002Ftestsuites>\n    \u003Cphp>\n        \u003Cenv name=\"APP_ENV\" value=\"testing\"\u002F>\n        \u003Cenv name=\"BCRYPT_ROUNDS\" value=\"4\"\u002F>\n        \u003Cenv name=\"CACHE_STORE\" value=\"array\"\u002F>\n        \u003Cenv name=\"DB_CONNECTION\" value=\"sqlite\"\u002F>\n        \u003Cenv name=\"DB_DATABASE\" value=\":memory:\"\u002F>\n        \u003Cenv name=\"MAIL_MAILER\" value=\"array\"\u002F>\n        \u003Cenv name=\"QUEUE_CONNECTION\" value=\"sync\"\u002F>\n        \u003Cenv name=\"SESSION_DRIVER\" value=\"array\"\u002F>\n    \u003C\u002Fphp>\n\u003C\u002Fphpunit>\n```\n\n### Base TestCase Setup\n\n```php\nnamespace Tests;\n\nuse Illuminate\\Foundation\\Testing\\TestCase as BaseTestCase;\n\nabstract class TestCase extends BaseTestCase\n{\n    protected function setUp(): void\n    {\n        parent::setUp();\n        \u002F\u002F Call $this->withoutExceptionHandling() only in tests that\n        \u002F\u002F test non-HTTP exceptions; it suppresses assertStatus() etc.\n    }\n\n    \u002F\u002F Helper: Authenticate and return user\n    protected function actingAsUser(): mixed\n    {\n        $user = \\App\\Models\\User::factory()->create();\n        $this->actingAs($user);\n        return $user;\n    }\n\n    protected function actingAsAdmin(): mixed\n    {\n        $admin = \\App\\Models\\User::factory()->admin()->create();\n        $this->actingAs($admin);\n        return $admin;\n    }\n}\n```\n\n## Model Factories\n\n```php\n\u002F\u002F database\u002Ffactories\u002FUserFactory.php\nclass UserFactory extends Factory\n{\n    protected static ?string $password = null;\n\n    public function definition(): array\n    {\n        return [\n            'name' => fake()->name(),\n            'email' => fake()->unique()->safeEmail(),\n            'email_verified_at' => now(),\n            'password' => static::$password ??= Hash::make('password'),\n            'remember_token' => Str::random(10),\n            'role' => 'user',\n        ];\n    }\n\n    public function admin(): static\n    {\n        return $this->state(fn (array $attributes) => ['role' => 'admin']);\n    }\n\n    public function unverified(): static\n    {\n        return $this->state(fn (array $attributes) => ['email_verified_at' => null]);\n    }\n}\n\n\u002F\u002F database\u002Ffactories\u002FProductFactory.php\nclass ProductFactory extends Factory\n{\n    public function definition(): array\n    {\n        return [\n            'name' => fake()->unique()->words(3, true),\n            'slug' => fn (array $attrs) => Str::slug($attrs['name']),\n            'description' => fake()->paragraph(),\n            'price' => fake()->numberBetween(100, 100000),\n            'stock' => fake()->numberBetween(0, 100),\n            'is_active' => true,\n            'user_id' => UserFactory::new(),\n        ];\n    }\n\n    public function outOfStock(): static\n    {\n        return $this->state(fn (array $attributes) => ['stock' => 0]);\n    }\n}\n```\n\n### Using Factories\n\n```php\n$user = User::factory()->create();\n$admin = User::factory()->admin()->create();\n$product = Product::factory()->create(['user_id' => $user->id]);\n$products = Product::factory()->count(10)->create();\n$draft = Product::factory()->make(); \u002F\u002F Not persisted\n\n\u002F\u002F With relationships\n$user = User::factory()->has(Product::factory()->count(3))->create();\n\n\u002F\u002F Sequences\nUser::factory()->count(3)->sequence(\n    ['role' => 'admin'], ['role' => 'editor'], ['role' => 'user'],\n)->create();\n```\n\n## Model Testing\n\n```php\nnamespace Tests\\Unit\\Models;\n\nuse App\\Models\\User;\nuse App\\Models\\Product;\nuse Illuminate\\Foundation\\Testing\\RefreshDatabase;\nuse Tests\\TestCase;\n\nclass UserTest extends TestCase\n{\n    use RefreshDatabase;\n\n    public function test_it_hides_sensitive_attributes(): void\n    {\n        $user = User::factory()->create();\n        $this->assertArrayNotHasKey('password', $user->toArray());\n    }\n\n    public function test_admin_scope_returns_only_admins(): void\n    {\n        User::factory()->admin()->create();\n        User::factory()->count(3)->create();\n\n        $this->assertCount(1, User::admin()->get());\n    }\n}\n\nclass ProductTest extends TestCase\n{\n    use RefreshDatabase;\n\n    public function test_active_scope_filters_correctly(): void\n    {\n        Product::factory()->count(3)->create(['is_active' => true]);\n        Product::factory()->count(2)->create(['is_active' => false]);\n\n        $this->assertCount(3, Product::active()->get());\n    }\n\n    public function test_it_belongs_to_a_user(): void\n    {\n        $user = User::factory()->create();\n        $product = Product::factory()->create(['user_id' => $user->id]);\n\n        $this->assertTrue($product->user->is($user));\n    }\n}\n```\n\n## Feature \u002F HTTP Testing\n\n```php\nnamespace Tests\\Feature\\Http\\Controllers;\n\nuse App\\Models\\Product;\nuse App\\Models\\User;\nuse Illuminate\\Foundation\\Testing\\RefreshDatabase;\nuse Tests\\TestCase;\n\nclass ProductControllerTest extends TestCase\n{\n    use RefreshDatabase;\n\n    public function test_guests_are_redirected_to_login(): void\n    {\n        $this->get(route('products.create'))->assertRedirect(route('login'));\n    }\n\n    public function test_it_stores_a_new_product(): void\n    {\n        $user = User::factory()->create();\n        $this->actingAs($user);\n\n        $response = $this->post(route('products.store'), [\n            'name' => 'New Product',\n            'description' => 'Description',\n            'price' => 2999,\n            'stock' => 10,\n        ]);\n\n        $response->assertRedirect(route('products.index'));\n        $this->assertDatabaseHas('products', [\n            'name' => 'New Product',\n            'user_id' => $user->id,\n        ]);\n    }\n\n    public function test_it_validates_required_fields(): void\n    {\n        $this->actingAs(User::factory()->create());\n        $this->post(route('products.store'), [])\n            ->assertSessionHasErrors(['name', 'price']);\n    }\n\n    public function test_users_cannot_modify_others_products(): void\n    {\n        $owner = User::factory()->create();\n        $attacker = User::factory()->create();\n        $product = Product::factory()->create(['user_id' => $owner->id]);\n\n        $this->actingAs($attacker)\n            ->delete(route('products.destroy', $product))\n            ->assertForbidden();\n    }\n}\n```\n\n## JSON API Testing\n\n```php\nnamespace Tests\\Feature\\Http\\Controllers\\Api;\n\nuse App\\Models\\Product;\nuse App\\Models\\User;\nuse Illuminate\\Foundation\\Testing\\RefreshDatabase;\nuse Tests\\TestCase;\n\nclass ProductApiTest extends TestCase\n{\n    use RefreshDatabase;\n\n    public function test_unauthenticated_requests_are_rejected(): void\n    {\n        $this->getJson('\u002Fapi\u002Fproducts')->assertUnauthorized();\n    }\n\n    public function test_it_lists_paginated_products(): void\n    {\n        $user = User::factory()->create();\n        Product::factory()->count(5)->create(['user_id' => $user->id]);\n\n        $response = $this->actingAs($user)->getJson('\u002Fapi\u002Fproducts');\n\n        $response->assertOk();\n        $response->assertJsonCount(5, 'data');\n        $response->assertJsonStructure([\n            'data' => [['id', 'name', 'price']],\n            'meta' => ['current_page', 'last_page', 'total'],\n        ]);\n    }\n\n    public function test_it_creates_a_product(): void\n    {\n        $user = User::factory()->create();\n\n        $response = $this->actingAs($user)->postJson('\u002Fapi\u002Fproducts', [\n            'name' => 'API Product',\n            'price' => 4999,\n        ]);\n\n        $response->assertCreated();\n        $response->assertJsonPath('data.name', 'API Product');\n    }\n\n    public function test_users_cannot_delete_others_products(): void\n    {\n        $owner = User::factory()->create();\n        $attacker = User::factory()->create();\n        $product = Product::factory()->create(['user_id' => $owner->id]);\n\n        $this->actingAs($attacker)\n            ->deleteJson(\"\u002Fapi\u002Fproducts\u002F{$product->id}\")\n            ->assertForbidden();\n    }\n}\n```\n\n## Sanctum API Auth Testing\n\n```php\nnamespace Tests\\Feature\\Http\\Controllers\\Api;\n\nuse App\\Models\\User;\nuse Illuminate\\Foundation\\Testing\\RefreshDatabase;\nuse Illuminate\\Support\\Facades\\Hash;\nuse Tests\\TestCase;\n\nclass AuthControllerTest extends TestCase\n{\n    use RefreshDatabase;\n\n    public function test_users_can_register(): void\n    {\n        $response = $this->postJson('\u002Fapi\u002Fregister', [\n            'name' => 'Test User',\n            'email' => 'test@example.com',\n            'password' => 'Password123!',\n            'password_confirmation' => 'Password123!',\n        ]);\n\n        $response->assertCreated();\n        $response->assertJsonStructure(['data' => ['user', 'token']]);\n    }\n\n    public function test_users_can_login(): void\n    {\n        User::factory()->create([\n            'email' => 'test@example.com',\n            'password' => Hash::make('Password123!'),\n        ]);\n\n        $response = $this->postJson('\u002Fapi\u002Flogin', [\n            'email' => 'test@example.com',\n            'password' => 'Password123!',\n        ]);\n\n        $response->assertOk();\n        $response->assertJsonStructure(['data' => ['token']]);\n    }\n\n    public function test_users_cannot_login_with_wrong_password(): void\n    {\n        User::factory()->create(['email' => 'test@example.com']);\n\n        $this->postJson('\u002Fapi\u002Flogin', [\n            'email' => 'test@example.com',\n            'password' => 'wrong',\n        ])->assertUnprocessable();\n    }\n\n    public function test_token_bearer_authenticates_requests(): void\n    {\n        $user = User::factory()->create();\n        $token = $user->createToken('test')->plainTextToken;\n\n        $this->withToken($token)\n            ->getJson('\u002Fapi\u002Fuser')\n            ->assertOk()\n            ->assertJsonPath('data.email', $user->email);\n    }\n}\n```\n\n## Mocking and Fakes\n\n### HTTP Fake\n\n```php\nuse Illuminate\\Support\\Facades\\Http;\n\npublic function test_it_handles_successful_payment(): void\n{\n    Http::fake([\n        'api.stripe.com\u002F*' => Http::response(['id' => 'pi_123', 'status' => 'succeeded'], 200),\n    ]);\n\n    $result = (new PaymentService())->charge(2999);\n    $this->assertTrue($result->success);\n}\n\npublic function test_it_handles_gateway_failure(): void\n{\n    Http::fake([\n        'api.stripe.com\u002F*' => Http::response(['error' => 'card_declined'], 402),\n    ]);\n\n    $this->expectException(PaymentFailedException::class);\n    (new PaymentService())->charge(2999);\n}\n\npublic function test_it_retries_on_timeout(): void\n{\n    Http::fake([\n        'api.stripe.com\u002F*' => Http::sequence()\n            ->pushStatus(408)\n            ->pushStatus(200),\n    ]);\n\n    $this->assertTrue((new PaymentService())->charge(2999)->success);\n}\n```\n\n### Mail Fake\n\n```php\nMail::fake();\n\n$order->sendConfirmation();\n\nMail::assertSent(OrderConfirmation::class, function ($mail) use ($order) {\n    return $mail->hasTo($order->user->email);\n});\n```\n\n### Notification Fake\n\n```php\nNotification::fake();\n\n$user->notify(new WelcomeUser());\n\nNotification::assertSentTo($user, WelcomeUser::class);\n```\n\n### Queue Fake\n\n```php\nQueue::fake();\n\nProcessImage::dispatch($product);\n\nQueue::assertPushed(ProcessImage::class, function ($job) use ($product) {\n    return $job->product->id === $product->id;\n});\n```\n\n### Storage Fake\n\n```php\nStorage::fake('public');\n\n$file = UploadedFile::fake()->image('photo.jpg', 200, 200);\n\n$response = $this->actingAs($user)->post('\u002Favatar', [\n    'avatar' => $file,\n]);\n\n$response->assertSessionHasNoErrors();\nStorage::disk('public')->assertExists('avatars\u002F' . $file->hashName());\n```\n\n### Event Fake\n\n```php\nEvent::fake();\n\n$order->markAsShipped();\n\nEvent::assertDispatched(OrderShipped::class, function ($event) use ($order) {\n    return $event->order->id === $order->id;\n});\n```\n\n## Artisan Command Tests\n\n```php\npublic function test_it_sends_newsletters(): void\n{\n    Mail::fake();\n    User::factory()->count(5)->create(['subscribed' => true]);\n\n    $this->artisan('newsletter:send')\n        ->expectsOutput('Sending newsletter to 5 subscribers...')\n        ->assertExitCode(0);\n\n    Mail::assertSent(NewsletterMail::class, 5);\n}\n\npublic function test_it_handles_no_subscribers(): void\n{\n    $this->artisan('newsletter:send')\n        ->expectsOutput('No subscribers found.')\n        ->assertExitCode(0);\n}\n```\n\n## Authorization Tests\n\n```php\npublic function test_users_can_update_own_posts(): void\n{\n    $user = User::factory()->create();\n    $post = Post::factory()->create(['user_id' => $user->id]);\n\n    $this->actingAs($user)\n        ->put(route('posts.update', $post), ['title' => 'Updated'])\n        ->assertRedirect();\n}\n\npublic function test_users_cannot_update_others_posts(): void\n{\n    $post = Post::factory()->create();\n    $this->actingAs(User::factory()->create())\n        ->put(route('posts.update', $post), ['title' => 'Hacked'])\n        ->assertForbidden();\n}\n\npublic function test_gate_before_grants_super_admin_full_access(): void\n{\n    $super = User::factory()->create(['role' => 'super-admin']);\n    $post = Post::factory()->create();\n\n    $this->actingAs($super)\n        ->delete(route('posts.destroy', $post))\n        ->assertRedirect();\n\n    $this->assertSoftDeleted($post);\n}\n```\n\n## Pest Feature Tests\n\n```php\n\u003C?php\n\nuse App\\Models\\Product;\nuse App\\Models\\User;\n\nuses(\\Illuminate\\Foundation\\Testing\\RefreshDatabase::class);\n\nbeforeEach(function () {\n    $this->user = User::factory()->create();\n    $this->actingAs($this->user);\n});\n\nit('lists products', function () {\n    Product::factory()->count(3)->create(['user_id' => $this->user->id]);\n\n    $this->get(route('products.index'))\n        ->assertOk()\n        ->assertViewHas('products');\n});\n\nit('creates a product with valid data', function () {\n    $this->post(route('products.store'), [\n        'name' => 'Test Product', 'price' => 1999,\n    ])->assertRedirect();\n\n    $this->assertDatabaseHas('products', ['name' => 'Test Product']);\n});\n\nit('fails validation without required fields', function () {\n    $this->post(route('products.store'), [])\n        ->assertSessionHasErrors(['name', 'price']);\n});\n\nit('authorizes updates', function () {\n    $other = User::factory()->create();\n    $product = Product::factory()->create(['user_id' => $other->id]);\n\n    $this->put(route('products.update', $product), ['name' => 'Hacked'])\n        ->assertForbidden();\n});\n```\n\n## Coverage\n\n```bash\n# PHPUnit (use clover output for CI threshold checks)\nvendor\u002Fbin\u002Fphpunit --coverage-html coverage --coverage-clover clover.xml\n\n# Pest (built-in threshold support)\nvendor\u002Fbin\u002Fpest --coverage --min=80\n```\n\n### Coverage Goals\n\n| Component | Target |\n|-----------|--------|\n| Models | 95%+ |\n| Actions\u002FServices | 90%+ |\n| Form Requests | 90%+ |\n| Controllers | 85%+ |\n| Policies | 95%+ |\n| Overall | 80%+ |\n\n## Testing Best Practices\n\n### DO\n\n- Use factories over manual `create()` calls\n- One logical assertion per test\n- Descriptive names: `test_guests_cannot_create_products`\n- Test edge cases and authorization boundaries\n- Mock external services with `Http::fake()`, `Mail::fake()`\n- Use `RefreshDatabase` for clean state\n\n### DON'T\n\n- Don't test Laravel internals (trust the framework)\n- Don't make tests dependent on each other\n- Don't over-mock — mock only service boundaries\n- Don't test private methods — test through the public interface\n- Don't couple tests to HTML structure\n\n## Quick Reference\n\n| Pattern | Usage |\n|---------|-------|\n| `RefreshDatabase` | Reset database between tests |\n| `$this->actingAs($user)` | Authenticate as user |\n| `$this->withToken($token)` | Bearer token auth for APIs |\n| `Model::factory()->create()` | Create model with factory |\n| `Model::factory()->count(5)->create()` | Create multiple records |\n| `Http::fake([...])` | Mock HTTP calls |\n| `Mail::fake()` | Trap sent mail |\n| `Notification::fake()` | Trap sent notifications |\n| `Queue::fake()` | Trap queued jobs |\n| `Event::fake()` | Trap dispatched events |\n| `Storage::fake('public')` | Trap file operations |\n| `assertDatabaseHas` | Assert DB row exists |\n| `assertSoftDeleted` | Assert soft-delete |\n| `assertSessionHasErrors` | Assert validation errors |\n| `assertForbidden` | Assert 403 status |\n\n## Related Skills\n\n- `laravel-patterns` — Laravel architecture, Eloquent, routing, and API patterns\n- `laravel-security` — Laravel authentication, authorization, and secure coding\n- `tdd-workflow` — The repo-wide RED -> GREEN -> REFACTOR loop\n- `backend-patterns` — General backend API and database patterns\n",{"name":5,"metadata":24,"description":7},{"origin":25},"ECC","main","c32dc0b68600587f78aff3310f3bbd4212173ab3",".kilo\u002Fskills\u002Flaravel-tdd",1,"https:\u002F\u002Fgithub.com\u002Flytong760-cell\u002Fcompiler_ko","https:\u002F\u002Fko-lang.ai.studio","https:\u002F\u002Fgithub.com\u002Flytong760-cell","hanaminikata.com","hello ","2026-11-05 18:26:32",{"source":8,"skillName":5,"commands":37,"prompt":47,"zipAvailable":48},[38,41,44],{"tool":39,"command":40},"npx","npx skills add lytong760-cell\u002Fcompiler_ko --skill laravel-tdd",{"tool":42,"command":43},"bunx","bunx skills add lytong760-cell\u002Fcompiler_ko --skill laravel-tdd",{"tool":45,"command":46},"pnpm","pnpm dlx skills add lytong760-cell\u002Fcompiler_ko --skill laravel-tdd","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Flytong760-cell\u002Fcompiler_ko\u002Fblob\u002Fmain\u002F.kilo\u002Fskills\u002Flaravel-tdd\u002FSKILL.md",true,[],[51,58,65,72,79,86],{"skillNo":52,"name":53,"nameZh":6,"description":54,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":55,"categories":56,"keywords":57,"publishedAt":19},"01M7B36K22Z7155PTGEGTSDNJ4","x-api","X\u002FTwitter API integration for posting tweets, threads, reading timelines, search, and analytics. Covers OAuth auth patterns, rate limits, and platform-native content posting. Use when the user wants to interact with X programmatically.","https:\u002F\u002Fgithub.com\u002Flytong760-cell\u002Fcompiler_ko\u002Fblob\u002Fmain\u002F.kilo\u002Fskills\u002Fx-api\u002FSKILL.md",[],[],{"skillNo":59,"name":60,"nameZh":6,"description":61,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":62,"categories":63,"keywords":64,"publishedAt":19},"01M7B36HCAE9ESGBVS6J0FR52F","writing-for-agents","Writing documents for agents. Use when creating or editing skills, or modifying AGENTS.md or CLAUDE.md.","https:\u002F\u002Fgithub.com\u002Flytong760-cell\u002Fcompiler_ko\u002Fblob\u002Fmain\u002F.kilo\u002Fskills\u002Fwriting-for-agents\u002FSKILL.md",[],[],{"skillNo":66,"name":67,"nameZh":6,"description":68,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":69,"categories":70,"keywords":71,"publishedAt":19},"01M7B36DYH4ZFJ3GZHPAEMVQAY","workspace-surface-audit","Audit the active repo, MCP servers, plugins, connectors, env surfaces, and harness setup, then recommend the highest-value ECC-native skills, hooks, agents, and operator workflows. Use when the user wants help setting up Claude Code or understanding what capabilities are actually available in their environment.","https:\u002F\u002Fgithub.com\u002Flytong760-cell\u002Fcompiler_ko\u002Fblob\u002Fmain\u002F.kilo\u002Fskills\u002Fworkspace-surface-audit\u002FSKILL.md",[],[],{"skillNo":73,"name":74,"nameZh":6,"description":75,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":76,"categories":77,"keywords":78,"publishedAt":19},"01M7B36A1QXMEZT8VZMFVQNR5E","wizard","Generate an interactive bash wizard that walks a human through steps only they can perform. Use when provisioning infrastructure, setting up credentials or CI secrets, walking an unfamiliar third-party dashboard, or running a one-off migration or cutover. Don't invoke this for steps the agent can perform itself.","https:\u002F\u002Fgithub.com\u002Flytong760-cell\u002Fcompiler_ko\u002Fblob\u002Fmain\u002F.kilo\u002Fskills\u002Fwizard\u002FSKILL.md",[],[],{"skillNo":80,"name":81,"nameZh":6,"description":82,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":83,"categories":84,"keywords":85,"publishedAt":19},"01M7B364EK3N88VQQJ6HFATJQE","windows-desktop-e2e","E2E testing for Windows native desktop apps (WPF, WinForms, Win32\u002FMFC, Qt) using pywinauto and Windows UI Automation. Use when writing E2E tests for a Windows native desktop app with pywinauto or UI Automation.","https:\u002F\u002Fgithub.com\u002Flytong760-cell\u002Fcompiler_ko\u002Fblob\u002Fmain\u002F.kilo\u002Fskills\u002Fwindows-desktop-e2e\u002FSKILL.md",[],[],{"skillNo":87,"name":88,"nameZh":6,"description":89,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":90,"categories":91,"keywords":92,"publishedAt":19},"01M7B360YF7GGNAF21KT4QB5PG","wayfinder","Plan a huge chunk of work (more than one agent session can hold) as a shared map of decision tickets on your issue tracker, and resolve them one at a time until the way to the destination is clear.","https:\u002F\u002Fgithub.com\u002Flytong760-cell\u002Fcompiler_ko\u002Fblob\u002Fmain\u002F.kilo\u002Fskills\u002Fwayfinder\u002FSKILL.md",[],[]]