Product Version: NetBeans IDE Dev (Build 200909221401)
Java: 1.6.0_10; Java HotSpot™ Client VM 11.0-b15
System: Windows XP version 5.1 running on x86; Cp1252; es_ES (nb)
Apache/2.2.6 (Win32) PHP/5.2.9-2
Yii framework 1.0.9
PHPUnit 3.3.15
Create a web application project with yiic tools (e.g. yiic webapp testdrive).
Create a netbeans php project from the source code obtained (File>New Project>Categories:PHP>Projects: PHP Application with Existing Sources).
Make sure that your Yii framework is added to your PHP Include Path
Create a directory for your tests under testdrive folder. You may want to use the Files tab.
Create a file in the tests folder. Name it bootstrap.php. Add the following code and save.
<?php
require_once dirname(__FILE__).'/../../yii/1.0.9/framework/yii.php'; // make sure your path to yii.php is correct
?>
Right click testdrive project. Select Properties. Project Properties pops up. select PHPUnit then in the PHPUnit configuration activate Use Bootstrap and browse to your bootstrap.php file.
Right click Source Files under testdrive folder in the Projects tab and select Tools > create PHPUnits tests.
You may see some folders created for you contaning unit test skeleton. You may want tweak them to fit your needs.
You may want to do some changes. One solution may be as follow:
Create a TestApplication class in the same folder as bootstrap.php
class TestApplication extends CWebApplication
{
public function __construct($config=null)
{
Yii::setApplication(null);
parent::__construct($config);
}
}
Unfortunately I didnt manage to run PhpUnit with Yii… there’s one thing that cant get off my mind - how do you able to write/run model tests without creating Yii application with db config?
protected function setUp() {
$this->db = new CDbConnection('mysql:host=localhost;port=3306;dbname=db_name','user','password');
$this->db->active=true;
CActiveRecord::$db=$this->db;
$this->object = new Country;
}