Skip to content

Instantly share code, notes, and snippets.

@kasparsd
Created July 3, 2018 14:09
Show Gist options
  • Save kasparsd/e9639ec9b0601e0dbdbf0d1b63ff01a7 to your computer and use it in GitHub Desktop.
Save kasparsd/e9639ec9b0601e0dbdbf0d1b63ff01a7 to your computer and use it in GitHub Desktop.

Running WordPress Unit Tests Inside Docker Inside Vagrant

We start in the theme folder.

  1. Capture the current composer command and store it as $CMD.

  2. Find the relative path to our current working directory from the root of the project directory. Find the path to the Vagrantfile levels down from the current directory. There must be one because our theme is in a subdirectory of the site repository.

  3. Store the relative path to our theme folder as $RELATIVE_CWD. Use pwd -P to get the realpath to the current directory. Substract the absolute path to the Vagrantfile from the theme directory to get the relative theme directory.

  4. SSH into the Vagrant machine and run the $CMD command inside the phpfpm docker container with a specific Composer working directory.

    $ vagrant ssh -c "cd /vagrant && docker-compose run phpfpm $CMD --working-dir=$RELATIVE_CWD"
    
  5. Boom!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment