Installing PHPUnit on Windows

Below are the steps to install PHPUnit on Windows. Irrespective of whether you are using WAMP or XAMP installation steps shall remain the same.

  • Step I: Create a directory named bin in C drive.
  • Step II: Now add the path C:\bin to your environment.
    To do this click on Windows icon and right click on Computer and then select Properties.

    Setting Path variable - 1

    Then click on Advanced system settings in the left sidebar.

    Setting Path variable - 2

    Now in the Advanced tab click on Environment Variables button at the bottom left.

    Setting Path variable - 3

    In the System variables section scroll down and select the line where the Variable column value is Path. Click on Edit.

    Setting Path Variable - 4

    Now right click into the Variable value input box and copy it’s value.

    Setting Path Variable - 5

    Paste it in Notepad. Now add ;C:\bin at the end.

    Setting Path Variable - 6

    Now copy all this and paste it in Variable value. Save it.

  • Step III: Download phpunit phar file to bin folder.
    If you are using WAMP with PHP 7 then download the phar file from https://phar.phpunit.de/phpunit-6.2.phar. Else if you are using PHP 5.6 then download the phar file from https://phar.phpunit.de/phpunit-5.7.phar. Once downloaded rename the file to phpunit.phar and move it to C:\bin folder.
  • Step IV: Create a batch script phpunit.cmd
    Open command prompt. Type cd C:\bin and hit enter. Then type
    echo @php "%~dp0phpunit.phar" %* > phpunit.cmd and hit enter. Close and again start command prompt.
    That’s it. To verify PHPUnit has been installed type phpunit --version in command prompt. You should get something like PHPUnit x.y.z by Sebastian Bergmann and contributors.

Join the discussion

  1. I am using Windows 10, php 7.1.17, 64bit. I following your instructions to the T, and yet, Step IV does not work, nothing gets displayed. I am using WampServer 3.13. When inside Wamp, i click on the local host, it works. I am using Explorer for this, and http://localhost/ does bring up the index.php in my www folder.

    C:\Users\owner>phpunit –version
    Could not open input file: c:\bin\phpunit.phar

    My path is:
    C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\binaries\php\php_runningversion;C:\app\owner\product\11.2.0\dbhome_2\bin;C:\app\owner\product\12.1.0\dbhome_1\bin;C:\app\owner\product\11.2.0\dbhome_1\bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;c:\python27;C:\Program Files (x86)\Java\jdk1.7.0_51\bin;C:\Program Files\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files\OpenVPN\bin;C:\Program Files (x86)\Zend\ZendServer\share\ZendFramework\bin;C:\Program Files (x86)\Zend\ZendServer\bin;C:\Program Files (x86)\Zend\MySQL55\bin;C:\Program Files (x86)\Brackets\command;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\Git\cmd;C:\HashiCorp\Vagrant\bin;c:\bin;

  2. Gourav Pathela says:

    Thanks a lot for help. It was very useful.

Leave a Reply

Your email address will not be published. Required fields are marked *