Running PHPunit PHAR from anyware under Windows CLI

1- Download and move it to a folder
For example : “D:\Tools\phpunit\phpunit.phar”

2- Add “D:\Tools\phpunit\” to your Windows PATH

Unfortunately this will work only if you execute phpunit from “D:\Tools\phpunit\”, trying to do it from another folder (Obviously your project folder aka “D:\Workspace\MyAwesomeProject”) will not work

 php phpunit.phar . Could not open input file: phpunit.phar

To fix this, just create a new file “phpunit.bat” in the same folder as “phpunit.phar” with the following content

php “%~dp0phpunit.phar” %*

More about the weird %~dp0 :

If you are using cygwin/mintyy, create also a file “phpunit”


dir=$(d=$(dirname “$0”); cd “$d” && pwd)

# if running in cygwin
if command -v ‘cygpath’ >/dev/null 2>&1; then
if [[ $(which php) == /cygdrive/* ]]; then
dir=$(cygpath -m $dir);

dir=$(echo $dir | sed ‘s/ /\ /g’)
php “${dir}/phpunit.phar” $*


Now you can call phpunit.bat or directly phpunit if using cygwin

phpunit --version PHPUnit 4.1.0 by Sebastian Bergmann.  $ phpunit --colors MoneyTest PHPUnit 4.1.0 by Sebastian Bergmann.  .  Time: 39 ms, Memory: 4.00Mb  OK (1 test, 1 assertion)