我已经制作了两个Laravel模型,Module
和ModuleDone
。
Module.php :
class Module extends Model
{
protected $fillable = [
'id', 'domain','level', 'description', 'sbu'
];
public function getFullNameAttribute()
{
return $this->domain . $this->level." ".$this->description." (".$this->sbu.")";
}
}
ModuleDone.php :
class ModuleDone extends Model
{
protected $dates = [
'date', 'date_start', 'date_end'
];
protected $fillable = [
'id', 'date','modules_id','result','date_start','date_end'
];
public function Module() {
return $this->belongsTo(Module::class, 'modules_id');
}
public function getDescriptionHeaderAttribute(){
if ($this->result != null) {
return $this->Module->domain.$this->Module->level.' ('. $this->result.')';
} else {
return $this->Module->domain.$this->Module->level.' (S: '.
$this->date_start->format('d-m-Y').')';
}
}
}
这是Module
类的单元测试代码:
public function testGetFullNameAttribute()
{
$module = new Module([
'domain' => 'T',
'level' => '9',
'description' => 'Test',
'sbu' => '10',
]);
$this->assertEquals($module->fullName, 'T9 Test (10)', "FullNameAttribe");
}
我的问题是,getDescriptionHeaderAttribute()
的单元测试在没有将任何内容保存到数据库或没有在数据库中植入任何内容的情况下会是什么样?