0

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 ?

1
  • 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 Commented May 16, 2017 at 17:42

3 Answers 3

1

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.

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

4 Comments

Judging from the error message, I'm pretty sure he is running under Windows.
You are right @Cerad. I added Windows install instructions as well.
For what it is worth I think it is just as easy to use composer to install phpunit under the vendor directory.
@Cerad, I agree with you, but I dont know why the installation with Composer didn't work :-/
1

Follow the instructions from here:

https://phpunit.de/manual/current/en/installation.html

Comments

0

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

1 Comment

Hi there @COil. The error used to occur, but looks like the PARSE_CONSTANT error has been fixed. I've experienced this previously. So installing as per Dana Danna link is the correct way to go now if you have the latest.

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.