Fixed: Throw exception if size is not found
continuous-integration/drone/push Build is passing Details

This commit is contained in:
philipp lang 2021-12-17 01:44:38 +01:00
parent d371560708
commit 5f1259a462
2 changed files with 18 additions and 0 deletions

View File

@ -4,6 +4,7 @@ namespace Aweos\Resizer\Classes;
use Aweos\Resizer\Compressors\CompressorNotFoundException; use Aweos\Resizer\Compressors\CompressorNotFoundException;
use Aweos\Resizer\Compressors\Factory as CompressorFactory; use Aweos\Resizer\Compressors\Factory as CompressorFactory;
use Aweos\Resizer\Exceptions\ResizerException;
use Aweos\Resizer\Lib\MediaPath; use Aweos\Resizer\Lib\MediaPath;
use Aweos\Resizer\Models\Setting; use Aweos\Resizer\Models\Setting;
use Cache; use Cache;
@ -32,6 +33,10 @@ class TagGenerator {
$size = collect(Setting::get('sizes'))->filter(fn ($size) => $size['name'] === $name) $size = collect(Setting::get('sizes'))->filter(fn ($size) => $size['name'] === $name)
->first(); ->first();
if (is_null($size)) {
throw new ResizerException("Size with name {$name} not found.");
}
return explode('x', $size['aspect_ratio']); return explode('x', $size['aspect_ratio']);
} }

View File

@ -4,6 +4,7 @@ namespace Aweos\Resizer\Tests;
use Aweos\Resizer\Classes\CacheManager; use Aweos\Resizer\Classes\CacheManager;
use Aweos\Resizer\Classes\TagGenerator; use Aweos\Resizer\Classes\TagGenerator;
use Aweos\Resizer\Exceptions\ResizerException;
use Aweos\Resizer\Lib\MediaPath; use Aweos\Resizer\Lib\MediaPath;
use Aweos\Resizer\Models\Setting; use Aweos\Resizer\Models\Setting;
use Aweos\Resizer\Tests\TestCase; use Aweos\Resizer\Tests\TestCase;
@ -38,6 +39,18 @@ class ImageTagTest extends TestCase
); );
} }
public function testItThrowsExceptionWhenSizeNotFound()
{
$this->expectException(ResizerException::class);
Setting::set('folders', ['pages']);
Setting::set('sizes', []);
Setting::set('breakpoints', []);
$this->media->put('/pages/test.jpg', UploadedFile::fake()->image('test.jpg', 500, 500)->get());
UploadedFile::fake()->image('test.jpg', 500, 500)->storeAs('uploads/public/c/pages', 'test-500x500.jpg', 'local');
dd(app(CacheManager::class)->get(new MediaPath('pages/test.jpg'), 'notfound', null));
}
public function testFetchPdfImage() public function testFetchPdfImage()
{ {
Setting::set('folders', ['pages']); Setting::set('folders', ['pages']);