PHPUnit - Version 3.7.21 instead of Version 6 installed
I suppose you have xampp installed? It comes with PHPUnit 3.x.x preinstalled with PEAR which strangely can not be uninstalled with pear uninstall
. And since its config is in php root folder, that 3-ish version has priority when running phpunit command (even if you have phpunit installed globally) in CMD or PS. How to fix:
- Go to
xampp/php
folder and delete two filesphpunit
(with no extension) andphpunit.bat
. Usually it's enough to prevent older PHPUnit version from being run but let's be on the safer side: - Go to
xampp/php/PEAR
dir and delete two foldersPHPUnit
andPHPUnit2
. - Go to Control Panel, then navigate
System and Security->System
and click "Advanced system settings" link on the left. This will open Advanced tab in System Properties window. Click "Environment Variables" button, then under System Variables select "Path" variable and click "Edit..." button. In the new window, click "New" button and type your path tovendor/bin
folder (if you already installed PHPUnit for your project there will be phpunit.bat file). By default for xamp it looks like this:C:\xampp\htdocs\yourprojectname\vendor\bin
.- Restart your Command Prompt (or PowerShell) window, then type
phpunit --version
to see the that it's PHPUnit 6.x.x now.
- Restart your Command Prompt (or PowerShell) window, then type
P.S. (If you want latest PHPUnit do not use ^6.0 in require string, since it will install v6.0.0, write it in composer.lock file that will never update PHPunit to the latest e.g. 6.2.1 version atm). Just use
composer require --dev phpunit/phpunit
to install the latest stable version for your project.
You run your global PHPUnit version which is installed in another folder. To get the installed version you have to go to the vendor/bin
folder.
vendor/bin/phpunit --version
PHPUnit 6.0.8 by Sebastian Bergmann and contributors.
In newer versions you can run it with bin/phpunit
there should be the executable. When you need another PHP-Version then define it before php74 bin/phpunit
.