The inability to access or use your installed PHPUnit is a common error in PHPUnit especially if you are using XAMPP.
composer require --dev phpunit/phpunit ^9.2
..to check the version via the command-line interface and see version 3.7x. Then this article is for you. Normally xampp comes with version 3.x.x of PHPUnit. That is what is overriding your installed version.
Here is how I resolved this same problem recently along with its associated error messages.
- Go to xampp/PHP/pear directory. There you will see two folders named PHPUnit and PHPUnit2. Delete both folders.
- Go to xampp/php folder you will see two files named PHPUnit and another phpunit.bat. Delete both files.
- Go to environment variable settings. Just type env in your system search bar and hit enter. You will see the panel on the image below. Click the button I circled in red.
Copy the path to your PHPUnit C:\xampp-main\htdocs\projecFolder\vendor\bin
Then click on the places highlighted in red and click “Edit”, click “new” on the panel that will pop up. Add the path you just copied.
5... Restart your command prompt or open another command prompt. Type PHPUnit –version, you will see your installed version.
That is it. Now you can move on with your adventure in PHP unit testing.
- Ikechukwu Unegbu