Installing PHPUnit on Windows and VS Code

Here are some methods I used to get PHPUnit working on my Windows machine with Visual Studio Code. This post will stick to the “hows” instead of the “whys” but I’ll add some links along the way for additional info.

  1. Head over to [https://phpunit.de] and download the PHPUnit Archive
  2. Make sure to rename the file to phpunit.phar leaving the version number in the name won’t work
  3. Create a folder to hold the file (I used C:\PHPUnit)
    1. paste phpunit.phar into this folder
  4. Hit your windows key and type env then click “Edit the system environment variables”

set the path

  1. In System Properties: Click the Environment variables button
  2. Under the user variables section: click the line that starts with
    Path then click the edit button
  3. Click new and type the path to your folder C:\PHPUnit

This will ensure that the system can find the batch file we will create below

  1. Right click in the C:\PHPUnit folder choose new -> text document
  2. Rename the file phpunit.bat
  3. Edit the file and enter the following

@echo off
php c:\dev\phpunit.phar %*

  1. Next go into Visual Studio Code and install the PHPUnit Extension

install the php unit plugin

  1. In VS Code hit ctrl + shift + p to open the command palette
  2. Type pref and select “Preferences open user settings”
  3. In the settings search bar type phpunit and hit enter
  4. Restart Visual Studio code
  5. Open a PHP file and hit ctrl + shift + p to bring up the command palette
  6. Type Phpunit and select “PHPUnit Test”
  7. You will get a prompt to select a portion of code to test. Select
    any of the options as we aren’t running a real test

If all is good you should see something like the following:

test it out

And that’s about it! If you want to learn more about actually writing tests check out this great tutorial by Codecourse: Codecourse tutorial

Matt Detwiler
Director, IT Operations

My interests include IT leadership/mentoring, business systems, software development, gadgets, gaming, and the great outdoors. I love networking, click my contact link and let's do coffee!