Install PHPUNIT with Composer
When you install PHP-Unit in windows via composer, the global installation will create files in
C:\Users\YOUR_USERNAME\AppData\Roaming\Composer
To execute phpunit
easily via command line you need to add path of phpunit.bat
file in windows Environment Variables. For this:
- Right click
My Computer
- Go to
Properties -> Advance system settings
and- Click
Environment variables
from theAdvance
tab.
Now add C:\Users\YOUR_USERNAME\AppData\Roaming\Composer\vendor\bin
to the windows PATH
.
You can now run the phpunit from command. Note that you may need to restart your command prompt for the changes to take effect.
The bin file of packages are put in the configured bin directory. By default, this is vendor/bin
and when you use the symfony standard edition, this is the bin
folder.
To execute this bin file, run ./bin/phpunit
(or ./vendor/bin/phpunit
when not using the Symfony Standard Edition)
Windows users have to put this in double quotes: "bin/phpunit"
(or "vendor/bin/phpunit"
)
composer require --dev phpunit/phpunit ^7
The above example assumes, composer is already on your $PATH variable.
You composer.json should look similar to;
{ "name": "vendor_name/package_name", "description": "This project is for practicing writing php unit tests", "minimum-stability": "stable", "license": "proprietary", "authors": [ { "name": "Umair Anwar", "email": "umair.anwar@gmail.com" } ], "autoload": { "classmap": [ "src/" ] }, "require-dev": { "phpunit/phpunit": "^7", "phpunit/dbunit": "^4.0" }}