PHPUnit Installation and Sample Test
- Many people online recommend installing via PEAR. I tried various methods from different blog posts, but all failed.
- The method that worked for me is more straightforward:
Download link:
The download is a .phar PHP extension. Download the PHPUnit version that matches your PHP version.

Follow the instructions at https://phpunit.de/manual/current/en/installation.html#installation.phar.windows step by step.
- Download PHPUnit.phar to a folder, for example:
C:\bin\ - Add this folder
C:\bin\to the Path environment variable - In the command line, navigate to
C:\binand enter: echo @php "%~dpophpunit.phar"%*>phpunit.cmd
In any command line location, enter:
| |
You should see:

At this point, PHPUnit is successfully installed.
Test Example:
SayHello.php
| |
TestSayHello.php
| |
The SayHello class prints “Hello” to the screen and returns “Hello”.
TestSayHello verifies whether the SayHello class correctly returns the “Hello” string.
Run it in the command line, and the test passes.

Configuring PHPUnit in PHPStorm
Older versions of PHPStorm may not support PHPUnit well and will throw:
Warning: require_once(PHPUnit/Runner/Version.php)
See:
This article uses PHPStorm 10. Download link:
https://www.jetbrains.com/phpstorm/?fromMenu
- Open the two files from earlier

- Open Settings: File => Settings
Configure PHP version:

Configure PHPUnit

Sample Test
Select TestSayHello and run it directly. The result:
