Run PHPUnit Tests Whenever Your Files Change
The immediate key take away from this video is the following script:
#!/bin/sh
dir1="$PWD/src"
dir2="$PWD/tests"
while inotifywait -qre modify "$dir1" "$dir2"; do
make run_tests
done
Of course this assumes you have a Makefile
with a run_tests
entry in there. Mine, for example is:
run_tests:
@docker-compose exec php php vendor/bin/simple-phpunit
Watch the video for a better understanding of this whole process.
A quick note: This method is pretty much no fun for Windows, or Mac users. I believe OSX has a variation of inotify-tools
so adapting this method may be possible.
Alternatively, you can use Node / tools like Grunt, or Gulp. For me this is OK if I already have PHP and JS intermixed in the same project. If I have to add JS dependencies solely to run my PHP tests, then I would prefer this option.
Your mileage may vary, and that's a-ok.