~/talk

How (Not) to Write Testable Code

Talkat WordCamp Nuremberg 2016 · 2016-04-16..04-17· [developer-experience, testing]
slides:none on file

Shows concrete PHP and JavaScript examples that break unit testing (missing return values, exit/redirect calls, creating dependencies inside methods, globals, singletons, deep object chains, and one 3–4 digit-condition monster method) and demonstrates fixes: replace with dependency injection and factories, wrap globals/exit/redirect in testable wrappers, add singleton reset, apply Law of Demeter, and split large methods. Uses real tooling: PHPUnit, Mockery, Tape, Sinon, Brain Monkey/WP Mock and publishes a GitHub repo with before/after pull requests.

AI-written summary · about

  1. 0:00Start
  2. 8:37Example 2: Test
  3. 9:21Example 2: Mockery Version
  4. 9:36Example 2: JavaScript Version
  5. 10:35WP Mock Version
  6. 13:19Solution: Delegation
  7. 16:12Solution: Dependency Injection
  8. 17:28Solution: Use a Factory
  9. 20:01Issue: Using Unresettable Singletons
  10. 20:38Solution: Add a reset() Method
  11. 24:18Solution: Wrap Static Method
  12. 27:09Solution: Write Modular Code
~/search
type to search 6,518 conferences, 143,918 speakers and 192,133 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
← →
on a talk: 5 seconds back / forward
0–9
on a talk: jump to 0%–90% of the recording
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.