~/talk

Introduction to WordPress Unit Testing

Talkat WordCamp US 2015 · 2015-12-04..12-06· [wordpress, testing]
slides:none on file

Unit testing claims to give a safety net by isolating functions with test doubles so code behavior is constant and the database is not hit. The demo builds a scaffolded plugin with WP‑CLI scaffolding, uses Composer to require PHPUnit and PHP‑Mock, shows mocking get_option to return "bar" and then adding array defaults, and runs on GitHub with Travis CI. The setup avoids the WP test database, speeds runs (about 200 tests in 2 seconds reported), and the example tests pass.

AI-written summary · about

  1. 0:00Start
  2. 2:53WordPress tests are integration tests
  3. 3:04It's about how pieces of code work together
  4. 3:22Neither is better
  5. 3:36Operating System: unix-based
  6. 3:56PHP version: 5.3 (for code) / 5.4 (for tests)
  7. 4:28PHPUnit
  8. 4:38WP-CLI (optional)
  9. 5:20Add composer.json
  10. 6:11Modify bootstrap.php (created by WP-CLI)
  11. 6:32Our first plugin function
  12. 7:00Our first unit test
  13. 8:03Testing demo_get_option
  14. 8:59Let's try to run it
  15. 9:20Missing test double
  16. 9:45Verifies how you interact with it
  17. 11:32Let's make our function do this for us
  18. 11:50Gives you a taste for test-driven development
  19. 12:13First, a small change to demo_get_option
  20. 12:29Update our test as well
  21. 13:15Creating our failing test
  22. 13:30Changing inputs, outputs and expected values
  23. 14:42Building your testing habit
  24. 15:01Just one loop in your safety net
  25. 15:50Testing is a lot like picking up a new habit
  26. 16:00Hard to stay motivated Chips are soooo tasty!
~/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.