From 59c84410f2892b27231c0d9b91b8f74405bfc203 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Wed, 14 Aug 2024 09:44:23 +0200 Subject: [PATCH] dev: Fix some PHPUnit Testdox warnings I detected these warnings by running the tests of this specific file. It appears that silenced warnings are detected by the Testdox output, but not by the default output. The best would be to never use `@` anyway. Reference: https://github.com/sebastianbergmann/phpunit/issues/5884 --- .../Service/DataImporter/DataImporterTest.php | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/Service/DataImporter/DataImporterTest.php b/tests/Service/DataImporter/DataImporterTest.php index 93941b27..94462748 100644 --- a/tests/Service/DataImporter/DataImporterTest.php +++ b/tests/Service/DataImporter/DataImporterTest.php @@ -1334,8 +1334,7 @@ public function testImportTicketsImportsDocumentsAsWell(): void ], ], ]; - $documentsPath = sys_get_temp_dir() . '/documents'; - @mkdir($documentsPath); + $documentsPath = $this->createDocumentsFolder(); $content = 'My bug'; $hash = hash('sha256', $content); file_put_contents($documentsPath . '/bug.txt', $content); @@ -2058,9 +2057,11 @@ public function testImportTicketsFailsIfDocumentIsMissing(): void ], ], ]; - $documentsPath = sys_get_temp_dir() . '/documents'; - @mkdir($documentsPath); - @unlink($documentsPath . '/bug.txt'); + $documentsPath = $this->createDocumentsFolder(); + $filepath = "{$documentsPath}/bug.txt"; + if (file_exists($filepath)) { + unlink($filepath); + } $this->processGenerator($this->dataImporter->import( organizations: $organizations, @@ -2072,4 +2073,15 @@ public function testImportTicketsFailsIfDocumentIsMissing(): void $this->assertSame(0, MessageFactory::count()); $this->assertSame(0, MessageDocumentFactory::count()); } + + private function createDocumentsFolder(): string + { + $documentsPath = sys_get_temp_dir() . '/documents'; + + if (!is_dir($documentsPath)) { + mkdir($documentsPath); + } + + return $documentsPath; + } }