I followed the instructions on the official PHPUnit page to install PHPUnit 6.
composer require --dev phpunit/phpunit ^6.0
However, If I go to the project folder and execute phpunit --version
then I get PHPUnit 3.7.21 by Sebastian Bergmann.
.
Why is PHPUnit 3.7.21 installed instead of PHPUnit 6?
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
.
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:
xampp/php
folder and delete two files phpunit
(with no extension) and phpunit.bat
. Usually it's enough to prevent older PHPUnit version from being run but let's be on the safer side:xampp/php/PEAR
dir and delete two folders PHPUnit
and PHPUnit2
.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 to vendor/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
.
phpunit --version
to see the that it's PHPUnit 6.x.x now. 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With