Hi
I am new to testing so I am not sure what class methods or functions need to have test cases and how to do the test. You can throw me a book about testing but I find it is easy if I take step by step in a practical manner.
here is my sample code
class Project extends \yii\db\ActiveRecord
{
use \common\traits\commonTrait;
const STATUS_ESTIMATED = 1;
const STATUS_AWARDED = 2;
const STATUS_COMPLETED = 3;
public function __toString() {
return $this->name;
}
/*
* Return String - Project Location
*/
public function getLocation() {
$loc = array( (string) $this->city, (string) $this->state, (string) $this->country);
return implode(', ',array_filter($loc));
}
/**
* @return \yii\db\ActiveQuery
*/
public function getCountry()
{
return $this->hasOne(Country::className(), ['id' => 'country_id']);
}
public function getClientPOs()
{
return $this->hasMany(ClientPo::className(), ['project_id' => 'id']);
}
/* Get Client POs in Text */
public function getClientPOsText($glue = ', ')
{
$text = '';
$clientPOs = $this->clientPOs;
if (empty($clientPOs)) return $text;
foreach($clientPOs as $clientPO) {
$text[] = $clientPO->name;
}
return implode($glue , $text);
}
// $startDate, $endDate is YYYY-MM-DD format
public function calculateActualQuantity($costCodeId = null, $startDate = null, $endDate = null)
{
$query = ClaimEntry::find()
->joinWith('claim', TRUE, 'INNER JOIN')
->joinWith('claimingRule', TRUE, 'INNER JOIN');
$query->andFilterWhere([
'claim.project_id' => $this->id,
'claim.cost_code_id' => $costCodeId]);
$query->andFilterWhere([
'between', 'claim.date', $startDate, $endDate
]);
return $query->sum('[[claim_amount]] * [[percent]]/100');
}
}
Do I need to test and how do I test them ?
-
__toString() ?
-
getCountry() ?
-
getClientPOs() ?
-
getClientPOsText() ?
-
calculateActualQuantity() ?