Problem With PHPUnit and Yii

Hi, i’m starting with the Yii framework, following the Book 'Agile Web Application Development with Yii 1.1 and PHP5", and i’m kind of stuck.

I’ve to install PHPunit and selenium-server(wich i dont know how to use), but i made it to install both and start testing with the PHPUnit, but i’m getting several error messages when i try to run the excersises.

This is what i did.

on Windows Console i go to my webapp file and then


cd protected/tests  

phpunit functional/SiteTest



i got this Error Message


Class functional/SiteTest coulld not be found in functional/SiteTest.php

Then after some searching on the web i find that i must be on the .php file before tested.

then i did this


cd protected/tests/functional

phpunit SiteTest 

...

Time:00:00

OK (2 tests)

Following the book it says that i must try with the WebTestCase.php file

so i did this


-->cd protected/tests

-->phpunit WebTestCase.php

This is what i get

-->PHP Fatal error: Class 'CWebTestCase' not Found in C:\..\WebRoot\demo\protected\tests\WebTestCase.php on line 16

-->Fatal Error: Class 'CWebTestCase' not found in C:\..\WebRoot\demo\protected\tests\WebTestCase.php on line 16



after many hours of trying to fixed i give up and keep throght with the book, but then i unfortunately find another error like the one before.

I was told to do This, create a unit Test, called "MessageTest.php" and store in "protected\test\unit", a that file contains


<? php  class MessageTest extends CTestCase {} ?>

after this i should tested it with phpunit

i did this


--> cd /protected/test/unit

--> phpunit MessageTest.php

-->PHP Fatal Error: Class 'CTestCase' not Found in C:\..\webroot\demo\protected\tests\unit\MessageTests.php on line 3

-->Fatal Error: Class 'CTestCase' not Found in C:\..\webroot\demo\protected\tests\unit\MessageTests.php on line 3



For what i could understand the Extends of the Yii Framework/tests classes are invisible to the phpunit. I’ve trying to fixed unsuccessfully. I’m right now sick of this, i could keep reading the book but for what i see, i need this commands to in right performance, but i dont know what i could do.

If you need any other info to help to fix my problem i could give it, thanks :)

PD:

this is mi Windows console path (only the ones relevant for this problem):

PATH=C:\ApacheServer\php\;C:\ApacheServer\www\Yii;C:\ApacheServer\www\Yii\Framework;

and this is my include_path on the php.ini

include_path = ".;c:\ApacheServer\php\;c:\ApacheServer\www\Yii\"

i modified both of then a lot of times trying to solve this.

this are the routes of Apache, PHP 5, Phpunit.bat, my WebRoot and Yii

c:\ApacheServer\Apache <<< Apache

c:\ApacheServer\PHP5 <<< PHP5

c:\ApacheServer\PHP5 <<< Phpunit.bat

c:\ApacheServer\www\ <<< WebRoot

c:\ApacheServer\www\Yii <<< Yii

What’s your version of phpunit? The yii test cases require phpunit >= 3.5.

Please also try to use code highlighting in your posts (The "<>" button in the editor), even for the console output. It would make it much more readable.

The version i was able to install of phpunit sucesfully was 3.0(the one used on the book), i got a lot of problems when i tried to install phpunit 3.6 with pearl. I’ll try of install phpunit 3.5 or 3.6. Thanks :)

I think the error shown is because unit tests bootstrap is not used.

Instead of running tests from the "/protected/test/unit" try to do it from "/protected/test" where bootstrap.php is placed:




--> cd /protected/test

--> phpunit unit/MessageTest.php



And anyway you need to install php unit > 3.5.

Thanks to both of you for answer me.

Right now i’m trying to install PHPUnit 3.5 by using pear but i’m giving this error message




Warning: require_once(Structures/Graph.php): failed to open stream: No such file or directory in PEAR\Downloader.php on line 1217


Warning: require_once(Structures/Graph.php): failed to open stream: No such file or directory in C:\ApacheServer\PHP5V\PEAR\PEAR\Downloader.php on line 1217


Fatal error: require_once(): Failed opening required 'Structures/Graph.php' (include_path='C:\ApacheServer\PHP5V\pear') in C:\ApacheServer\PHP5V\PEAR\PEAR\Downloader.php on line 1217



i look on that file C:\ApacheServer\PHP5V\PEAR\PEAR\Downloader.php, and there is no Strctures/Graph.php, and i belive there is no manual installation for this version. if there is any i can do??

It seems like there is some bug in pear under Windows and you should download Structures_Graph package manually.

See these links: