How to install PHPUnit with WAMP?

14,968

Solution 1

Try this blog : http://nishutayaltech.blogspot.com/2011/04/installing-phpunit-on-windows.html

This setup is for Windows. Hope this will help you.

Solution 2

Also check this out, may be useful http://www.mark-leong.com/installing-php-and-phpunit-on-windows-7/

// adding required pear channels

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

// performing install

pear install --alldeps --force phpunit/PHPUnit

If everything ok, check whether phpunit have been installed by putting in command line

phpunit -v

If you encountered any errors or interrupted installing

pear clear-cache

may be usefull in that case.

Solution 3

1) download https://phar.phpunit.de/phpunit.phar 2) run it via php phpunit.phar

Btw if that file ever goes away you can look at the original directions here: https://github.com/sebastianbergmann/phpunit

Solution 4

I recommend using composer. It can be used per project, but also 'globally'.

Make a folder on your C drive called 'globalpackages', then cd into it from the command line.

run 'composer require phpunit/phpunit'

once that finishes run 'composer install'

once that finishes you can check the contents of C:\globalpackages\vendor\phpunit' and should see two phpunit files, one of them a bat.

Add C:\globalpackages\vendor\phpunit to your system path and then you will be able to run phpuni from anywhere on your system.

Solution 5

For me this is the fastests and easiest way.

  1. Make sure you have wamp with WAMP with PHP 7 installed as phpunit requires PHP7 to work! or at least 6.2

  2. Go to folder wamp64\bin\php\php7.0.10 (wherever you installed your wamp - BEWARE last folder is name of PHP version you have so it might be different then above )

We will be working in this folder during entire installation. So if I say edit file etc it means in this folder.

  1. Download newest version of phpunit from https://phpunit.de/

At the time of writing this I get version phpunit 6.2 and php7.0.10 4. Copy downloaded file to wamp64\bin\php\php7.0.10 folder For me it's: phpunit-6.2.2.phar for you it might be different version.

  1. Now change name of the phpunit-6.2.2.phar to phpunit.phar

  2. Now make sure you have added your php to PATH in Environment Variables To do this on Windows 10 and Windows 8

6a. In Search, search for and then select: System (Control Panel)

6b. Click the Advanced system settings link.

6c. Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.

6d. In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Paste location of your PHP. For me it would be: D:\AnyFolderYouInsalledWampTo\wamp64\bin\php\php7.0.10

(if in PATH there was other command or path just add ";" at the end. For exmaple:

%someOtherCommand%; D:\AnyFolderYouInsalledWampTo\wamp64\bin\php\php7.0.10)

6e. Click OK. Close all remaining windows by clicking OK.

  1. In cmd (to run cmd go to search in Windows and type cmd.exe and click Enter) go to folder wamp64\bin\php\php7.0.10 (to go to folder type for example cd D:\AnyFolderYouInsalledWampTo\wamp64\bin\php\php7.0.10)

  2. now once you are in this folder run this command in cmd: echo @php "%~dp0phpunit.phar" %* > phpunit.cmd

  3. now run this command:

phpunit

you should get list of all commands available in phpunit

now run this:

phpunit --check-version

you will get info what phpunit version you have and if you are using the newest version.

  1. if this doesn't work go to wamp64\bin\php\php7.0.10

  2. Edit file phpunit.bat

  3. Add this line:

    ""%PHPBIN%" "D:\AnyFolderYouInsalledWampTo\wamp64\bin\php\php7.0.10\phpunit.phar" %*

  4. Repeat point 9.

  5. if it still doesn't work let me know.

Share:
14,968

Related videos on Youtube

Elle Stewards
Author by

Elle Stewards

Updated on September 14, 2022

Comments

  • Elle Stewards
    Elle Stewards over 1 year

    I'm a newbie programmer and I have tried for an embarrassingly long time to get PHPUnit set up and working with WAMP. I have read the documentation and went through various sites to see what I'm doing wrong, but I give up! I need someone to explain this to me like I'm mildly retarded.

    I've probably seen all the guides on how to set it up, but feel free to link me to something you believe is foolproof!

  • kleopatra
    kleopatra over 10 years
    Note that link-only answers are discouraged, SO answers should be the end-point of a search for a solution (vs. yet another stopover of references, which tend to get stale over time). Please consider adding a stand-alone synopsis here, keeping the link as a reference.
  • Luke
    Luke over 10 years
    Why is setting this up so complicated?
  • Pragnesh Chauhan
    Pragnesh Chauhan over 10 years
    i try to install using this link but get this error "C:\php>phpunit -v PHPUnit 3.4.15 by Sebastian Bergmann. unrecognized option -- v"
  • adavea
    adavea about 10 years
    I think this has gotten a lot easier over the last year.
  • orszaczky
    orszaczky over 9 years
  • orszaczky
    orszaczky over 9 years
  • stormwild
    stormwild over 8 years
    composer global require "phpunit/phpunit=5.1.*" phpunit.de/manual/current/en/…
  • Ephesiel
    Ephesiel over 3 years
    Thanks, it works well. Just the .cmd or .bat didn't worked, I should wrote phpunit.cmd to run the command. Why don't you just rename phpunit.phar to phpunit ?