Skip to content

Commit

Permalink
pkp/pkp-lib#10306 fixed issue with dummy file
Browse files Browse the repository at this point in the history
  • Loading branch information
touhidurabir committed Oct 1, 2024
1 parent c90043e commit 28409a3
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/jobs/statistics/ProcessUsageStatsLogFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 28409a3

Please sign in to comment.