Testing With Fakes
summary
Shows how Laravel’s built-in fakes turn real side effects into testable assertions: default mailer is an in-memory array and queue driver defaults to sync (causing jobs to run during tests); use Mail::fake and assertOutgoingCount / assertQueued to verify one mailable; use Bus::fake or Bus::fakeExcept / onlyFake to let a downstream job actually run; factories can use createQuietly to suppress model events; HTTP::preventStrayRequests highlights unexpected external calls; real-time facades (prefix with Facades\) let LanguageAI be mocked with expects rather than shouldReceive.
AI-written summary · about
chapters (11)
- 0:00Introduction to test doubles
- 1:45Modern fakes in Laravel
- 3:53Testing naive controller actions
- 6:16Mail facade fakes explained
- 10:32Bus facade fakes and assertions
- 14:25Event facade fakes in jobs
- 17:52Refactoring with lifecycle events
- 20:19HTTP facade fakes for external calls
- 25:33Real-time facades and mocking
- 29:02Confidence in testing with facades
- 29:44Q&A on testing approaches
related talks
34mBetter Testing in Laravel
29mEffective tests and testing effectively
30mFaking It - The Art of Testing Using Verified Fakes
52mLaravel Testing Tips, Techniques and Pitfalls
25mFakes over Mocks: Shift your paradigm and identify monolithic code
01h 00mStop mocking everything
52mWriting Unit Tests Using PHPUnit
51mAvoiding Mockageddon
