Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPUnit - Version 3.7.21 instead of Version 6 installed

Tags:

php

phpunit

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?

like image 345
Black Avatar asked Mar 09 '17 13:03

Black


2 Answers

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.

like image 144
René Höhle Avatar answered Nov 01 '22 16:11

René Höhle


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:

  1. Go to 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:
  2. Go to xampp/php/PEAR dir and delete two folders PHPUnit and PHPUnit2.
  3. 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 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.
    1. Restart your Command Prompt (or PowerShell) window, then type 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.

like image 22
Goujon Avatar answered Nov 01 '22 16:11

Goujon