From 41d759428f1f16bc93ca2846e78c17c00c634245 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Thu, 19 Aug 2021 12:54:06 +0100 Subject: [PATCH] [TESTS][DataFixtures] Use Temporary file instead of an ad-hoc solution to copy the upload files --- src/DataFixtures/MediaFixtures.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/DataFixtures/MediaFixtures.php b/src/DataFixtures/MediaFixtures.php index 06b2a4bc74..ac35cc7643 100644 --- a/src/DataFixtures/MediaFixtures.php +++ b/src/DataFixtures/MediaFixtures.php @@ -4,11 +4,11 @@ namespace App\DataFixtures; use App\Core\DB\DB; use App\Core\GSFile; +use App\Util\TemporaryFile; use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Persistence\ObjectManager; use Exception; use Functional as F; -use Symfony\Component\HttpFoundation\File\File; class MediaFixtures extends Fixture { @@ -17,15 +17,15 @@ class MediaFixtures extends Fixture DB::setManager($manager); F\map(glob(INSTALLDIR . '/tests/sample-uploads/*'), function (string $filepath) { - $copy_filepath = str_replace('.', '.copy.', $filepath); - copy($filepath, $copy_filepath); - $file = new File($copy_filepath, checkPath: true); + $file = new TemporaryFile(); + $file->write(file_get_contents($filepath)); try { GSFile::sanitizeAndStoreFileAsAttachment($file); } catch (Exception $e) { - echo "Could not save file {$copy_filepath}, failed with {$e}\n"; + echo "Could not save file {$filepath}, failed with {$e}\n"; + } finally { + unset($file); } - @unlink($copy_filepath); }); $manager->flush(); }