Stub: A simplified replacement for a dependency in testing — it returns hardcoded responses without executing real logic. Similar to a mock, but stubs typically focus on providing canned answers rather than verifying calls. A stub is a simple stand-in for a real dependency in a test. It returns fixed answers without doing real work, so the code under test can run in isolation.
A stub for a payment gateway might always return "approved", so you can test what your checkout does after a successful payment without calling a real payment provider or spending money.
What should you keep in mind with Stub?
The difference from a mock is focus. A stub provides answers; a mock also checks how it was called, such as whether charge() was called exactly once with the right amount. Laravel offers fakes like Mail::fake() and Http::fake() that combine both. Use stubs for external services and slow dependencies, and keep tests that exercise real database logic against a real test database.
Master end-to-end testing with Playwright and Cypress to build reliable test suites that catch bugs, improve confidence, and enable fast deployment. Use when implementing E2E tests, debugging flaky tests, or establishing testing standards.
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.