Yii Framework Forum: Phpunit Unit/ Not Running Tests - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Phpunit Unit/ Not Running Tests unable to run all tests in directory Rate Topic: -----

#1 User is offline   domino 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 09-October 12

Posted 09 October 2012 - 08:14 PM

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.
0

#2 User is offline   Haensel 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 444
  • Joined: 14-January 11
  • Location:Vienna (Austria)

Posted 10 October 2012 - 08:56 AM

Very weird. Have you tried using either

phpunit ./unit
//or
phpunit unit


Both work for me on Mac OSX
0

#3 User is offline   domino 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 09-October 12

Posted 10 October 2012 - 10:11 AM

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.

View PostHaensel, on 10 October 2012 - 08:56 AM, said:

phpunit ./unit
//or
phpunit unit


0

#4 User is offline   Haensel 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 444
  • Joined: 14-January 11
  • Location:Vienna (Austria)

Posted 10 October 2012 - 10:30 AM

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.
0

#5 User is offline   domino 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 09-October 12

Posted 10 October 2012 - 02:29 PM

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)


View PostHaensel, on 10 October 2012 - 10:30 AM, said:

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.

0

#6 User is offline   Salman Asif 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 06-November 12

Posted 11 December 2012 - 12:59 AM

View Postdomino, on 10 October 2012 - 02:29 PM, said:

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
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users