Skip to content

Commit 6be229d

Browse files
committed
pkp/pkp-lib#10306 fixed issue with dummy file
1 parent aab18f4 commit 6be229d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/jobs/statistics/ProcessUsageStatsLogFileTest.php

+33
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use PHPUnit\Framework\Attributes\CoversClass;
1919
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
2020
use PKP\db\DAORegistry;
21+
use PKP\file\FileManager;
2122
use PKP\task\FileLoader;
2223
use PKP\tests\PKPTestCase;
2324
use ReflectionClass;
@@ -60,6 +61,8 @@ public function testRunSerializedJob(): void
6061
// we need to create a dummy file if not existed as to avoid mocking PHP's built in functions
6162
$dummyFile = $this->createDummyFileIfNeeded($processUsageStatsLogFileJob, 'loadId');
6263

64+
$this->createArchiveDirectoryIfRequired();
65+
6366
$temporaryTotalsDAOMock = Mockery::mock(\APP\statistics\TemporaryTotalsDAO::class)
6467
->makePartial()
6568
->shouldReceive([
@@ -129,10 +132,40 @@ protected function createDummyFileIfNeeded(ProcessUsageStatsLogFile $job, string
129132
. DIRECTORY_SEPARATOR;
130133

131134
if (!file_exists($filePath . $fileName)) {
135+
136+
// create the 'FileLoader::FILE_LOADER_PATH_DISPATCH' directory if not exists
137+
if (!file_exists($filePath)) {
138+
$fileManager = new FileManager();
139+
$fileManager->mkdirtree($filePath);
140+
}
141+
142+
touch($filePath . $fileName);
143+
132144
file_put_contents($filePath . $fileName, $this->dummyFileContent);
133145
return $filePath . $fileName;
134146
}
135147

136148
return null;
137149
}
150+
151+
/**
152+
* Create the archive path/directory as needed
153+
*/
154+
protected function createArchiveDirectoryIfRequired(): bool
155+
{
156+
$filePath = StatisticsHelper::getUsageStatsDirPath()
157+
. DIRECTORY_SEPARATOR
158+
. FileLoader::FILE_LOADER_PATH_ARCHIVE
159+
. DIRECTORY_SEPARATOR;
160+
161+
if (file_exists($filePath)) {
162+
return true;
163+
}
164+
165+
// create the 'FileLoader::FILE_LOADER_PATH_ARCHIVE' directory if not exists
166+
$fileManager = new FileManager();
167+
$fileManager->mkdirtree($filePath);
168+
169+
return file_exists($filePath);
170+
}
138171
}

0 commit comments

Comments
 (0)