diff --git a/tests/jobs/statistics/ProcessUsageStatsLogFileTest.php b/tests/jobs/statistics/ProcessUsageStatsLogFileTest.php index 29934eb82d9..c80b699ad40 100644 --- a/tests/jobs/statistics/ProcessUsageStatsLogFileTest.php +++ b/tests/jobs/statistics/ProcessUsageStatsLogFileTest.php @@ -12,13 +12,14 @@ namespace APP\tests\jobs\statistics; -use APP\jobs\statistics\ProcessUsageStatsLogFile; -use APP\statistics\StatisticsHelper; use Mockery; +use ReflectionClass; use PKP\db\DAORegistry; use PKP\task\FileLoader; +use PKP\file\FileManager; use PKP\tests\PKPTestCase; -use ReflectionClass; +use APP\statistics\StatisticsHelper; +use APP\jobs\statistics\ProcessUsageStatsLogFile; /** * @runTestsInSeparateProcesses @@ -77,6 +78,8 @@ public function testRunSerializedJob(): void // we need to create a dummy file if not existed as to avoid mocking PHP's built in functions $dummyFile = $this->createDummyFileIfNeeded($processUsageStatsLogFileJob, 'loadId'); + $this->createArchiveDirectoryIfRequired(); + $temporaryInstitutionsDAOMock = Mockery::mock(\PKP\statistics\TemporaryInstitutionsDAO::class) ->makePartial() ->shouldReceive([ @@ -166,10 +169,40 @@ protected function createDummyFileIfNeeded(ProcessUsageStatsLogFile $job, string . DIRECTORY_SEPARATOR; if (!file_exists($filePath . $fileName)) { + + // create the 'FileLoader::FILE_LOADER_PATH_DISPATCH' directory if not exists + if (!file_exists($filePath)) { + $fileManager = new FileManager(); + $fileManager->mkdirtree($filePath); + } + + touch($filePath . $fileName); + file_put_contents($filePath . $fileName, $this->dummyFileContent); return $filePath . $fileName; } return null; } + + /** + * Create the archive path/directory as needed + */ + protected function createArchiveDirectoryIfRequired(): bool + { + $filePath = StatisticsHelper::getUsageStatsDirPath() + . DIRECTORY_SEPARATOR + . FileLoader::FILE_LOADER_PATH_ARCHIVE + . DIRECTORY_SEPARATOR; + + if (file_exists($filePath)) { + return true; + } + + // create the 'FileLoader::FILE_LOADER_PATH_ARCHIVE' directory if not exists + $fileManager = new FileManager(); + $fileManager->mkdirtree($filePath); + + return file_exists($filePath); + } }