From ad858396bead34bc24c0147bd3722418af85fca3 Mon Sep 17 00:00:00 2001 From: Touhidur Rahman Date: Tue, 1 Oct 2024 10:20:29 +0600 Subject: [PATCH] pkp/pkp-lib#10306 fixed issue with dummy file --- .../ProcessUsageStatsLogFileTest.php | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/jobs/statistics/ProcessUsageStatsLogFileTest.php b/tests/jobs/statistics/ProcessUsageStatsLogFileTest.php index 18b69199b96..31dd4fbaff1 100644 --- a/tests/jobs/statistics/ProcessUsageStatsLogFileTest.php +++ b/tests/jobs/statistics/ProcessUsageStatsLogFileTest.php @@ -18,6 +18,7 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; use PKP\db\DAORegistry; +use PKP\file\FileManager; use PKP\task\FileLoader; use PKP\tests\PKPTestCase; use ReflectionClass; @@ -60,6 +61,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([ @@ -129,10 +132,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); + } }