0
votes

I want to proceed to unit testing on my Symfony3.2 project.

But 'phpunit' command is not working : when I run phpunit, it returns “'phpunit' is not recognized as an internal or external command, operable program or batch file.”

Though, everything seems to be correctly set up. I searched the internet and didn't find anything. So, could somebody help me please ?

3
vendor/bin/phpunit is all you need assuming you started with the usual symfony composer.json file. The other answers deal more with installing phpunit globally. If still not found do a composer require-dev phpunit/phpunit - Cerad

3 Answers

1
votes

Link only answers are not acceptable on Stackoverflow.

Here are the steps to install on Linux:

wget https://phar.phpunit.de/phpunit-6.1.phar
chmod +x phpunit-6.1.phar
sudo mv phpunit-6.1.phar /usr/local/bin/phpunit
phpunit --version

Verify the version is shown as 6.1.x and then from your Symfony directory you can now run:

phpunit

and your tests should run.


EDIT #2

Based on feedback from Cerad. Use these commands to install on windows:

  1. Make a directory C:\bin
  2. Download https://phar.phpunit.de/phpunit-6.1.phar to C:\bin
  3. Rename the file phpunit.phar
  4. Open a command prompt and enter the following:

cd C:\bin
echo @php "%~dp0phpunit.phar" %* > phpunit.cmd

Then you can enter:

phpunit --version

and you should see the version shown. Also you need to add C:\bin to your environment PATH.

0
votes

The new way to go as of Symfony 3.2 is to use the phpunit bridge as explained in this blog post.