PHP Unit Test Discussion (Feb. 12) Recap

We had a lively discussion about our PHPPHP The web scripting language in which WordPress is primarily architected. WordPress requires PHP 5.6.20 unit tests today.

Our goal here is to makemake A collection of P2 blogs at, which are the home to a number of contributor groups, including core development (make/core, formerly "wpdevel"), the UI working group (make/ui), translators (make/polyglots), the theme reviewers (make/themes), resources for plugin authors (make/plugins), and the accessibility working group (make/accessibility). writing unit tests a straight-forward, understandable experience by updating the PHP Unit Test handbook page.

During the meeting, we landed on some practical changes for the handbook page we can make soon.

  • VVV has out-of-the-box support for running WP PHP unit tests. We should suggest using it without giving it an obvious endorsement, as it is not officially endorsed by the project.
  • Getting phpunit running with MAMP (the application) is hard. We should link to Boone’s tutorial on the topic.

The rest of the meeting moved towards outlining our current approach to unit tests, especially in structure. We should discuss if these are best practices, and develop agreed upon standards for the project.

  • Our tests are organized into folders based on component. (browse the phpunit/tests folder)
  • There are a good number of top-level test files in the /tests folder. New tests should not go in these files.
  • We should consider migrating top-level test files into their respective component folders.
  • Tests for a specific function should go inside a single file within a component directory.
  • Generally the test file path has taken the form /tests/phpunit/tests/{component}/{functionInCamelCase}.php
  • Generally a file’s test class has taken the form Tests_{Component}_{FunctionInCamelCase}
  • Test method names should take the format test_{{description_of_what_is_expected}}. For example, test_termmeta_cache_should_be_primed_by_default.

Please leave a comment here if you have any thoughts.

I’ll schedule a meeting next week to continue our discussion.

Thanks to everyone who attended, this was a great meeting.