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; + } }