【发布时间】:2020-09-11 08:41:28
【问题描述】:
我目前正在编写一个测试来测试模型方法。
我的模型Store有这个方法:
public function hourTemplate() {
return $this->belongsTo(HourTemplate::class);
}
我在 setUp 方法中也对这段代码进行了测试:
public function setUp() : void
{
parent::setUp();
$this->storeMock = Mockery::mock(StoreModel::class)->makePartial();
app()->instance(StoreModel::class, $this->storeMock);
}
而测试方法是这样的:
public function test_getStoreHoursArray_when_hour_isNull() {
$this->storeMock->shouldReceive('hourTemplate')->andReturn(new HourTemplate());
dump((new StoreModel())->hourTemplate);
}
但是返回值为null。
【问题讨论】:
标签: laravel testing phpunit mockery