guh.me - gustavo's personal blog

Run PHPUnit tests every time a file changes

βΈ»

Running unit tests manually sucks and is a waste of time. What if you could automatically run your tests every time a file changes? Well, you can! :P

A simple bash script that uses inofity-tools can detect changes in the filesystem and run all the commands you need. In this case, I wanted to run my tests when anything changed in the /test folder, clear the screen and display the PHPUnit results - below follows the resulting script:

while true; do
  inotifywait -r ./test -e modify,close_write,moved_to,move,create,delete &&
  clear &&
  phpunit --configuration phpunit.xml
done