Skip to content

Commit

Permalink
Prevent regenerating asset meta file for non-images (#3609)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga authored Apr 28, 2021
1 parent e8d1696 commit 14cc1fa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Assets/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,10 @@ public function move($folder, $filename = null)
*/
public function dimensions()
{
if (! $this->isImage()) {
return [null, null];
}

return [$this->meta('width'), $this->meta('height')];
}

Expand Down
22 changes: 22 additions & 0 deletions tests/Assets/AssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,28 @@ public function it_gets_dimensions()
$this->assertEquals(60, $asset->height());
}

/** @test */
public function it_gets_no_dimensions_for_non_images()
{
$file = UploadedFile::fake()->create('file.txt');
Storage::fake('test')->putFileAs('foo', $file, 'file.txt');
$asset = (new Asset)->path('foo/file.txt')->container($this->container);

$this->assertEquals([null, null], $asset->dimensions());
$this->assertEquals(null, $asset->width());
$this->assertEquals(null, $asset->height());
}

/** @test */
public function it_doesnt_regenerate_the_meta_file_when_getting_non_image_dimensions()
{
$asset = $this->partialMock(Asset::class);

$asset->shouldReceive('meta')->times(0);

$this->assertEquals([null, null], $asset->dimensions());
}

/** @test */
public function it_gets_file_size_in_bytes()
{
Expand Down

0 comments on commit 14cc1fa

Please sign in to comment.