What is Laravel's testing with Mocking and Faking?

Answer

Laravel provides built-in fakes for common services that make testing clean without hitting real external services. Mail::fake() — prevent emails from sending, assert with Mail::assertSent(WelcomeEmail::class, fn($mail) => $mail->hasTo("alice@example.com")). Queue::fake() — prevent job dispatching, assert with Queue::assertPushed(ProcessPodcast::class). Event::fake() — prevent events from firing. Notification::fake() — prevent notifications. Storage::fake("s3") — use a fake in-memory disk. Http::fake() — mock outgoing HTTP requests: Http::fake(["example.com/*" => Http::response(["name" => "Alice"])]). Beyond fakes, use $this->mock(UserRepository::class) for class mocking via Mockery. These tools enable fast, deterministic tests without external dependencies.