包含另一个模型的模型的Laravel单元测试

时间:2018-10-18 09:19:53

标签: laravel unit-testing

我已经制作了两个Laravel模型,ModuleModuleDone

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()的单元测试在没有将任何内容保存到数据库或没有在数据库中植入任何内容的情况下会是什么样?

0 个答案:

没有答案