Yii Framework Forum: How To Fix It? - Yii Framework Forum

Jump to content

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

How To Fix It? Rate Topic: -----

#1 User is offline   Salman Asif 

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

Posted 10 December 2012 - 11:37 PM

dear yii members,

i am facing a problem can any body tell how to fix it???

i m following Agile's book at chapter 7 page 148 as i ran test suits i.e. on running "phpunit unit/" it give me following error:


Fatal error: Cannot redeclare class ProjectTest in ..path\tests\unit\projectTest.php on line 57

but when i ran it sepratly with "phpunit unit/projectTest.php" it runs fine with no error. can any body tell me how to fix it???


#2 User is offline   Kostas Apazidis (KonApaz) 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,382
  • Joined: 21-February 11
  • Location:Greece

Posted 11 December 2012 - 04:52 AM

Hi Salman

Do you use wampserver or something like that ?

The phpunit on wampserver has some bugs issues and needs few upgrades and configures
Yii is the best php framework in the world!
It is also powerful and flexible for large scale websites
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)

#3 User is offline   mrk 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 41
  • Joined: 07-March 11

Posted 11 December 2012 - 06:06 AM

You've probably named another class ProjectTest by mistake or purposely. I guess you were copy/pasting other test class, you've changed file name but forgot to rename class inside.
So when you run all unit tests PHPUnit is going through file tree and load all classes. If it meets two classes with the same name error "Fatal error: Cannot redeclare class X" occurs. SO solution for it would be to find second class with that name and fix it.

Otherwise if you keep two ProjectTest classes and that's how it should be (because you have to different Project classes under different packages), you can solve this problem by using namespaces:
Inside ProjectTest.php file before
class ProjectTest

you type
namespace SomeName

next you have to replace all usages of methods and classes with it's name with '\' in front of it
For example if you have

you have to change it to

and so on.

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