image(fake()->word().'.jpg'); $fsFile = $fs->putFile('', $file); $image = Image::factory()->createOne([ Image::ATTRIBUTE_PATH => $fsFile, ]); $action = new OptimizeImageAction($image); $result = $action->handle(); $this->assertTrue($result->getStatus() === ActionStatus::SKIPPED); $this->assertDatabaseCount(Image::class, 1); $this->assertTrue($image->exists()); }); test('converts to avif', function (): void { $fs = Storage::fake(Config::get(ImageConstants::DISKS_QUALIFIED)); $file = File::fake()->image(fake()->word().'.jpg'); $fsFile = $fs->putFile('', $file); $image = Image::factory()->createOne([ Image::ATTRIBUTE_PATH => $fsFile, ]); $action = new OptimizeImageAction($image, 'avif'); $result = $action->handle(); $this->assertTrue(Str::endsWith(($image->refresh()->path), '.avif')); $this->assertTrue($result->getStatus() === ActionStatus::PASSED); $this->assertDatabaseCount(Image::class, 1); $this->assertTrue($image->exists()); }); test('downscale', function (): void { $fs = Storage::fake(Config::get(ImageConstants::DISKS_QUALIFIED)); $file = File::fake()->image(fake()->word().'.jpg'); $fsFile = $fs->putFile('', $file); $image = Image::factory()->createOne([ Image::ATTRIBUTE_PATH => $fsFile, ]); $action = new OptimizeImageAction($image, null, fake()->randomDigitNotNull(), fake()->randomDigitNotNull()); $result = $action->handle(); $this->assertTrue($result->getStatus() === ActionStatus::PASSED); $this->assertDatabaseCount(Image::class, 1); $this->assertTrue($image->exists()); });