I am new to laravel, I can run successfully my file uploader, it uploads successfully my file, but the unit test fails, here is my code:
UploadTest.php
public function testUploadFile()
{
$fileSize = 1024; // 1mb
$fileName = 'file.txt';
Storage::fake('files');
$response = $this->json('POST', '/webservice/upload', [
'file' => UploadedFile::fake()->create($fileName, $fileSize)
]);
Storage::disk('files')->assertExists($fileName);
Storage::disk('files')->assertMissing($fileName);
}
FileUploadController
public function upload(Request $request)
{
$file = $request->file('file');
if ($file == null) {
return view('fileupload',
['submitClickedMsg' => "Please select a file to upload."]);
}
$path = $file->storeAs('files', $file->getClientOriginalName(), 'local');
return response()->json([
'path' => $path
]);
}
filesystem.php
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
],
],
Help is greatly appreciated, thanks.