phpunit unit/IssueTest.php problem

Hello Yii,

I am working in my localhost environment:

LAMPP

PHP version 5.3.8

PHPmyadmin (MySQL) version 5.0.8

My webroot directory is:

/opt/lampp/htdocs/

And my base directory for the trackstar site is:

/opt/lampp/htdocs/yii/trackstar/

I run "phpunit unit/IssueTest.php" and i got error message. it says:

There was 1 error:

  1. IssueTest::testGetStatusText

CException: Property "Issue.statusOptions" is not defined.

/opt/lampp/htdocs/yii/framework/base/CComponent.php:131

/opt/lampp/htdocs/yii/framework/db/ar/CActiveRecord.php:129

/opt/lampp/htdocs/yii/trackstar/protected/models/Issue.php:171

/opt/lampp/htdocs/yii/trackstar/protected/tests/unit/IssueTest.php:11

FAILURES!

Tests: 4, Assertions: 11, Errors: 1.

IssueTest.php:

public function testGetStatusText()

{

$this->assertTrue(‘Started’ == $this->issues(‘issueBug’)->getStatusText());

}

public function testGetTypeText()

{

$this->assertTrue(‘Bug’ == $this->issues(‘issueBug’)->getTypeText());

}

Issue.php:

/**

  • @return string the status text display for the current issue

*/

public function getStatusText()

{

$statusOptions=$this->statusOptions;

return isset($statusOptions[$this->status_id]) ? $statusOptions[$this->status_id] : "unknown status ({$this->status_id})" ;

}

Does anyone have any ideas or suggestions and how to solve the problem?

Thanks

Best Wishes,

Adnan

Your code seems to be ok, can you post the entire Issue.php, IssueTest.php and tbl_issue.php?

Issue.php:




<?php

 

//class Issue extends CActiveRecord

class Issue extends TrackStarActiveRecord

{

   const TYPE_BUG=0;

   const TYPE_FEATURE=1;

   const TYPE_TASK=2;

   

   const STATUS_NOT_YET_STARTED=0;

   const STATUS_STARTED=1;

   const STATUS_FINISHED=2;

	/**

	 * Returns the static model of the specified AR class.

	 * @return Issue the static model class

	 */

	public static function model($className=__CLASS__)

	{

		return parent::model($className);

	}


	/**

	 * @return string the associated database table name

	 */

	public function tableName()

	{

		return 'tbl_issue';

	}


	/**

	 * @return array validation rules for model attributes.

	 */

	public function rules()

	{

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			array('name', 'required'),

			array('project_id, type_id, status_id, owner_id, requester_id, create_user_id, update_user_id', 'numerical', 'integerOnly'=>true),

			array('name', 'length', 'max'=>256),

			array('description', 'length', 'max'=>2000),

			array('create_time, update_time', 'safe'),

			// The following rule is used by search().

			// Please remove those attributes that should not be searched.

			array('id, name, description, project_id, type_id, status_id, owner_id, requester_id, create_time, create_user_id, update_time, update_user_id', 'safe', 'on'=>'search'),

		);

	}


	/**

	 * @return array relational rules.

	 */

	public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

			'requester' => array(self::BELONGS_TO, 'User', 'requester_id'),

			'owner' => array(self::BELONGS_TO, 'User', 'owner_id'),

			'project' => array(self::BELONGS_TO, 'Project', 'project_id'),

		);

	}


	/**

	 * @return array customized attribute labels (name=>label)

	 */

	public function attributeLabels()

	{

		return array(

			'id' => 'ID',

			'name' => 'Name',

			'description' => 'Description',

			'project_id' => 'Project',

			'type_id' => 'Type',

			'status_id' => 'Status',

			'owner_id' => 'Owner',

			'requester_id' => 'Requester',

			'create_time' => 'Create Time',

			'create_user_id' => 'Create User',

			'update_time' => 'Update Time',

			'update_user_id' => 'Update User',

		);

	}


	/**

	 * Retrieves a list of models based on the current search/filter conditions.

	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.

	 */

	public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;


		$criteria->compare('id',$this->id);

		$criteria->compare('name',$this->name,true);

		$criteria->compare('description',$this->description,true);

		$criteria->compare('project_id',$this->project_id);

		$criteria->compare('type_id',$this->type_id);

		$criteria->compare('status_id',$this->status_id);

		$criteria->compare('owner_id',$this->owner_id);

		$criteria->compare('requester_id',$this->requester_id);

		$criteria->compare('create_time',$this->create_time,true);

		$criteria->compare('create_user_id',$this->create_user_id);

		$criteria->compare('update_time',$this->update_time,true);

		$criteria->compare('update_user_id',$this->update_user_id);

		

		//chapter#6

		$criteria->condition='project_id=:projectID';

		$criteria->params=array(':projectID'=>$this->project_id);




		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

		));

	}

	

	/**

* @return array issue type names indexed by type IDs

*/

//Chapter#6


public function getTypeOptions()

{

return array(

self::TYPE_BUG=>'Bug',

self::TYPE_FEATURE=>'Feature',

self::TYPE_TASK=>'Task',

);


}


public function getTypeOptions1 () 

{

return array(	self::STATUS_NOT_YET_STARTED=>'Not Yet Started',

self::STATUS_STARTED=>'Started',

self::STATUS_FINISHED=>'Finished',

);

}


/**

* @return string the status text display for the current issue

*/

public function getStatusText()

{

$statusOptions=$this->statusOptions;

return isset($statusOptions[$this->status_id]) ? $statusOptions[$this->status_id] : "unknown status ({$this->status_id})" ;


}




/**

* @return string the type text display for the current issue

*/

public function getTypeText()

{

$typeOptions=$this->typeOptions;

return isset($typeOptions[$this->type_id]) ? $typeOptions[$this->type_id] : "unknown type ({$this->type_id})";

}




}



IssueTest.php:


<?php

class IssueTest extends CDbTestCase

{

    public $fixtures=array(

    'projects'=>'Project',

    'issues'=>'Issue',

);


public function testGetStatusText()

{

$this->assertTrue('Started' == $this->issues('issueBug')->getStatusText());

}


public function testGetTypeText()

{

$this->assertTrue('Bug' == $this->issues('issueBug')->getTypeText());

}




public function testGetTypes()

{

$options = Issue::model()->typeOptions;

$this->assertTrue(is_array($options));

$this->assertTrue(3 == count($options));

$this->assertTrue(in_array('Bug', $options));

$this->assertTrue(in_array('Feature', $options));

$this->assertTrue(in_array('Task', $options));

}

}



tbl_issue.php:




<?php

   return array(

	'issueBug'=>array(

	'name' => 'Test Bug 1',

	'description' => 'This is test bug for project 1',

	'project_id' => 1,

	'type_id' => 0,

	'status_id' => 1,

	'owner_id' => 1,

	'requester_id' => 2,

	'create_time' => '',

	'create_user_id' => '',

	'update_time' => '',

	'update_user_id' => '',

),


	'issueFeature'=>array(

	'name' => 'Test Bug 2',

	'description' => 'This is test bug for project 2',

	'project_id' => 2,

	'type_id' => 1,

	'status_id' => 0,

	'owner_id' => 2,

	'requester_id' => 1,

	'create_time' => '',

	'create_user_id' => '',

	'update_time' => '',

	'update_user_id' => '',

),

);




public function getTypeOptions1 () 

{

return array(   self::STATUS_NOT_YET_STARTED=>'Not Yet Started',

self::STATUS_STARTED=>'Started',

self::STATUS_FINISHED=>'Finished',

);

}

should be


public function getStatusOptions () 

{

return array(   self::STATUS_NOT_YET_STARTED=>'Not Yet Started',

self::STATUS_STARTED=>'Started',

self::STATUS_FINISHED=>'Finished',

);

}

Really Worked!!!

Thank you so much for your help.

Best Wishes,

Adnan