Phpunit Unit/ Not Running Tests

I’m unable to run all unit tests in my project from a single command. Here is what I try:


root@web:/home/vagrant# cd /github/trackstar/protected/tests/  #change to the tests directory

root@web:/github/trackstar/protected/tests# phpunit unit/   

root@web:/github/trackstar/protected/tests# ll unit/  # nothing happened, so confirm the tests are in the directory

total 20

drwxr-xr-x 5 501 dialout  170 Oct  4 04:26 ./

drwxr-xr-x 9 501 dialout  306 Oct  4 04:26 ../

-rw-r--r-- 1 501 dialout  144 Oct  4 04:26 DbTest.php

-rw-r--r-- 1 501 dialout 1161 Oct  9 00:52 IssueTest.php

-rw-r--r-- 1 501 dialout 3989 Oct  9 03:14 ProjectTest.php

root@web:/github/trackstar/protected/tests# phpunit unit/DbTest.php   #it works when run one at a time as shown here

PHPUnit 3.6.12 by Sebastian Bergmann.


Configuration read from /github/trackstar/protected/tests/phpunit.xml


.


Time: 0 seconds, Memory: 6.75Mb


OK (1 test, 1 assertion)

Any ideas? OS = ubuntu precise.

Very weird. Have you tried using either


phpunit ./unit

//or

phpunit unit



Both work for me on Mac OSX

I tried both of these with no luck. I’ve also tried rebooting. However, I think I’ve made some progress:


root@web:/github/trackstar/protected/tests# phpunit unit/

root@web:/github/trackstar/protected/tests# echo $?

255

There is an exit code of 255 after running that phpunit unit/. Even though it doesn’t display an error, it is not exiting with exit code 0. I remember that 255 is a php error. So I just checked my php logs:

[10-Oct-2012 14:36:48 UTC] PHP Fatal error: Cannot redeclare class ProjectTest in /github/trackstar/protected/tests/unit/ProjectTest.php on line 100

I am confused though, because this is line 100 (only a line to close the class):


}

And I can run ProjectTest.php without issues if I do this:


root@web:/github/trackstar/protected/tests# phpunit unit/ProjectTest.php 

PHPUnit 3.6.12 by Sebastian Bergmann.


Configuration read from /github/trackstar/protected/tests/phpunit.xml


F....


Time: 1 second, Memory: 11.00Mb


There was 1 failure:


1) ProjectTest::testCreate

Failed asserting that null matches expected '1'.


/github/trackstar/protected/tests/unit/ProjectTest.php:66


FAILURES!

Tests: 5, Assertions: 13, Failures: 1.

One of my tests fails. But I would expect running phpunit unit/ would allow me to see that. I’m not exactly sure what are the next steps to troubleshoot. I am expecting this one test to fail because I’m following the trackstar TDD and coded that test before the functionality. Also, I commented out the failing test, and it has no impact on phpunit unit/ working.

The "error in line xyz" messages are bogus most of the time. But the redecleration of a class is a php error so I guess you are using


class ProjectTest ....

twice in your code. You are only supposed to have one ProjectTest class in all of your files. So search for this line and if there are two of them you know what’s wrong.

Wow - yes it was obvious, so I decided to actually do the search, and yes, I had named another class ProjectTest as well (when I had meant to name it IssueTest). Now it works:


root@web:/github/trackstar/protected/tests# phpunit unit/

PHPUnit 3.6.12 by Sebastian Bergmann.


Configuration read from /github/trackstar/protected/tests/phpunit.xml


.........


Time: 0 seconds, Memory: 10.75Mb


OK (9 tests, 22 assertions)

thank u found my answer too… thank u very much