Elle Stewards
Elle Stewards

Reputation: 225

How to install PHPUnit with WAMP?

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 in simple terms.

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!

Upvotes: 15

Views: 15463

Answers (5)

Nishu Tayal
Nishu Tayal

Reputation: 20830

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

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

Upvotes: 12

Emil
Emil

Reputation: 123

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.

Upvotes: 1

S..
S..

Reputation: 5758

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.

Upvotes: 2

adavea
adavea

Reputation: 1602

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

Upvotes: 2

Yehor
Yehor

Reputation: 6793

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.

Upvotes: 4

Related Questions