Host images locally
Some checks failed
PHP Unit / PHPUnit test suite (pull_request) Has been cancelled
Laravel Pint / Laravel Pint (pull_request) Has been cancelled

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.
This commit is contained in:
Jonny Barnes 2024-10-25 20:40:52 +01:00
parent d80e8164c8
commit d7da42b626
Signed by: jonny
SSH key fingerprint: SHA256:CTuSlns5U7qlD9jqHvtnVmfYV3Zwl2Z7WnJ4/dqOaL8
47 changed files with 295 additions and 214 deletions

View file

@ -14,38 +14,48 @@ class ProcessMediaJobTest extends TestCase
/** @test */
public function nonMediaFilesAreNotSaved(): void
{
Storage::fake('s3');
$manager = app()->make(ImageManager::class);
Storage::disk('local')->put('file.txt', 'This is not an image');
Storage::disk('local')->put('media/file.txt', 'This is not an image');
$job = new ProcessMedia('file.txt');
$job->handle($manager);
$this->assertFalse(file_exists(storage_path('app') . '/file.txt'));
$this->assertFileDoesNotExist(storage_path('app/media/') . 'file.txt');
}
/** @test */
public function smallImagesAreNotResized(): void
{
Storage::fake('s3');
$manager = app()->make(ImageManager::class);
Storage::disk('local')->put('aaron.png', file_get_contents(__DIR__ . '/../../aaron.png'));
Storage::disk('local')->put('media/aaron.png', file_get_contents(__DIR__ . '/../../aaron.png'));
$job = new ProcessMedia('aaron.png');
$job->handle($manager);
$this->assertFalse(file_exists(storage_path('app') . '/aaron.png'));
$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('test-image.jpg', file_get_contents(__DIR__.'/../../test-image.jpg'));
Storage::fake('s3');
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('s3')->assertExists('media/test-image-small.jpg');
Storage::disk('s3')->assertExists('media/test-image-medium.jpg');
$this->assertFalse(file_exists(storage_path('app') . '/test-image.jpg'));
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'));
}
}