Laravel Version: 5.5
PHP Version: 7.1
Database Driver: mysql
Im currently having a problem with unit testing, basically the problem is in the move() function inside my controller, when that function is running the program say the file is being used my another program. and throw this exception
Could not move the file "C:\Users\JUAN ANTONIO\AppData\Local\Temp\phpED45.tmp" to "uploads/partners\15517582682740.jpg" (rename(C:\Users\JUAN ANTONIO\AppData\Local\Temp\phpED45.tmp,uploads/partners\15517582682740.jpg): The process cannot access the file because it is being used by another process. (code: 32))"
here are the snippet of my code:
PartnerTest.php->testStorePartner()
/** @test */
public function testStorePartner(){
Storage::fake('local');
//1. Create Data
$data = [
'name' => 'test',
'file' => UploadedFile::fake()->image('avatar.jpg')
];
//2. Store Data
$response = $this->actingAs($this->user)->json('POST', route('PartnersStore'), $data);
//3. Data Stored In Database
$this->assertDatabaseHas('partners', ['name' => 'test',]);
//4. Test response status 302 -> redirect
$response->assertStatus(302);
}
PartnerController->store(Request $request)
public function store(Request $request)
{
$this->validate($request, [
'file' => 'mimes:png,jpeg,jpg,gif|max:3000'
]);
// Start of Upload Files
$formFileName = "file";
$fileName = "";
if ($request->$formFileName != "") {
$fileName = time() . rand(1111,
9999) . '.' . $request->file($formFileName)->getClientOriginalExtension();
$path = $this->getUploadPath();
$request->file($formFileName)->move($path, $fileName);
}
// End of Upload Files
$Partner = new Partner;
$Partner->name = $request->name;
$Partner->file = $fileName;
$Partner->status = 1;
$Partner->created_by = Auth::user()->id;
$Partner->save();
return redirect('/admin/partners')->with('doneMessage', trans('backLang.addDone'));
}
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_KEY'),
'secret' => env('AWS_SECRET'),
'region' => env('AWS_REGION'),
'bucket' => env('AWS_BUCKET'),
],
],