Run PHPUnit tests on change

后端 未结 10 1703
星月不相逢
星月不相逢 2021-02-07 11:34

I\'d like to run my PHPUnit tests (or at least a subset of them) whenever a file changes on disk. Very similar to what you can do with \"grunt watch\". I have a project in which

10条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-07 11:51

    A dead simple way to do this, using inotifywait and a bash script:

    #!/bin/bash
    while true; do
      FILE=$(inotifywait --exclude=".*.*sw*" --exclude="4913" ./ --format "%w%f" -e close_write) &&
      clear &&
      phpunit --color $FILE
    done
    

    Then you just run that in a terminal (or however you want) and you're good. I'm running tmux, so I just have a stacked pane set up, with a little window to see my test results. Just run this script in the directory where your tests live.

    Works well for me.

    Also, this script is Vim friendly (Vim creates a file, 4913, during saves, this script ignores it).

    It was totally inspired from various places around the web -- probably even from some of these answers.

提交回复
热议问题