Categories
websites

Setting up Yii Testing with XAMPP, PHPUnit and Selenium

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

  1. pear config-set auto_discover 1
  2. pear channel-update pear.php.net
  3. pear upgrade-all
  4. pear channel-discover pear.phpunit.de
  5. pear channel-discover components.ez.no
  6. pear channel-discover pear.symfony-project.com
  7. pear update-channels
  8. pear install -a -f phpunit/PHPUnit
  9. pear install –alldeps pear.phpunit.de/DbUnit
  10. pear install –alldeps pear.phpunit.de/PHPUnit_Story
  11. pear install phpunit/PHPUnit_Selenium

Install and Run Selenium Server

  1. Download Selenium Server (selenium-server-standalone-x.xx.x.jar) from http://seleniumhq.org/download/
  2. Unzip to an easy to find location (I just put it in c:\apps\selenium)
  3. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *