Setup Yii Testing
In protected/tests/WebTestCase.php, change TEST_BASE_URL to your project
define('TEST_BASE_URL','http://127.0.0.1/webapp/');
Check protected/tests/bootstrap.php to make sure it is configured in a reasonable manner. I believe in most cases it will be fine – I am using the yii-environment extension, and needed to copy over my config so it would read from existing config files. Take note of what $config is set to. Default is as follows:
$config=dirname(__FILE__).'/../config/test.php';
In protected/config/test.php (or whatever config file you’ve setup for testing above), make sure CDbFixtureManager component is registered.
'components' => array( 'fixture'=>array( 'class'=>'system.test.CDbFixtureManager', ), ),
In webapp/index-test.php
Should be configured similarly to index.php, with $config pointing to your config from above
$config=dirname(__FILE__).'/protected/config/test.php';
Install PHP Unit
- pear config-set auto_discover 1
- pear channel-update pear.php.net
- pear upgrade-all
- pear channel-discover pear.phpunit.de
- pear channel-discover components.ez.no
- pear channel-discover pear.symfony-project.com
- pear update-channels
- pear install -a -f phpunit/PHPUnit
- pear install –alldeps pear.phpunit.de/DbUnit
- pear install –alldeps pear.phpunit.de/PHPUnit_Story
- pear install phpunit/PHPUnit_Selenium
Install and Run Selenium Server
- Download Selenium Server (selenium-server-standalone-x.xx.x.jar) from http://seleniumhq.org/download/
- Unzip to an easy to find location (I just put it in c:\apps\selenium)
- Switch to the Selenium directory and start Selenium Server
> java -jar selenium-server.jar
Run Tests (test testing?)
The default webapp skeleton has some functional tests already configured (SiteTest.php) – this is a good way to make sure your testing environment has been setup correctly.
Run all functional tests:
> cd c:\apps\xampp\htdocs\webapp\protected\tests > phpunit --verbose functional
You should get a summary on the command line informing you of the results…
Tests: 3, Assertions: 3, Errors: 0.