PHPUnit doesn't work on Ubuntu 11.04

Hello Folk

I try to make PHPUnit work on my machine but unfortunately it doesn’t work.

This is my machine info




OS: Ubuntu 11.04

PHP 5.3.5-1ubuntu7.2 with Suhosin-Patch (cli) (built: May  2 2011 23:18:30) 

Zend Engine v2.3.0

Xdebug v2.1.0

PHPUnit 3.5.14

selenium-server-standalone-2.0rc2



I create virtual host name “helloyii.localhost” I can browse demos app (it’s awesome)

Then I create new app by use command




php framework/yiic.php webapp testdrive



I can browse hxxp://helloyii.localhost/testdrive

and it work very well.

Note: I change http to hxxp because forum not allow me post URL in first post

Next step, I modified testdrive/protected/tests/WebTestCase.php to correct the TEST_BASE_URL




define('TEST_BASE_URL','hxxp://helloyii.localhost/testdrive/index-test.php/');



and phpunit.xml look like this




<phpunit bootstrap="bootstrap.php"

		colors="false"

		convertErrorsToExceptions="true"

		convertNoticesToExceptions="true"

		convertWarningsToExceptions="true"

		stopOnFailure="false">


	<selenium>

		<browser name="Firefox" browser="*firefox" />

	</selenium>


</phpunit>



finally I run phpunit and get error message




phpunit SiteTest.php 

PHP Fatal error:  Class 'WebTestCase' not found in /home/myhomefolder/www/helloyii.localhost/public_html/testdrive/protected/tests/functional/SiteTest.php on line 4

Fatal error: Class 'WebTestCase' not found in /home/myhomefolder/www/helloyii.localhost/public_html/testdrive/protected/tests/functional/SiteTest.php on line 4



I google a lot today, try many solution from the website I founded but still not work and I have no idea now.

Do I made mistake somewhere?

Thank you in advance for all opinion.

I create new Ubuntu 10.04 instance and try again, I got same problem.

Can any one share your environment such as OS, PHP version, php.ini ?

thank you.

I think I had the same/similar problem a few days ago and found for me the following solution:

My system:




Ubuntu 10.10 2.6.35-28

PHP 5.3.3-1ubuntu9.5 with Suhosin-Patch (cli) (built: May  3 2011 00:49:55) 

Copyright © 1997-2009 The PHP Group

Zend Engine v2.3.0, Copyright © 1998-2010 Zend Technologies

with Xdebug v2.1.0, Copyright © 2002-2010, by Derick Rethans

with Suhosin v0.9.31, Copyright © 2007-2010, by SektionEins GmbH

selenium-server-standalone-2.0rc2



You have to install the Selenium phpunit extension with an extra pear command cause it doesn’t come

with the default pear installation => Installing PHPUnit

Try




sudo pear install phpunit/PHPUnit_Selenium



I’m not sure if you have the same issue like me but maybe it helps someone else.

Resources:

stackoverflow - Getting PHPUnit Working

pear.phpunit.de

Thank you so much kokomo.

Do you add some value to PHP include_path?

PHPUnit is work for me now but not work when I run the YII test (run test by follow the tutorial)

btw, I test on Windows 7 I got same error message




PHP Fatal error:  Class 'WebTestCase' not found



No, my include_path is still




.:/usr/share/php:/usr/share/pear



which is the default I my opinion. PHPUnit and other php extensions installed via pear are located at /usr/share/php in my case.

I thinking about PHP configuration is mistake somewhere because the error message talk about PHP Fatal error, PHP should found file and auto load WebTestCase.php but it’s not.

Can any one help me to test my code?

This is my code.




https://github.com/amaudy/learn-yii



thank you.

These are a few things I needed to do to get this to work that were not obvious/documented

add these to the environment path (Windows - these are my paths yours will differ)


W:\xampp\htdocs\yii\1.1.8\framework;W:\xampp\php\PEAR\PHPUnit2

download PHPUnit_Selenium from http://pear.phpunit.de/ extract it and put it under PEAR/PHPUnit/Extensions

Check these files are pointing to the right place


protected/tests/bootstrap

/index.php

/index-test.php

Need to start the server first


java -jar selenium-server.jar

Run functional Tests from tests folder wont work unless command prompt started in /protected/tests


phpunit functional/SiteTest.php

add


sleep(5);

before failed asserts