Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I would like to run some unit Tests individually with PHPUnit, but I have certain classes separated from the Tests, since I am using the symfony framework, and I group the Tests and the Classes in different folders.

I would like to run the Tests individually like this:

php phpunit.phar MyTest.php

The problem is that the test file uses the classes from the controllers, and phpunit doesnt seem to be able to import the needed classes for the test.

This is not a problem to run all the tests together, thanks to phpunit.xml but when I want to run them individualy, its a problem.

How could I fix this?

share|improve this question
 
phpunit has a filter option which you can use. phpunit.de/manual/current/en/… What do you mean by running individually? –  Schleis Jun 4 '13 at 17:27
 
I mean running just 1 test, not all the test in all the files defined in the xml –  Enrique Moreno OB Jun 6 '13 at 10:23
add comment

3 Answers

You have to point phpunit where you have your phpunit.xml config file (because it must know the autoloader for example). If you have default symfony 2 structure it will be in app directory, so just run your test like that (I assume that you are in project root path):

phpunit -c app/ --filter="concreteTestPattern" src/Acme/DemoBundle/Tests/MyTest.php

edit:

Above will run all tests which names match to the pattern: /.*concreteTestPattern.*/

share|improve this answer
 
Thats running all the test in that file. I just want to run one –  Enrique Moreno OB Jun 6 '13 at 10:22
 
Ok, I've edited my answer –  Cyprian Jun 6 '13 at 10:37
add comment

You would use the --filter argument in your PHPUnit command string. This will only run tests that match the pattern given. If you pass only the complete name of the test that you want run, phpunit should only run that test.

If you have a data provider associated with the test and only want to run one test case, you can also filter that by using --filter <testName>::<testcase name>

share|improve this answer
add comment

PHPUnit can be set to execute using a configuration file.

In our Symfony2 project this file is located at app/phpunit.xml.dist.

As this file is suffixed with .dist, you need to copy its contents into a file called app/phpunit.xml.

If you are using a VCS such as Git, you should add the new app/phpunit.xml file to the VCS ignore list.

You will also notice the configuration is specifying the bootstrap file located at app/bootstrap.php.cache. This file is used by PHPUnit to get the testing environment setup.

We can execute this test by running the following command from the root directory of the project. The -c option specifies that PHPUnit should load its configuration from the app directory.

$ phpunit -c app

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.