diff --git a/tests/jobs/statistics/ProcessUsageStatsLogFileTest.php b/tests/jobs/statistics/ProcessUsageStatsLogFileTest.php index b654e79eedb..0927924ff12 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 @@ -75,6 +76,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(); + $temporaryTotalsDAOMock = Mockery::mock(\APP\statistics\TemporaryTotalsDAO::class) ->makePartial() ->shouldReceive([ @@ -142,10 +145,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); + } }