From 27d4fc009a015a786211d3493e49a90e3231e7aa Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Fri, 15 Mar 2019 22:50:42 +0800 Subject: [PATCH] Update user photo upload filesystem Add FILESYSTEM_DRIVER env on phpunit.xml --- app/Http/Controllers/UsersController.php | 8 +++----- phpunit.xml | 1 + tests/Feature/UsersProfileTest.php | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/UsersController.php b/app/Http/Controllers/UsersController.php index 276b3a0..5619a86 100644 --- a/app/Http/Controllers/UsersController.php +++ b/app/Http/Controllers/UsersController.php @@ -179,13 +179,11 @@ class UsersController extends Controller 'photo' => 'required|image|max:200', ]); - $storage = env('APP_ENV') == 'testing' ? 'avatars' : 'public'; - - if (Storage::disk($storage)->exists($user->photo_path)) { - Storage::disk($storage)->delete($user->photo_path); + if (Storage::exists($user->photo_path)) { + Storage::delete($user->photo_path); } - $user->photo_path = $request->photo->store('images', $storage); + $user->photo_path = $request->photo->store('images'); $user->save(); return back(); diff --git a/phpunit.xml b/phpunit.xml index f5f6354..bec66c3 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -29,5 +29,6 @@ + diff --git a/tests/Feature/UsersProfileTest.php b/tests/Feature/UsersProfileTest.php index d92cdb9..2bdbf9b 100644 --- a/tests/Feature/UsersProfileTest.php +++ b/tests/Feature/UsersProfileTest.php @@ -96,7 +96,7 @@ class UsersProfileTest extends TestCase /** @test */ public function user_can_upload_their_own_photo() { - Storage::fake('avatars'); + Storage::fake(config('filesystems.default')); $user = $this->loginAsUser(); $this->visit(route('users.edit', $user->id)); @@ -110,7 +110,7 @@ class UsersProfileTest extends TestCase $user = $user->fresh(); $this->assertNotNull($user->photo_path); - Storage::disk('avatars')->assertExists($user->photo_path); + Storage::assertExists($user->photo_path); } /** @test */