How To Fix It?

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:

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???

thanks

Hi Salman

Do you use wampserver or something like that ?

The phpunit on wampserver has some bugs issues and needs few upgrades and configures

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


Yii::t()

you have to change it to


\Yii::t()

and so on.