-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
86 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Models\User; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
use Illuminate\Support\Facades\Storage; | ||
use Intervention\Image\ImageManager; | ||
|
||
class MinifyProfilePhoto implements ShouldQueue | ||
{ | ||
use Dispatchable; | ||
use InteractsWithQueue; | ||
use Queueable; | ||
use SerializesModels; | ||
|
||
public function __construct(public readonly User $user) | ||
{ | ||
} | ||
|
||
public function handle(): void | ||
{ | ||
if ($this->user->profile_photo_path === null) { | ||
return; | ||
} | ||
|
||
$photo = Storage::disk('public')->path($this->user->profile_photo_path); | ||
|
||
$image = ImageManager::gd()->read($photo); | ||
$image->scaleDown(height: 500); | ||
$image->save(quality: 50); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,28 @@ | ||
<?php | ||
|
||
use App\Jobs\MinifyProfilePhoto; | ||
use App\Models\User; | ||
use Illuminate\Http\UploadedFile; | ||
use Illuminate\Support\Facades\Queue; | ||
use Illuminate\Support\Facades\Storage; | ||
|
||
test('profile information can be updated', function () { | ||
Queue::fake(); | ||
Storage::fake('public'); | ||
$this->actingAs($user = User::factory()->create()); | ||
|
||
$response = $this->put('/user/profile-information', [ | ||
'name' => 'Test Name', | ||
'email' => '[email protected]', | ||
'photo' => UploadedFile::fake()->image('photo.png'), | ||
]); | ||
|
||
$response->assertRedirect(); | ||
expect($user->fresh()) | ||
->name->toEqual('Test Name') | ||
->email->toEqual('[email protected]'); | ||
->email->toEqual('[email protected]') | ||
->profile_photo_path->not()->toBeNull(); | ||
|
||
Storage::disk('public')->assertExists($user->fresh()->profile_photo_path); | ||
Queue::assertPushed(MinifyProfilePhoto::class); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
use App\Jobs\MinifyProfilePhoto; | ||
use App\Models\User; | ||
use Illuminate\Support\Facades\Storage; | ||
use Intervention\Image\Drivers\Gd\Driver; | ||
|
||
test('it minifies the profile photo', function () { | ||
Storage::fake('public'); | ||
Storage::disk('public')->put( | ||
'profile-photos/default.jpg', | ||
Storage::disk('local')->get('default.jpg') | ||
); | ||
$user = User::factory()->create([ | ||
'profile_photo_path' => 'profile-photos/default.jpg', | ||
]); | ||
$previousSize = Storage::disk('public')->size($user->profile_photo_path); | ||
|
||
$action = new MinifyProfilePhoto($user); | ||
$action->handle(new Driver()); | ||
|
||
$this->assertFileExists( | ||
Storage::disk('public')->path($user->profile_photo_path) | ||
); | ||
$this->assertLessThan( | ||
$previousSize, | ||
Storage::disk('public')->size($user->profile_photo_path) | ||
); | ||
})->group('slow'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters