new ImageOptimizerService( new TemporaryFileFactory(), new NullLogger(), ); it('creates a real temp file for optimized images with the original extension', function () use ($makeService): void { // GIVEN $service = $makeService(); $file = UploadedFile::fake()->image('picture.jpg', 800, 600); // WHEN $optimized = $service->optimize($file, quality: 70); $path = $optimized->getRealPath(); $optimized->rewind(); $content = $optimized->fread(16); // THEN expect($optimized)->toBeInstanceOf(\SplFileObject::class) ->and($path)->not->toBeFalse() ->and(file_exists($path))->toBeTrue() ->and(pathinfo($path, PATHINFO_EXTENSION))->toBe('jpg') ->and($content)->toBeString(); }); it('creates a real temp file for non-image uploads with a readable path', function () use ($makeService): void { // GIVEN $service = $makeService(); $pdf = UploadedFile::fake()->create('document.pdf', 250, 'application/pdf'); // WHEN $result = $service->optimize($pdf); $path = $result->getRealPath(); $result->rewind(); $content = $result->fread(16); // THEN expect($result)->toBeInstanceOf(\SplFileObject::class) ->and($path)->not->toBeFalse() ->and(file_exists($path))->toBeTrue() ->and(pathinfo($path, PATHINFO_EXTENSION))->toBe('pdf') ->and($content)->toBeString(); }); });