From 9e0bacaa455ec6c55546c91045c5bd6da7b407bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Tue, 3 Mar 2026 08:54:09 +0100 Subject: [PATCH] fix: create image dynamically in test to omit image fixture from repo --- tests/Service/Pdf/SanitizerTest.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/Service/Pdf/SanitizerTest.php b/tests/Service/Pdf/SanitizerTest.php index b9b18fb..f51dbab 100644 --- a/tests/Service/Pdf/SanitizerTest.php +++ b/tests/Service/Pdf/SanitizerTest.php @@ -5,22 +5,31 @@ namespace App\Tests\Service\Pdf; use App\Service\Pdf\Sanitizer; use PHPUnit\Framework\TestCase; use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\Process\Process; class SanitizerTest extends TestCase { public function testAcceptsImages(): void { $tempDir = realpath(__DIR__.'/../../../temp'); - $sourceFilepath = realpath(__DIR__.'/../../Resources/upload.jpg'); - $targetFilepath = $tempDir.'/test.pdf'; + $sourceFilepath = $tempDir.'/upload.png'; + $targetFilepath = $tempDir.'/test-image'; $sanitizer = new Sanitizer('/usr/bin/gs', '/usr/bin/convert', $tempDir); - $sanitizer->sanitizeFile($sourceFilepath, $targetFilepath); + $process = new Process(['/usr/bin/convert', '-size', '1x1', 'xc:white', $sourceFilepath]); + $process->run(); - $this->assertFileExists($targetFilepath); + if (false === $process->isSuccessful()) { + $this->markTestSkipped('Unable to create image fixture: '.$process->getErrorOutput()); + } - (new Filesystem())->remove($targetFilepath); + $sanitizedFilepath = $sanitizer->sanitizeFile($sourceFilepath, $targetFilepath, false); + + $this->assertSame($targetFilepath.'.pdf', $sanitizedFilepath); + $this->assertFileExists($sanitizedFilepath); + + (new Filesystem())->remove([$sourceFilepath, $sanitizedFilepath]); } public function testAcceptsPdfs(): void @@ -31,7 +40,7 @@ class SanitizerTest extends TestCase $sanitizer = new Sanitizer('/usr/bin/gs', '/usr/bin/convert', $tempDir); - $sanitizer->sanitizeFile($sourceFilepath, $targetFilepath); + $sanitizer->sanitizeFile($sourceFilepath, $targetFilepath, false); $this->assertFileExists($targetFilepath);