Browse Source

various fixes

Olivier Massot 3 years ago
parent
commit
7d068515b9

+ 2 - 1
src/ApiResources/Export/ExportRequest.php

@@ -7,6 +7,7 @@ use ApiPlatform\Core\Annotation\ApiProperty;
 use ApiPlatform\Core\Annotation\ApiResource;
 use App\Entity\Access\Access;
 use Symfony\Component\Validator\Constraints as Assert;
+use App\Enum\Export\ExportFormatEnum;
 
 /**
  * Demande d'export d'un fichier
@@ -27,7 +28,7 @@ abstract class ExportRequest
      * Format de sortie attendu (pdf, txt...)
      * @var string
      */
-    #[Assert\Choice(callback: ['\App\Enum\Export\ExportFormatEnum', 'toArray'], message: 'invalid-output-format')]
+    #[Assert\Choice(callback: [ExportFormatEnum::class, 'toArray'], message: 'invalid-output-format')]
     protected string $format;
 
     /**

+ 8 - 24
src/DataPersister/Export/LicenceCmf/ExportRequestDataPersister.php

@@ -7,19 +7,15 @@ use ApiPlatform\Core\DataPersister\ContextAwareDataPersisterInterface;
 use App\ApiResources\Export\ExportRequest;
 use App\Entity\Access\Access;
 use App\Entity\Core\File;
-use App\Enum\Core\FileStatusEnum;
 use App\Message\Command\Export;
 use App\Service\ServiceIterator\ExporterIterator;
-use Doctrine\ORM\EntityManagerInterface;
 use Exception;
-use Symfony\Component\HttpFoundation\JsonResponse;
 use Symfony\Component\Messenger\MessageBusInterface;
 use Symfony\Component\Security\Core\Security;
 
 class ExportRequestDataPersister implements ContextAwareDataPersisterInterface
 {
     public function __construct(
-        private EntityManagerInterface $em,
         private Security               $security,
         private MessageBusInterface    $messageBus,
         private ExporterIterator       $handler
@@ -33,8 +29,9 @@ class ExportRequestDataPersister implements ContextAwareDataPersisterInterface
     /**
      * @param $exportRequest ExportRequest Une requête d'export
      * @param array $context
-     * @return JsonResponse
+     * @return File
      * @throws Exception
+     * @noinspection PhpParameterNameChangedDuringInheritanceInspection
      */
     public function persist($exportRequest, array $context = []): File
     {
@@ -42,24 +39,14 @@ class ExportRequestDataPersister implements ContextAwareDataPersisterInterface
         $access = $this->security->getUser();
         $exportRequest->setRequesterId($access->getId());
 
-        $file = new File();
-        $file->setOrganization($access->getOrganization());
-        $file->setVisibility('NOBODY');
-        $file->setFolder('DOCUMENTS');
-        $file->setCreateDate(new \DateTime());
-        $file->setCreatedBy($access->getId());
-        $file->setStatus(FileStatusEnum::PENDING()->getValue());
-        $file->setName('');
-        $file->setPath('');
-        $file->setSlug('');
-        $file->setIsTemporaryFile(true);
-        $this->em->persist($file);
-        $this->em->flush();
+        // Prepare the file record and attach its id to the export request
+        $exporter = $this->handler->getExporterFor($exportRequest);
+        $file = $exporter->prepareFile($exportRequest, true);
 
         $exportRequest->setFileId($file->getId());
 
         if (!$exportRequest->isAsync()) {
-            return $this->handler->getExporterFor($exportRequest)->export($exportRequest);
+            return $exporter->export($exportRequest);
         }
 
         // Send the export request to Messenger (@see App\Message\Handler\ExportHandler)
@@ -69,11 +56,8 @@ class ExportRequestDataPersister implements ContextAwareDataPersisterInterface
         return $file;
     }
 
-    /**
-     * @throws Exception
-     */
-    public function remove($data, array $context = [])
+    public function remove($data, array $context = []): void
     {
-        throw new Exception('not supported', 500);
+        throw new \RuntimeException('not supported', 500);
     }
 }

+ 2 - 0
src/Enum/Core/FileTypeEnum.php

@@ -5,11 +5,13 @@ namespace App\Enum\Core;
 use MyCLabs\Enum\Enum;
 
 /**
+ * @method static UNKNOWN()
  * @method static NONE()
  * @method static LICENCE_CMF()
  */
 class FileTypeEnum extends Enum
 {
+    private const UNKNOWN = 'UNKNOWN';
     private const NONE = 'NONE';
     private const LICENCE_CMF ='LICENCE_CMF';
 }

+ 0 - 18
src/Enum/Export/ExportFormatEnum.php

@@ -15,22 +15,4 @@ class ExportFormatEnum extends Enum
     private const TXT = 'txt';
     private const XLSX = 'xlsx';
     private const XML = 'xml';
-
-    /** @var array */
-    protected static array $mimeType = [
-        self::PDF => 'application/pdf',
-        self::CSV => 'text/csv',
-        self::TXT => 'text/plain',
-        self::XLSX => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
-        self::XML => 'application/xml'
-    ];
-
-    /**
-     * @param string $formatShortName
-     * @return string
-     */
-    public static function getMimeType(string $formatShortName): string
-    {
-        return static::$mimeType[$formatShortName] ?? "Unknown format ($formatShortName)";
-    }
 }

+ 48 - 49
src/Service/Export/BaseExporter.php

@@ -5,8 +5,7 @@ namespace App\Service\Export;
 
 use App\ApiResources\Export\ExportRequest;
 use App\Entity\Core\File;
-use App\Enum\Core\FileStatusEnum;
-use App\Enum\Export\ExportFormatEnum;
+use App\Enum\Core\FileTypeEnum;
 use App\Repository\Access\AccessRepository;
 use App\Repository\Core\FileRepository;
 use App\Service\Export\Model\ExportModelInterface;
@@ -14,7 +13,6 @@ use App\Service\ServiceIterator\EncoderIterator;
 use App\Service\Storage\FileStorage;
 use App\Service\Utils\StringsUtils;
 use Doctrine\ORM\EntityManagerInterface;
-use Exception;
 use Psr\Log\LoggerInterface;
 use Symfony\Contracts\Service\Attribute\Required;
 use Twig\Environment;
@@ -66,7 +64,6 @@ abstract class BaseExporter implements ExporterInterface
      *
      * @param ExportRequest $exportRequest
      * @return File
-     * @throws Exception
      */
     public function export(ExportRequest $exportRequest): File
     {
@@ -76,48 +73,64 @@ abstract class BaseExporter implements ExporterInterface
         // Génère le html à partir du template et du service
         $html = $this->render($model);
 
+        $f = fopen("test.html", "w+");
+        fwrite($f, $html);
+        fclose($f);
+
         // Encode le html au format voulu
         $content = $this->encode($html, $exportRequest->getFormat());
 
-        // Créé le fichier dans le storage adapté
-        $filename = $this->getFileBasename($model);
-        if (!preg_match('/^.+\.' . $exportRequest->getFormat() . '$/i', $filename)) {
-            $filename .= '.' . $exportRequest->getFormat();
+        $requesterId = $exportRequest->getRequesterId();
+        $requester = $this->accessRepository->find($requesterId);
+        if ($requester === null) {
+            throw new \RuntimeException('Unable to determine the user; abort.');
         }
 
-        $path = $this->store($filename, $content);
-
         // Met à jour ou créé l'enregistrement du fichier en base
         if ($exportRequest->getFileId() !== null) {
             $file = $this->fileRepository->find($exportRequest->getFileId());
         } else {
             // Todo: voir si ce else est nécessaire une fois tous les exports implémentés
-            $file = new File();
-
-            $requesterId = $exportRequest->getRequesterId();
-            $organization = $this->accessRepository->find($requesterId)?->getOrganization();
+            $organization = $requester->getOrganization();
             if ($organization === null) {
                 throw new \RuntimeException('Unable to determine the organization of the curent user; abort.');
             }
-            $file->setOrganization($organization);
-            $file->setVisibility('NOBODY');
-            $file->setFolder('DOCUMENTS');
-            $file->setCreateDate(new \DateTime());
-            $file->setCreatedBy($requesterId);
+            $file = $this->prepareFile($exportRequest, false);
         }
 
-        $file->setType($this->getFileType());
-        $file->setMimeType(ExportFormatEnum::getMimeType($exportRequest->getFormat()));
-        $file->setName($filename);
-        $file->setPath($path);
-        $file->setSlug($path);
-        $file->setStatus(FileStatusEnum::READY()->getValue());
+        return $this->storage->writeFile($file, $content, $requester);
+    }
+
+    /**
+     * Create a pending file record in the database
+     *
+     * @param ExportRequest $exportRequest
+     * @param bool $flushFile
+     * @return File
+     */
+    public function prepareFile(ExportRequest $exportRequest, bool $flushFile = true): File {
 
-        $this->entityManager->persist($file);
-        $this->entityManager->flush();
+        $requesterId = $exportRequest->getRequesterId();
+        $requester = $this->accessRepository->find($requesterId);
+        if ($requester === null) {
+            throw new \RuntimeException('Unable to determine the current user; abort.');
+        }
 
-        // Retourne l'objet File ainsi créé
-        return $file;
+        $filename = $this->getFileBasename($exportRequest);
+        if (!preg_match('/^.+\.' . $exportRequest->getFormat() . '$/i', $filename)) {
+            $filename .= '.' . $exportRequest->getFormat();
+        }
+
+        return $this->storage->prepareFile(
+            $requester,
+            $filename,
+            $this->getFileType(),
+            $requester,
+            true,
+            'NOBODY',
+            FileStorage::getMimeTypeFromExt($exportRequest->getFormat()),
+            $flushFile
+        );
     }
 
     /**
@@ -125,7 +138,6 @@ abstract class BaseExporter implements ExporterInterface
      *
      * @param ExportRequest $exportRequest
      * @return ExportModelInterface
-     * @throws Exception
      */
     protected function buildModel(ExportRequest $exportRequest): ExportModelInterface
     {
@@ -165,7 +177,6 @@ abstract class BaseExporter implements ExporterInterface
      *
      * @param ExportModelInterface $model
      * @return string Rendu HTML
-     * @throws Exception
      */
     protected function render(ExportModelInterface $model): string
     {
@@ -176,7 +187,7 @@ abstract class BaseExporter implements ExporterInterface
             );
         }
         catch (\Twig\Error\LoaderError | \Twig\Error\RuntimeError | \Twig\Error\SyntaxError $e) {
-            throw new \Exception('error during template rendering : ' . $e);
+            throw new \RuntimeException('error during template rendering : ' . $e);
         }
     }
 
@@ -186,7 +197,6 @@ abstract class BaseExporter implements ExporterInterface
      * @param string $html
      * @param string $format @see ExportFormatEnum
      * @return string
-     * @throws Exception
      */
     protected function encode(string $html, string $format): string
     {
@@ -196,10 +206,10 @@ abstract class BaseExporter implements ExporterInterface
     /**
      * Retourne le nom du fichier exporté
      *
-     * @param ExportModelInterface $model
+     * @param ExportRequest $exportRequest
      * @return string
      */
-    protected function getFileBasename(ExportModelInterface $model): string
+    protected function getFileBasename(ExportRequest $exportRequest): string
     {
         return $this->getBasename();
     }
@@ -207,20 +217,9 @@ abstract class BaseExporter implements ExporterInterface
     /**
      * Retourne le type de fichier tel qu'il apparait au niveau du champ File.type
      *
-     * @return string
+     * @return FileTypeEnum
      */
-    protected function getFileType(): string {
-        return 'UNKNOWN';
-    }
-
-    /**
-     * Créé le fichier
-     *
-     * @return mixed
-     * @throws Exception
-     */
-    protected function store(string $name, string $content): string
-    {
-        return $this->storage->write($name, $content);
+    protected function getFileType(): FileTypeEnum {
+        return FileTypeEnum::UNKNOWN();
     }
 }

+ 9 - 0
src/Service/Export/ExporterInterface.php

@@ -26,4 +26,13 @@ interface ExporterInterface
      * @param ExportRequest $exportRequest
      */
     public function export(ExportRequest $exportRequest): File;
+
+    /**
+     * Create a pending file record in the database
+     *
+     * @param ExportRequest $exportRequest
+     * @param bool $flushFile
+     * @return File
+     */
+    public function prepareFile(ExportRequest $exportRequest, bool $flushFile = true): File;
 }

+ 14 - 16
src/Service/Export/LicenceCmfExporter.php

@@ -5,13 +5,12 @@ namespace App\Service\Export;
 
 use App\ApiResources\Export\ExportRequest;
 use App\ApiResources\Export\LicenceCmf\LicenceCmfOrganizationER;
-use App\Service\Export\Model\ExportModelInterface;
+use App\Enum\Core\FileTypeEnum;
 use App\Service\Export\Model\LicenceCmf;
 use App\Enum\Access\FunctionEnum;
 use App\Repository\Organization\OrganizationRepository;
 use App\Service\Export\Model\LicenceCmfCollection;
 use App\Service\Storage\FileStorage;
-use App\Service\Storage\UploadStorage;
 
 /**
  * Exporte la licence CMF de la structure ou du ou des access, au format demandé
@@ -27,8 +26,7 @@ class LicenceCmfExporter extends BaseExporter
     public const LICENCE_CMF_COLOR = [0 => '931572', 1 => 'C2981A', 2 =>  '003882', 3 =>  '27AAE1', 4 =>  '2BB673'];
 
     public function __construct(
-        private OrganizationRepository $organizationRepository,
-        private FileStorage $fileStorage,
+        private OrganizationRepository $organizationRepository
     )
     {}
 
@@ -60,10 +58,10 @@ class LicenceCmfExporter extends BaseExporter
             $this->getLicenceColor($exportRequest->getYear())
         );
 
-        $logoId = $organization->getLogo()?->getId();
-        if ($logoId) {
+        $logo = $organization->getLogo();
+        if ($logo) {
             $licenceCmf->setLogoUri(
-                $this->fileStorage->getUri($logoId)
+                $this->storage->getUri($logo)
             );
         }
 
@@ -78,10 +76,10 @@ class LicenceCmfExporter extends BaseExporter
 
         $cmf = $this->organizationRepository->find(self::CMF_ID);
         /** @noinspection NullPointerExceptionInspection */
-        $qrCodeId = $cmf->getParameters()?->getQrCode()?->getId();
-        if ($qrCodeId) {
+        $qrCode = $cmf->getParameters()?->getQrCode();
+        if ($qrCode) {
             $licenceCmf->setQrCodeUri(
-                $this->fileStorage->getUri($qrCodeId)
+                $this->storage->getUri($qrCode)
             );
         }
 
@@ -91,21 +89,21 @@ class LicenceCmfExporter extends BaseExporter
     }
 
     /**
-     * @param LicenceCmfCollection $model
+     * @param ExportRequest $exportRequest
      * @return string
      */
-    protected function getFileBasename(ExportModelInterface $model): string
+    protected function getFileBasename(ExportRequest $exportRequest): string
     {
-        return 'licence_cmf_' . $model->getLicences()[0]->getYear() . '.pdf';
+        return 'licence_cmf_' . $exportRequest->getYear() . '.pdf';
     }
 
     /**
      * Retourne le type de fichier tel qu'il apparait au niveau du champ File.type
      *
-     * @return string
+     * @return FileTypeEnum
      */
-    protected function getFileType(): string {
-        return 'LICENCE_CMF';
+    protected function getFileType(): FileTypeEnum {
+        return FileTypeEnum::LICENCE_CMF();
     }
 
     /**

+ 1 - 2
src/Service/ServiceIterator/EncoderIterator.php

@@ -26,7 +26,6 @@ class EncoderIterator
      *
      * @param string $format
      * @return EncoderInterface
-     * @throws Exception
      */
     public function getEncoderFor(string $format): EncoderInterface
     {
@@ -35,6 +34,6 @@ class EncoderIterator
             if($encoder->support($format))
                 return $encoder;
         }
-        throw new Exception('no encoder found for this export request');
+        throw new \RuntimeException('no encoder found for this export request');
     }
 }

+ 16 - 6
src/Service/Storage/FileStorage.php

@@ -51,6 +51,16 @@ class FileStorage
         return $this->filesystem->has($file->getSlug());
     }
 
+    /**
+     * Return the uri to download the given file
+     *
+     * @param File $file
+     * @return string
+     */
+    public function getUri(File $file): string {
+        return '';
+    }
+
     /**
      * Lists all the non-temporary files of the given owner
      *
@@ -103,21 +113,21 @@ class FileStorage
         bool $flushFile = true
     ): File
     {
+        [$organization, $person] = $this->getOrganizationAndPersonFromOwner($owner);
+
         $file = (new File())
             ->setName($filename)
+            ->setOrganization($organization)
+            ->setPerson($person)
             ->setSlug(null)
             ->setType($type->getValue())
             ->setVisibility($visibility)
             ->setIsTemporaryFile($isTemporary)
             ->setMimeType($mimeType ?? self::guessMimeTypeFromFilename($filename))
+            ->setCreateDate(new DateTime())
             ->setCreatedBy($createdBy->getId())
             ->setStatus(FileStatusEnum::PENDING()->getValue());
 
-        [$organization, $person] = $this->getOrganizationAndPersonFromOwner($owner);
-
-        $file->setOrganization($organization)
-             ->setPerson($person);
-
         $this->entityManager->persist($file);
 
         if ($flushFile) {
@@ -303,7 +313,7 @@ class FileStorage
         }
 
         if ($isTemporary) {
-            $prefix = Path::join('_temp_', $prefix);
+            $prefix = Path::join('temp', $prefix);
         }
 
         if ($type !== null && $type !== FileTypeEnum::NONE()->getValue()) {

+ 4 - 4
templates/export/licence_cmf.html.twig

@@ -239,7 +239,7 @@
                             <td width="80" id="avatar">
                                 <div align="center">
                                     {% if(licence.logoUri is null) %}
-                                        <img src="{{ asset('public/static/picto_face.png') }}"
+                                        <img src="{{ asset('static/picto_face.png') }}"
                                              width="85"
                                              height="82"/>
                                     {% else %}
@@ -263,7 +263,7 @@
                                 <div align="center">
                                     {% if(licence.personAvatarUri is null) %}
                                         <img
-                                                src="{{ asset('public/static/picto_face.png') }}"
+                                                src="{{ asset('static/picto_face.png') }}"
                                                 width="85"
                                                 height="82"/>
                                     {% else %}
@@ -288,7 +288,7 @@
                         <td width="70" valign="middle"
                             style="vertical-align: top;">
                             <div align="center">
-                                <img src="{{ asset('public/static/cmf_licence.png') }}"
+                                <img src="{{ asset('static/cmf_licence.png') }}"
                                      height="45"/>
                                 <span id="year_card">{{ licence.year }}</span>
                             </div>
@@ -302,7 +302,7 @@
                             </div>
                         </td>
                         <td width="70" align="right" valign="middle" id="qrCode">
-                            {% if(licence.qrCodeUri is not null) %}
+                            {% if(licence.qrCodeUri) %}
                                 <img style="margin-right: 10px;"
                                      src="{{ asset(licence.qrCodeUri) }}"
                                      alt=""

+ 10 - 14
tests/Service/Export/LicenceCmfExporterTest.php

@@ -4,7 +4,6 @@ use App\ApiResources\Export\ExportRequest;
 use App\ApiResources\Export\LicenceCmf\LicenceCmfOrganizationER;
 use App\Entity\Access\Access;
 use App\Entity\Core\File;
-use App\Entity\Network\Network;
 use App\Entity\Network\NetworkOrganization;
 use App\Entity\Organization\Organization;
 use App\Entity\Organization\Parameters;
@@ -13,12 +12,10 @@ use App\Repository\Access\AccessRepository;
 use App\Repository\Organization\OrganizationRepository;
 use App\Service\Export\Encoder\PdfEncoder;
 use App\Service\Export\LicenceCmfExporter;
-use App\Service\Export\Model\ExportModelInterface;
 use App\Service\Export\Model\LicenceCmf;
 use App\Service\Export\Model\LicenceCmfCollection;
 use App\Service\ServiceIterator\EncoderIterator;
-use App\Service\Storage\TemporaryFileStorage;
-use App\Service\Storage\UploadStorage;
+use App\Service\Storage\FileStorage;
 use App\Tests\TestToolsTrait;
 use Doctrine\Common\Collections\Collection;
 use Doctrine\ORM\EntityManagerInterface;
@@ -35,9 +32,8 @@ class LicenceCmfExporterTest extends TestCase
     private MockObject | Environment $twig;
     private MockObject | EncoderIterator $encoderIterator;
     private MockObject | EntityManagerInterface $em;
-    private MockObject | TemporaryFileStorage $storage;
+    private MockObject | FileStorage $storage;
     private MockObject | OrganizationRepository $organizationRepo;
-    private MockObject | UploadStorage $uploadStorage;
     private MockObject | Access $access;
     private MockObject | Organization $organization;
     private MockObject | Organization $cmf;
@@ -58,9 +54,8 @@ class LicenceCmfExporterTest extends TestCase
         $this->encoderIterator = $this->getMockBuilder(EncoderIterator::class)->disableOriginalConstructor()->getMock();
         $this->encoder = $this->getMockBuilder(PdfEncoder::class)->disableOriginalConstructor()->getMock();
         $this->em = $this->getMockBuilder(EntityManagerInterface::class)->disableOriginalConstructor()->getMock();
-        $this->storage = $this->getMockBuilder(TemporaryFileStorage::class)->disableOriginalConstructor()->getMock();
+        $this->storage = $this->getMockBuilder(FileStorage::class)->disableOriginalConstructor()->getMock();
         $this->organizationRepo = $this->getMockBuilder(OrganizationRepository::class)->disableOriginalConstructor()->getMock();
-        $this->uploadStorage = $this->getMockBuilder(UploadStorage::class)->disableOriginalConstructor()->getMock();
         $this->access = $this->getMockBuilder(Access::class)->getMock();
         $this->organization = $this->getMockBuilder(Organization::class)->getMock();
         $this->cmf = $this->getMockBuilder(Organization::class)->getMock();
@@ -77,7 +72,7 @@ class LicenceCmfExporterTest extends TestCase
     private function makeExporterMock(string $methodUnderTest): LicenceCmfExporter | MockObject
     {
         $exporter = $this->getMockBuilder(LicenceCmfExporter::class)
-            ->setConstructorArgs([$this->organizationRepo, $this->uploadStorage])
+            ->setConstructorArgs([$this->organizationRepo])
             ->setMethodsExcept(['setAccessRepository', 'setTwig', 'setEncoderIterator',
                 'setEntityManager', 'setEntityManager', 'setStorage', $methodUnderTest])
             ->getMock();
@@ -101,7 +96,8 @@ class LicenceCmfExporterTest extends TestCase
         $this->assertFalse($exporter->support($unsupportedExportRequest));
     }
 
-    private function prepareModelBuilding() {
+    private function prepareModelBuilding(): void
+    {
         $this->exportRequest->method('getRequesterId')->willReturn(1);
         $this->exportRequest->method('getYear')->willReturn(2020);
         $this->exportRequest->method('getFormat')->willReturn('pdf');
@@ -117,7 +113,7 @@ class LicenceCmfExporterTest extends TestCase
         $this->parent->expects(self::once())->method('getName')->willReturn('my_network');
         $this->organization->method('getLogo')->willReturn($this->logo);
         $this->logo->method('getId')->willReturn(1);
-        $this->uploadStorage->method('getUri')->willReturn('http:://foo.bar/1');
+        $this->storage->method('getUri')->willReturn('http:://foo.bar/1');
         $this->president->method('getId')->willReturn(1);
         $this->president->method('getGender')->willReturn('M');
         $this->president->method('getGivenName')->willReturn('Joe');
@@ -174,10 +170,10 @@ class LicenceCmfExporterTest extends TestCase
         $licence = $this->getMockBuilder(LicenceCmf::class)->getMock();
         $licence->method('getYear')->willReturn(2020);
 
-        $model = $this->getMockBuilder(LicenceCmfCollection::class)->getMock();
-        $model->method('getLicences')->willReturn([$licence]);
+        $exportRequest = $this->getMockBuilder(LicenceCmfOrganizationER::class)->getMock();
+        $exportRequest->method('getYear')->willReturn(2020);
 
-        $result = $this->invokeMethod($exporter, 'getFileBasename', [$model]);
+        $result = $this->invokeMethod($exporter, 'getFileBasename', [$exportRequest]);
 
         $this->assertEquals(
             'licence_cmf_2020.pdf',

+ 18 - 28
tests/Service/Storage/FileStorageTest.php

@@ -526,7 +526,7 @@ class FileStorageTest extends TestCase
 
         $prefix = $fileStorage->getPrefix($organization, true);
 
-        $this->assertEquals('_temp_/organization/1', $prefix);
+        $this->assertEquals('temp/organization/1', $prefix);
     }
 
     public function testGetPrefixWithType(): void {
@@ -544,36 +544,26 @@ class FileStorageTest extends TestCase
     }
 
     public function testGuessMimeTypeFromFilename(): void {
-        $fileStorage = $this->getMockBuilder(TestableFileStorage::class)
-            ->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository])
-            ->setMethodsExcept(['guessMimeTypeFromFilename'])
-            ->getMock();
-
-        $this->assertEquals('application/pdf', $fileStorage::guessMimeTypeFromFilename('file.pdf'));
-        $this->assertEquals('text/csv', $fileStorage::guessMimeTypeFromFilename('file.csv'));
-        $this->assertEquals('text/plain', $fileStorage::guessMimeTypeFromFilename('file.txt'));
-        $this->assertEquals('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', $fileStorage::guessMimeTypeFromFilename('file.xlsx'));
-        $this->assertEquals('application/xml', $fileStorage::guessMimeTypeFromFilename('file.xml'));
-
-        $this->assertEquals(null, $fileStorage::guessMimeTypeFromFilename('file'));
-        $this->assertEquals(null, $fileStorage::guessMimeTypeFromFilename('file.invalid'));
+        $this->assertEquals('application/pdf', TestableFileStorage::guessMimeTypeFromFilename('file.pdf'));
+        $this->assertEquals('text/csv', TestableFileStorage::guessMimeTypeFromFilename('file.csv'));
+        $this->assertEquals('text/plain', TestableFileStorage::guessMimeTypeFromFilename('file.txt'));
+        $this->assertEquals('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', TestableFileStorage::guessMimeTypeFromFilename('file.xlsx'));
+        $this->assertEquals('application/xml', TestableFileStorage::guessMimeTypeFromFilename('file.xml'));
+
+        $this->assertEquals(null, TestableFileStorage::guessMimeTypeFromFilename('file'));
+        $this->assertEquals(null, TestableFileStorage::guessMimeTypeFromFilename('file.invalid'));
     }
 
     public function testGuessMimeTypeFromExt(): void {
-        $fileStorage = $this->getMockBuilder(TestableFileStorage::class)
-            ->setConstructorArgs([$this->filesystemMap, $this->entityManager, $this->accessRepository])
-            ->setMethodsExcept(['guessMimeTypeFromExt'])
-            ->getMock();
-
-        $this->assertEquals('application/pdf', $fileStorage::getMimeTypeFromExt('pdf'));
-        $this->assertEquals('text/csv', $fileStorage::getMimeTypeFromExt('csv'));
-        $this->assertEquals('text/plain', $fileStorage::getMimeTypeFromExt('txt'));
-        $this->assertEquals('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', $fileStorage::getMimeTypeFromExt('xlsx'));
-        $this->assertEquals('application/xml', $fileStorage::getMimeTypeFromExt('xml'));
-
-        $this->assertEquals('text/plain', $fileStorage::getMimeTypeFromExt('.txt'));
-        $this->assertEquals(null, $fileStorage::getMimeTypeFromExt(''));
-        $this->assertEquals(null, $fileStorage::getMimeTypeFromExt('invalid'));
+        $this->assertEquals('application/pdf', TestableFileStorage::getMimeTypeFromExt('pdf'));
+        $this->assertEquals('text/csv', TestableFileStorage::getMimeTypeFromExt('csv'));
+        $this->assertEquals('text/plain', TestableFileStorage::getMimeTypeFromExt('txt'));
+        $this->assertEquals('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', TestableFileStorage::getMimeTypeFromExt('xlsx'));
+        $this->assertEquals('application/xml', TestableFileStorage::getMimeTypeFromExt('xml'));
+
+        $this->assertEquals('text/plain', TestableFileStorage::getMimeTypeFromExt('.txt'));
+        $this->assertEquals(null, TestableFileStorage::getMimeTypeFromExt(''));
+        $this->assertEquals(null, TestableFileStorage::getMimeTypeFromExt('invalid'));
     }
 
     public function testGetOrganizationAndPersonFromOwner(): void {