21

I have project on Symfony 2 and i would like use PHPUNIT on Windows 7.

On githut phpunit is:

Composer

Simply add a dependency on phpunit/phpunit to your project's composer.json file if you use Composer to manage the dependencies of your project. Here is a minimal example of a composer.json file that just defines a development-time dependency on PHPUnit 3.7:

{
    "require-dev": {
        "phpunit/phpunit": "3.7.*"
    }
}
For a system-wide installation via Composer, you can run:

composer global require 'phpunit/phpunit=3.7.*'
Make sure you have ~/.composer/vendor/bin/ in your path.

First i use system-wide installation but i dont know when this installed. Next i add to my composer.json require-dev. This installed phpunit in C:/wamp/www/myproject/vendor/symfony. Next i try commands:

 composer install --dev

And i can't use phpunit. In cmd.exe i enter "phpunit" and i have error:

'phpunit' is not recognized as an internal or external command operable program or batch file

How can i use phpunit? I have Windows 7, Wamp server and php 5.4.12.

7 Answers 7

14

When you install PHP-Unit in windows via composer, the global installation will create files in

C:\Users\YOUR_USERNAME\AppData\Roaming\Composer

To execute phpunit easily via command line you need to add path of phpunit.bat file in windows Environment Variables. For this:

  1. Right click My Computer
  2. Go to Properties -> Advance system settings and
  3. Click Environment variables from the Advance tab.

Now add C:\Users\YOUR_USERNAME\AppData\Roaming\Composer\vendor\bin to the windows PATH.

You can now run the phpunit from command. Note that you may need to restart your command prompt for the changes to take effect.

Sign up to request clarification or add additional context in comments.

1 Comment

Also if you are using the terminal via an IDE such as PhpStorm you will need to close and reopen it for the changes to take effect.
13

The bin file of packages are put in the configured bin directory. By default, this is vendor/bin and when you use the symfony standard edition, this is the bin folder.

To execute this bin file, run ./bin/phpunit (or ./vendor/bin/phpunit when not using the Symfony Standard Edition)

Windows users have to put this in double quotes: "bin/phpunit" (or "vendor/bin/phpunit")

2 Comments

I have phpunit in folder C:/wamp/www/myproject/vendor/phpunit. So i go to C:/wamp/www/myproject and put "vendor/phpunit" and i have error '"vendor/phpunit"' is not recognized as an internal or external command operable program or batch file
Yes, but you need to execute a phpunit file, which is in vendor/bin or in bin
9
composer require --dev phpunit/phpunit ^9

The above example assumes, composer is already on your $PATH variable.

You composer.json should look similar to;

{
  "name": "vendor_name/package_name",
  "description": "This project is for practicing writing php unit tests",
  "minimum-stability": "stable",
  "license": "proprietary",
  "authors": [
    {
      "name": "Umair Anwar",
      "email": "[email protected]"
    }
  ],
  "autoload": {
    "classmap": [
      "src/"
    ]
  },
  "require-dev": {
    "phpunit/phpunit": "^9",
    "phpunit/dbunit": "^4.0"
  }
}

Comments

5

Easiest way to install phpunit via composer is to run from project root.

$ composer require phpunit/phpunit

What this would do is, it will create a phpunit folder inside vendor/bin and you can run unit tests like this..

$ ./vendor/bin/phpunit

Comments

2

Too simple operation on Windows with composer and works for me following way:

Install composer https://getcomposer.org/doc/00-intro.md#installation-windows Go to your symphony folder e.g C:\wamp64\www\symfony\UserManagement where is composer.json and run this command. Should be register with global to not have issue $phpunit bash: phpunit: command not found

//old version is 5.7 new 6.4 or put newest version.
composer global require --dev phpunit/phpunit ^5.7

Comments

1

I remember futzing around with the composer dependency stuff for phpunit and never could get it to work.

Instead, from your git bash shell:

mkdir ~/bin
cd ~/bin
curl https://phar.phpunit.de/phpunit.phar > phpunit
chmod +x phpunit

exit out of bash and then start a new bash session.

And you should be good to go. You can echo $PATH to verify you have a path to ~/bin but one seems to added by default.

https://phar.phpunit.de/phpunit.phar

Comments

0

I also came across the same issue and find out the solution by following steps

To run PHPUnit in Windows 7 under WAMP installation

  1. Composer Install

    { "require-dev": { "phpunit/phpunit": "3.7.*" } }

  2. Simply Set Environment Variable The php unit will be install in a vendor dir in vendor/bin

    Path : C:\wamp\www\myproject\vendor\bin;

  3. Open a new Command Prompt C:\Users\guny >phpunit --version PHPUnit 3.7.30 by Sebastain Bergmann

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.