Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introducing Tests to Legacy Applications

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →

Introducing Tests to Legacy Applications

Avatar for Marcus Moore

Marcus Moore

June 25, 2025

More Decks by Marcus Moore

Other Decks in Technology

Transcript

  1. why? • I don't trust myself • No one can

    remember everything • Improved confidence moving forward
  2. when? • Yesterday • Today • Before refactoring • When

    writing new code • or before it is merged • Before starting a bug fix
  3. how? • Start small. Know that it will take time

    • Get buy-in from the team • (I) skip browser testing and stick with phpunit/pest • CI
  4. foundation • Each test starts "clean" and builds up the

    world it needs • Application state needs to be cleared after each test • Laravel handles database via migrations and RefreshDatabase trait • DBML to Migration Files
  5. foundation - organization It's ok to have a bunch of

    test classes • UserTest • CreateUserTest • ShowUserTest • UpdateUserTest
  6. foundation - test class structure • setUp() • permissions •

    validation • cannots • cans • helpers
  7. the process - test method structure !" Arrange Settings!#enableMaintenanceMode(); !"

    Act $response = $this!$get('/home'); !" Assert $response!$assertSee('Come back later!');
  8. the process - in practice • Replicate the bug •

    Write a failing test to demonstrate the failure • Fix the bug
  9. the process - in practice • Unit test helper functions

    as you come across them • maybe PR it separately? • Fight the urge to refactor • Sometimes it's best just to document the current behavior even if it is a "bug"
  10. diving in • snipe-it - A free open source IT

    asset/license management system
  11. !

  12. Resources • Chris Hartjes (grumpy programmer) • Book - The

    Grumpy Programmer’s Guide To Testing PHP Applications • Book - The Complementary PHP Testing Tools Cookbook • Video - You're (Probably) Testing Things Wrong
  13. ❓