Fixed: Throw exception if size is not found
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
d371560708
commit
5f1259a462
|
@ -4,6 +4,7 @@ namespace Aweos\Resizer\Classes;
|
|||
|
||||
use Aweos\Resizer\Compressors\CompressorNotFoundException;
|
||||
use Aweos\Resizer\Compressors\Factory as CompressorFactory;
|
||||
use Aweos\Resizer\Exceptions\ResizerException;
|
||||
use Aweos\Resizer\Lib\MediaPath;
|
||||
use Aweos\Resizer\Models\Setting;
|
||||
use Cache;
|
||||
|
@ -32,6 +33,10 @@ class TagGenerator {
|
|||
$size = collect(Setting::get('sizes'))->filter(fn ($size) => $size['name'] === $name)
|
||||
->first();
|
||||
|
||||
if (is_null($size)) {
|
||||
throw new ResizerException("Size with name {$name} not found.");
|
||||
}
|
||||
|
||||
return explode('x', $size['aspect_ratio']);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Aweos\Resizer\Tests;
|
|||
|
||||
use Aweos\Resizer\Classes\CacheManager;
|
||||
use Aweos\Resizer\Classes\TagGenerator;
|
||||
use Aweos\Resizer\Exceptions\ResizerException;
|
||||
use Aweos\Resizer\Lib\MediaPath;
|
||||
use Aweos\Resizer\Models\Setting;
|
||||
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()
|
||||
{
|
||||
Setting::set('folders', ['pages']);
|
||||
|
|
Loading…
Reference in New Issue