PHPUnit testing setup

Windows 10 - I can get both phpunit --version (7.5.9) and run of an isolated unit test for oscarotero/env for wp-config constants from .env files successfully with the following:

Once Per Windows Installation

Once Per Lightning Site Creation
See original thread regarding getting Git Bash Terminal to setup PHP environment via local’s script

  • Via Local open Site Shell once and then close the command prompt
  • Go to ~/AppData/Roaming/Local/ssh-entry/
  • Find the right .sh script that corresponds to what Local opens when opening Site Shell. Copy the filename/path to the .sh for your desired site. (Sort by date of creation, or the comments in each .sh make it relatively easy to find).
  • Go to your VS Code project workspace (same place that /app/public/ would contain your WP installation) and create ssh.sh with one line to execute the Local specific .sh file. Example
    “sh ~/AppData/Roaming/Local/ssh-entry/_LL1zMTxi.sh”

Every time you want to use PHPUnit (or WP CLI)

  • Open your bash terminal to ~/Local Sites/example.local/
  • sh ssh.sh
  • From that point you should be able to run phpunit --version

This wouldn’t cover Grunt or other dependencies you may require for execution. I’m exploring mocking tools like Automattic/wordbless to reduce the scope of each unit test to the actual function/class I care about.

Over a few Local versions I’ve seen a few errors pop up when running the “sh ssh.sh” step. Re-running the Local Open Site Shell via UI once has generally resolved those.