運行我的單元測試時出現以下錯誤。似乎它不喜歡將Input :: get傳遞給構造函數,但是當在瀏覽器中運行腳本時,該操作正常工作,所以我知道它不是控制器代碼。如果我取出任何'task_update'代碼,測試只是通過輸入發現 - 因此不確定爲什麼它接受一種方法的輸入。Laravel - 輸入不通過單元測試
ErrorException: Argument 1 passed to Illuminate\Database\Eloquent\Model::__construct() must be of the type array, null given, called
我的控制器是:
public function store()
{
$task_update = new TaskUpdate(Input::get('tasks_updates'));
$task = $this->task->find(Input::get('tasks_updates')['task_id']);
$output = $task->taskUpdate()->save($task_update);
if (!!$output->id) {
return Redirect::route('tasks.show', $output->task_id)
->with('flash_task_update', 'Task has been updated');
}
}
並且測試 - 我設置task_updates陣列的輸入,但只是沒有被拾起:
Input::replace(['tasks_updates' => array('description' => 'Hello')]);
$mockClass = $this->mock;
$mockClass->task_id = 1;
$this->mock->shouldReceive('save')
->once()
->andReturn($mockClass);
$response = $this->call('POST', 'tasksUpdates');
$this->assertRedirectedToRoute('tasks.show', 1);
$this->assertSessionHas('flash_task_update');