File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -306,7 +306,7 @@ private function validateImage()
306306 }
307307
308308 if (! ImageValidator::isValidImage ($ extension , $ mime )) {
309- throw new \ Exception ( "Image [ {$ path }] does not actually appear to be a valid image. " );
309+ throw UnableToReadFile:: fromLocation ( $ path , "Image [ {$ path }] does not actually appear to be a valid image. " );
310310 }
311311 }
312312
Original file line number Diff line number Diff line change 1010use Illuminate \Support \Facades \Event ;
1111use Illuminate \Support \Facades \Storage ;
1212use League \Flysystem \Local \LocalFilesystemAdapter ;
13+ use League \Flysystem \UnableToReadFile ;
1314use League \Glide \Manipulators \Watermark ;
1415use League \Glide \Server ;
1516use PHPUnit \Framework \Attributes \DataProvider ;
@@ -85,6 +86,22 @@ public function it_generates_an_image_by_asset()
8586 Event::assertDispatchedTimes (GlideImageGenerated::class, 1 );
8687 }
8788
89+ #[Test]
90+ public function it_throws_unable_to_read_file_when_asset_is_not_a_valid_image ()
91+ {
92+ Storage::fake ('test ' );
93+ $ file = UploadedFile::fake ()->create ('foo/hoff.jpg ' , 100 );
94+ Storage::disk ('test ' )->putFileAs ('foo ' , $ file , 'hoff.jpg ' );
95+ $ container = tap (AssetContainer::make ('test_container ' )->disk ('test ' ))->save ();
96+ $ asset = tap ($ container ->makeAsset ('foo/hoff.jpg ' ))->save ();
97+
98+ ImageValidator::shouldReceive ('isValidImage ' )->andReturnFalse ();
99+
100+ $ this ->expectException (UnableToReadFile::class);
101+
102+ $ this ->makeGenerator ()->generateByAsset ($ asset , ['w ' => 100 ]);
103+ }
104+
88105 #[Test]
89106 public function it_generates_cache_manifest_for_multiple_asset_manipulations ()
90107 {
You can’t perform that action at this time.
0 commit comments