|
18 | 18 | use PHPUnit\Framework\Attributes\CoversClass;
|
19 | 19 | use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
|
20 | 20 | use PKP\db\DAORegistry;
|
| 21 | +use PKP\file\FileManager; |
21 | 22 | use PKP\task\FileLoader;
|
22 | 23 | use PKP\tests\PKPTestCase;
|
23 | 24 | use ReflectionClass;
|
@@ -60,6 +61,8 @@ public function testRunSerializedJob(): void
|
60 | 61 | // we need to create a dummy file if not existed as to avoid mocking PHP's built in functions
|
61 | 62 | $dummyFile = $this->createDummyFileIfNeeded($processUsageStatsLogFileJob, 'loadId');
|
62 | 63 |
|
| 64 | + $this->createArchiveDirectoryIfRequired(); |
| 65 | + |
63 | 66 | $temporaryTotalsDAOMock = Mockery::mock(\APP\statistics\TemporaryTotalsDAO::class)
|
64 | 67 | ->makePartial()
|
65 | 68 | ->shouldReceive([
|
@@ -129,10 +132,40 @@ protected function createDummyFileIfNeeded(ProcessUsageStatsLogFile $job, string
|
129 | 132 | . DIRECTORY_SEPARATOR;
|
130 | 133 |
|
131 | 134 | 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 | + |
132 | 144 | file_put_contents($filePath . $fileName, $this->dummyFileContent);
|
133 | 145 | return $filePath . $fileName;
|
134 | 146 | }
|
135 | 147 |
|
136 | 148 | return null;
|
137 | 149 | }
|
| 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 | + } |
138 | 171 | }
|
0 commit comments