fix: create image dynamically in test to omit image fixture from repo
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user