- Home
- Skills
- APIs & Backend
- Laravel Testing with Pest and PHPUnit
Works with the AI Agents you already use
Laravel Testing with Pest and PHPUnit
by Saizul Amin
Write, fix, and audit Laravel test suites using Pest or PHPUnit with best-practice fakes and factories.
$5
Laravel Testing with Pest and PHPUnit
Example session with this skill installed
Run the Laravel Testing with Pest and PHPUnit skill on my project and give me a prioritised list of what to fix, with exact changes.
- Read your context and instructions
- Compiled the laravel testing
Here is what the Laravel Testing with Pest and PHPUnit skill produced.
Demo: real, unedited output of the skill's bundled script on a sample input from its test suite.
Output
test smells: 1 high, 5 medium, 6 low, 2 info
HIGH tests/Feature/PostTest.php:11 [focused-test] focused test with ->only(): CI runs only this test
fix: Remove ->only() before committing.
MEDIUM tests/Feature/InvoiceTest.php:12 [no-db-reset] uses the database but never resets it
fix: Add use RefreshDatabase (PHPUnit) or pest()->use(RefreshDatabase::class)->in('Feature').
MEDIUM tests/Feature/PostTest.php:8 [no-db-reset] uses the database but never resets it
fix: Add use RefreshDatabase (PHPUnit) or pest()->use(RefreshDatabase::class)->in('Feature').
MEDIUM tests/Feature/PostTest.php:14 [real-http] outgoing HTTP without Http::fake()
fix: Call Http::fake([...]) and Http::preventStrayRequests() so tests never hit real APIs.
MEDIUM tests/Feature/PostTest.php:15 [sleep] sleep() slows the suite and makes it flaky
fix: Use $this->travel(5)->minutes(), Carbon::setTestNow() or Sleep::fake() (Laravel 10+).
MEDIUM tests/Feature/PostTest.php:16 [debug-output] dd() in a test
fix: Remove it; use assertions or ->dump() locally only.
LOW tests/Feature/InvoiceTest.php:10 [no-assertions] test 'test_invoice_page_loads' has no assertion
fix: Assert the outcome (assertOk(), assertDatabaseHas(), expect()->toBe()).
LOW tests/Feature/InvoiceTest.php:13 [hard-coded-id] hard-coded id in URL /api/invoices/42
fix: Create the model with a factory and use route('posts.show', $post) or "/posts/{$post->id}".
LOW tests/Feature/PostTest.php:10 [hard-coded-id] hard-coded id in URL /posts/1
fix: Create the model with a factory and use route('posts.show', $post) or "/posts/{$post->id}".
LOW tests/Feature/PostTest.php:12 [no-assertions] test 'syncs to the crm' has no assertion
fix: Assert the outcome (assertOk(), assertDatabaseHas(), expect()->toBe()).
LOW tests/Feature/PostTest.php:18 [no-assertions] test 'creates a post' has no assertion
fix: Assert the outcome (assertOk(), assertDatabaseHas(), expect()->toBe()).
LOW tests/Feature/PostTest.php:21 [without-middleware] withoutMiddleware() disables auth, CSRF and throttling
fix: Authenticate with actingAs() instead, or disable only one middleware class.
INFO tests/Feature/InvoiceTest.php:24 [skipped] skipped or incomplete test
fix: Fix or delete it; track the reason in an issue.
INFO tests/Feature/PostTest.php:24 [skipped] skipped or incomplete test
fix: Fix or delete it; track the reason in an issue.
What you do next
- Fix the highest-severity items first.
- Ask your agent to apply the fixes it suggests, then run the skill again to confirm.
- Keep the skill installed and re-run it whenever the project changes.
Connects securely to your tools. The creator never sees your data.
About this skill
Testing in Laravel often suffers from slow execution, flaky database states, and leaked external API calls. This skill provides a systematic approach to writing and auditing Laravel test suites using Pest or PHPUnit. It ensures your tests remain fast and deterministic by enforcing the use of factories, service fakes, and proper database lifecycle management.
What it does
- Write feature tests for HTTP routes, JSON APIs, and Livewire components with proper status and JSON path assertions.
- Isolate side effects by implementing fakes for Mail, Notifications, Queues, Events, and the HTTP client.
- Audit test quality using a built-in scanner to find "smells" like hard-coded IDs, missing database traits, or forgotten
->only()calls. - Manage test data via Eloquent factories with states and relationships instead of manual database seeding.
- Standardize suites by converting legacy PHPUnit tests to Pest or setting up parallel testing environments.
How it works
- Detect stack by analyzing
composer.jsonandphpunit.xmlto match the project's testing framework and database configuration. - Scan for smells using the provided Python utility to identify high-risk issues like real HTTP calls or missing assertions.
- Generate tests based on the target code, applying specific patterns for controllers, jobs, or policies.
- Execute and verify tests using
php artisan test, ensuring coverage and addressing any failures without weakening assertions.
Frameworks & tools
Laravel 10 through 12, Pest 2 or 3, PHPUnit 10 or 11, and Python 3.8 for the scanner utility.
Why this beats prompting it yourself
Generic prompts often produce tests with hard-coded URLs and brittle database setups. This skill enforces Laravel-specific best practices like RefreshDatabase, Http::preventStrayRequests(), and route naming, resulting in a suite that is easier to maintain and resistant to environmental drift.
Use cases
- Add comprehensive feature tests for a new JSON API endpoint including validation and auth.
- Identify why a test suite is running slowly or failing intermittently in CI.
- Refactor a folder of PHPUnit tests into clean, modern Pest syntax.
- Ensure all external integrations are properly mocked using Laravel Fakes.
Known limitations
Does not support browser-based E2E testing with Laravel Dusk or Playwright. Requires PHP 8.2 and Composer dependencies installed to execute the tests.
Open source: saizul/laravel-php-skills on GitHub (MIT licence, by Saizul Amin).
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for APIs & Backend.
No support for Laravel Dusk or Playwright. Requires PHP 8.2+. Does not handle static analysis or N+1 query detection.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 1 day ago
- Software
Python 3.8+