Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QA - Sentry] setKey on Array / TypeError #2218

Merged
merged 4 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/Controller/FrontSignalementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,12 @@ public function handleUpload(
if (null !== ($files = $request->files->get('signalement'))) {
try {
foreach ($files as $key => $file) {
$res = $uploadHandlerService->toTempFolder($file)->setKey($key);
if (!isset($res['error'])
&& \in_array($file->getMimeType(), ImageManipulationHandler::IMAGE_MIME_TYPES)
) {
$res = $uploadHandlerService->toTempFolder($file);
if (\is_array($res) && isset($res['error'])) {
throw new \Exception($res['error']);
}
$res = $uploadHandlerService->setKey($key);
if (\in_array($file->getMimeType(), ImageManipulationHandler::IMAGE_MIME_TYPES)) {
$imageManipulationHandler->resize($res['filePath'])->thumbnail();
}

Expand Down Expand Up @@ -202,11 +204,13 @@ public function envoi(
$signalement = new Signalement();
$dataDateBail = $dataHasDPE = $dataDateDPE = $dataConsoSizeYear = $dataConsoSize = $dataConsoYear = null;
$listNDECriticites = [];

if (isset($data['files'])) {
$dataFiles = $data['files'];
foreach ($dataFiles as $key => $files) {
foreach ($files as $titre => $file) {
if (\is_array($file)) {
continue;
}
$filename = $uploadHandlerService->moveFromBucketTempFolder($file);
$file = $fileFactory->createInstanceFrom(
filename: $filename,
Expand Down
29 changes: 29 additions & 0 deletions tests/Functional/Service/UploadHandlerServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\File\Exception\FileException;
use Symfony\Component\HttpFoundation\File\UploadedFile;

class UploadHandlerServiceTest extends KernelTestCase
Expand Down Expand Up @@ -108,6 +109,34 @@ public function testUploadBigFileShouldThrowsException(): void
$uploadHandlerService->uploadFromFile($uploadedFileMock, 'test.png');
}

public function testUploadToTempFolderThrowException(): void
{
$uploadFile = new UploadedFile(
$this->projectDir.$this->fixturesPath.$this->targetFilename.$this->extension,
$this->targetFilename,
'image/png',
null,
true
);

$this->filesystemOperator
->expects($this->once())
->method('writeStream')
->willThrowException(new FileException());

$uploadHandlerService = new UploadHandlerService(
$this->filesystemOperator,
$this->parameterBag,
$this->logger,
$this->heicToJpegConverter,
$this->filenameGenerator,
);

$uploadHandler = $uploadHandlerService->toTempFolder($uploadFile);
$this->assertIsArray($uploadHandler);
$this->assertArrayHasKey('error', $uploadHandler);
}

/*public function testUploadFromFilename(): void
{
$this->heicToJpegConverter
Expand Down
Loading