laravel-tdd
Laravel-TDD guides you through test-driven development for Laravel applications, covering PHPUnit and Pest frameworks alongside model factories, HTTP controller testing, and Sanctum authentication verification. Learn the red-green-refactor cycle with practical examples for unit tests, feature tests, and JSON API testing, plus techniques for mocking external services and validating authorization.
Laravel-TDD teaches test-driven development patterns for Laravel apps using PHPUnit, Pest, factories, and HTTP testing.
AI-generated summary based on this skill's SKILL.md
Decision gist · record as of 2026-07-27
Laravel-TDD teaches test-driven development patterns for Laravel apps using PHPUnit, Pest, factories, and HTTP testing. Laravel-TDD guides you through test-driven development for Laravel applications, covering PHPUnit and Pest frameworks alongside model factories, HTTP controller testing, and Sanctum authentication verification. Learn the red-green-refactor cycle with practical examples for unit tests, feature tests, and JSON API testing, plus techniques for mocking external services and validating authorization.
Use it when
- Laravel-TDD provides comprehensive guidance on testing Eloquent models, including model factory examples to generate test data efficiently.
- Laravel-TDD guides you through writing feature tests for controllers and HTTP endpoints using Laravel's testing utilities.
Verify before relying
Read SKILL.md below before installing (1 file). Open directory: indexed for reading, not audited.
Install
affaan-m/ECC/laravel-tdd · repository language: JavaScript
Open directory. Skills are indexed for reading, not audited. Review a skill's body before installing it.
Frequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
How to write tests in laravel using PHPUnit and Pest?
Laravel-TDD teaches both PHPUnit and Pest frameworks for writing tests in Laravel. PHPUnit is the default testing framework included with Laravel, while Pest offers a more elegant, expressive syntax built on top of PHPUnit. Laravel-TDD covers writing unit tests for models and business logic, feature tests for HTTP requests and controllers, and JSON API tests. You'll learn the red-green-refactor cycle: write a failing test, implement code to pass it, then refactor. Both frameworks integrate seamlessly with Laravel's testing utilities like factories, faking, and assertion helpers.
What does Laravel-TDD cover for testing Eloquent models?
Laravel-TDD provides comprehensive guidance on testing Eloquent models, including model factory examples to generate test data efficiently. You'll learn how to test model relationships, scopes, mutators, and custom methods. The skill covers setting up database testing with factories, using seeders for test data, and writing assertions that validate model behavior. Laravel-TDD emphasizes isolating model logic in unit tests before testing them through feature tests that exercise the full application stack.
How does Laravel-TDD approach testing Laravel controllers and APIs?
Laravel-TDD guides you through writing feature tests for controllers and HTTP endpoints using Laravel's testing utilities. You'll learn to test controller actions, validate HTTP responses, and verify JSON API responses. The skill covers testing form validation, checking status codes, inspecting response data, and following redirects. For APIs specifically, Laravel-TDD teaches JSON API testing patterns, including testing Sanctum authentication, verifying authorization policies, and mocking external service calls within API tests.
How can I test Sanctum API authentication in Laravel?
Laravel-TDD covers testing Sanctum authentication and API authorization comprehensively. You'll learn to create authenticated test requests using Sanctum tokens, verify that protected endpoints reject unauthenticated requests, and test token expiration and revocation. The skill includes testing authorization policies to ensure users can only access resources they're permitted to use. Laravel-TDD demonstrates mocking authenticated users, testing role-based access control, and validating API responses for both successful and unauthorized scenarios.
What techniques does Laravel-TDD teach for mocking external services?
Laravel-TDD covers mocking external services to isolate your tests and avoid real API calls during testing. You'll learn to use Laravel's faking utilities for common services like mail, queues, and HTTP requests. The skill teaches how to mock third-party APIs, verify that your code makes correct calls to external services, and test error handling when external services fail. Laravel-TDD emphasizes using factories and fakes to create predictable test environments, ensuring tests run fast and reliably without external dependencies.
How does Laravel-TDD help achieve code coverage targets?
Laravel-TDD guides you through measuring test effectiveness and achieving code coverage goals. You'll learn to run coverage reports using PHPUnit, identify untested code paths, and write tests strategically to reach coverage targets. The skill emphasizes that high coverage alone doesn't guarantee quality—Laravel-TDD teaches writing meaningful tests that validate behavior, not just line coverage. You'll learn to balance unit and feature tests, prioritize critical paths, and use coverage metrics to guide your test-driven development workflow.
SKILL.md
Rendered from the published skill. Quoted content, verbatim.
Laravel Testing with TDD
Test-driven development for Laravel applications using PHPUnit, Pest, Laravel factories, and testing helpers.
When to Activate
- Writing new Laravel applications or features
- Implementing API endpoints with Sanctum or Passport authentication
- Testing Eloquent models, relationships, scopes, and accessors
- Setting up testing infrastructure for Laravel projects
- Writing feature tests for HTTP controllers and form requests
- Mocking external services (queues, mail, notifications, HTTP)
TDD Workflow for Laravel
Red-Green-Refactor Cycle
// Step 1: RED — Write a failing test
public function test_a_product_can_be_created(): void
{
$product = Product::factory()->create(['name' => 'Test Product']);
$this->assertDatabaseHas('products', ['name' => 'Test Product']);
}
// Step 2: GREEN — Write the migration, model, and factory
// Step 3: REFACTOR — Improve while keeping tests green
Setup
PHPUnit Configuration
```xml <?xml
(truncated - see the full file via the links below)
File tree — 1 file
skills/laravel-tdd/SKILL.md
Let your AI agent find skills like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 56,283 agent skills by what they can do, searchable in plain language.
wish › “Learn test-driven development patterns and workflows for Laravel applications”
Give your agent the search over MCP, or paste the wish link into any chat. No install? Search from any chat →
Related skills
This skill guides you through testing Laravel 13 applications with either Pest PHP 4 or PHPUnit 12, covering 24 rules across HTTP endpoints, model factories, database state verification, service mocking, and authentication patterns. It detects your project's testing framework automatically and provides syntax examples for both frameworks side-by-side, so you can write fast, readable tests regardless of which one you use.
This skill guides you through TDD methodology tailored for Laravel development, using Pest PHP and Laravel's testing tools. Learn the red-green-refactor cycle with Laravel-specific patterns for controllers, models, authorization, APIs, and database operations. Apply TDD consistently across features and bugfixes to build reliable Laravel applications.
PHP Expert provides in-depth instruction on PHP 8+ language features including union types, named arguments, match expressions, attributes, and enums. Learn Laravel framework patterns, Composer dependency management, and object-oriented design principles for building robust applications.
Pest is a testing framework built on PHPUnit that replaces test classes with closures and assertion methods with a fluent expect() API. This skill covers test structure using test()/it()/describe(), the full expect() chain including modifiers and custom expectations, hooks for setup and teardown, datasets for parameterized testing, and advanced features like architecture rules and mutation testing.
Laravel Specialist guides you through building production-ready Laravel 10+ applications with type-safe Eloquent models, queue workers, API resources, and Livewire components. It enforces modern PHP 8.2+ patterns, eager loading, dependency injection, and >85% test coverage across feature and unit tests. Use it for architecting database schemas, implementing authentication flows, optimizing queries, and validating code against PSR-12 standards.
This skill teaches you to write and run Pest 3 tests across Bagisto's modular package structure. Learn to create unit and feature tests, use assertions and mocking, organize tests by package, and run specific test suites via command line.
More skills laravel-authorization-patterns (MIT) · laravel-systematic-debugging (MIT) · phpunit-skill (MIT) · Testing (unlicensed)