Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install phpunit on windows

How to install phpunit?

I read documentation https://github.com/sebastianbergmann/phpunit, but have an error:

>pear upgrade PEAR
Nothing to upgrade

>pear config-set auto_discover 1
config-set succeeded

>pear install pear.phpunit.de/PHPUnit
No releases available for package "pear.phpunit.de/PHPUnit"
install failed

How can I fix this error?

like image 383
Dmitry Avatar asked Sep 29 '12 18:09

Dmitry


People also ask

What is PHPUnit testing?

PHPUnit is a unit testing framework for the PHP programming language. It is an instance of the xUnit architecture for unit testing frameworks that originated with SUnit and became popular with JUnit. PHPUnit was created by Sebastian Bergmann and its development is hosted on GitHub.


3 Answers

Try the following instructions:

  1. In the command prompt, switch to the directory that you installed PHP to by running cd C:\php\
  2. Then install PEAR by running php go-pear.phar
  3. Press Enter to accept the default when it asks you “Are you installing a system-wide PEAR or a local copy?”
  4. Press Enter again to accept the file layout.
  5. Press Enter to finish.
  6. Run the following commands (they may take a while to update, be patient):
    • pear channel-update pear.php.net
    • pear upgrade-all
    • pear channel-discover pear.phpunit.de
    • pear channel-discover components.ez.no
    • pear channel-discover pear.symfony-project.com
    • pear update-channels
  7. Clear your pear cache pear clear-cache
  8. To install PHPUnit, run pear install --alldeps --force phpunit/PHPUnit
  9. To test that PHPUnit was successfully installed, run phpunit -v
like image 166
Satya Avatar answered Oct 16 '22 13:10

Satya


Old answer (2014): It's said that phpunit will not be available via PEAR since December 2014.
So it's easy to install it using composer:

composer global require "phpunit/phpunit=4.1.*"

Update 2019: it should be installed as a local (for your project) development package:

 composer require --dev phpunit/phpunit ^8

Update 2020: it should be installed as a local (for your project) development package: composer require --dev phpunit/phpunit ^9.3

like image 49
Dmitry Avatar answered Oct 16 '22 13:10

Dmitry


As said by @Wilt Installation via pear doesn't works any longer. Follow below steps instead

Step I: Create a directory named bin in C drive.

Step II: Now add the path C:\bin to your environment.

  • To do this click on Windows icon and right click on Computer and then select Properties.
  • Then click on Advanced system settings -> Advanced -> Environment Variables.
  • In the System variables section scroll down and select the line where the Variable column value is Path. Click on Edit.
  • Now add (append at the end) ;C:\bin at the end.

Step III: Download phpunit phar file to C:\bin folder.

  • If you are PHP 7 then download the phar file from https:// phar.phpunit.de/phpunit-6.2.phar. Else if you are using PHP 5.6 then download the phar file from https:// phar.phpunit.de/phpunit-5.7.phar.
  • Once downloaded rename the file to phpunit.phar and move it to C:\bin folder.

Step IV: Create a batch script phpunit.cmd

  • Open command prompt. Type cd C:\bin and hit enter.

  • Then type echo @php "%~dp0phpunit.phar" %* > phpunit.cmd and hit enter.

To verify PHPUnit has been installed type phpunit --version in command prompt. You should get something like PHPUnit x.y.z by Sebastian Bergmann and contributors.

Reference: https://perials.com/installing-phpunit-windows/

like image 12
Suraj Avatar answered Oct 16 '22 13:10

Suraj