laravel-testing

how to inject a file into http request

血红的双手。 提交于 2020-01-03 04:54:08
问题 i have a test case: $response = $this->postJson('api/unit/'.$unit->id.'/import',['file' =>Storage::get('file/file.xlsx')]); $response->assertJsonFragment(['a'=>'b']); my controller: public function import(Request $request, Unit $unit) { $this->validate($request, [ 'file' => 'file|required_without:rows', 'rows' => 'array|required_without:file', 'dry_run' => 'boolean', ]); if ($request->has('rows')) { // } else { $results = $request->file('file'); } return "ok"; } but i think my test case is