We don’t need the complexity of S3. Sepcifically the complexity of managing my own AWS account, flysystem made the Laravel side easy. A command is added to copy the the S3 files over to local storage.
61 lines
2.2 KiB
PHP
61 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Jobs;
|
|
|
|
use App\Jobs\ProcessMedia;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Intervention\Image\ImageManager;
|
|
use Tests\TestCase;
|
|
|
|
class ProcessMediaJobTest extends TestCase
|
|
{
|
|
/** @test */
|
|
public function nonMediaFilesAreNotSaved(): void
|
|
{
|
|
$manager = app()->make(ImageManager::class);
|
|
Storage::disk('local')->put('media/file.txt', 'This is not an image');
|
|
$job = new ProcessMedia('file.txt');
|
|
$job->handle($manager);
|
|
|
|
$this->assertFileDoesNotExist(storage_path('app/media/') . 'file.txt');
|
|
}
|
|
|
|
/** @test */
|
|
public function smallImagesAreNotResized(): void
|
|
{
|
|
$manager = app()->make(ImageManager::class);
|
|
Storage::disk('local')->put('media/aaron.png', file_get_contents(__DIR__ . '/../../aaron.png'));
|
|
$job = new ProcessMedia('aaron.png');
|
|
$job->handle($manager);
|
|
|
|
$this->assertFileDoesNotExist(storage_path('app/media/') . 'aaron.png');
|
|
|
|
// Tidy up files created by the job
|
|
Storage::disk('local')->delete('public/media/aaron.png');
|
|
Storage::disk('local')->delete('public/media');
|
|
}
|
|
|
|
/** @test */
|
|
public function largeImagesHaveSmallerImagesCreated(): void
|
|
{
|
|
$manager = app()->make(ImageManager::class);
|
|
Storage::disk('local')->put('media/test-image.jpg', file_get_contents(__DIR__.'/../../test-image.jpg'));
|
|
$job = new ProcessMedia('test-image.jpg');
|
|
$job->handle($manager);
|
|
|
|
Storage::disk('local')->assertExists('public/media/test-image.jpg');
|
|
Storage::disk('local')->assertExists('public/media/test-image-small.jpg');
|
|
Storage::disk('local')->assertExists('public/media/test-image-medium.jpg');
|
|
|
|
$this->assertFileDoesNotExist(storage_path('app/media/') . 'test-image.jpg');
|
|
|
|
// Tidy up files created by the job
|
|
Storage::disk('local')->delete('public/media/test-image.jpg');
|
|
Storage::disk('local')->delete('public/media/test-image-small.jpg');
|
|
Storage::disk('local')->delete('public/media/test-image-medium.jpg');
|
|
$this->removeDirIfEmpty(storage_path('app/public/media'));
|
|
$this->removeDirIfEmpty(storage_path('app/media'));
|
|
}
|
|
}
|