假设我有两个模型,Eloquent
它们相互关联。我可以嘲笑这种关系吗?
IE:
class Track extends Eloquent {
public function courses()
{
return $this->hasMany('Course');
}
}
class Course extends Eloquent {
public function track()
{
return $this->belongsTo('Track');
}
}
在 MyTest 中,我当然想创建一个模拟,并通过调用 track 属性而不是 track 实例返回一个 track 实例(我不想要查询生成器)
use \Mockery as m;
class MyTest extends TestCase {
public function setUp()
{
$track = new Track(array('title' => 'foo'));
$course = m::mock('Course[track]', array('track' => $track));
$track = $course->track // <-- This should return my track object
}
}