2
我正在使用Lumen 5.5,並且我編寫了簡單的應用程序來上傳文件。流明測試文件上傳5.5
我寫了這樣的測試(以下this教程)
<?php
class UploadImageTest extends TestCase
{
Use DatabaseMigrations;
public function testUploadingImageSuccessfully()
{
$this->json('POST', '/images', [
'image' => UploadedFile::fake()->image('image.jpg')
])->assertResponseOk()
}
}
問題是,在我的控制器,$request->file('image')
返回null。
<?php
use Illuminate\Http\Request;
class UploadController extends Controller
{
public function upload(Request $request)
{
if ($request->file('image')) { // always return null
return "File is uploaded!";
}
return "File is not uploaded!";
}
}
我檢查了其他問題(如this one),並沒有運氣試圖給出的解決方案!