Skip to content

Commit

Permalink
Fix phpunit tests that use temp files
Browse files Browse the repository at this point in the history
  • Loading branch information
cpeel committed Dec 8, 2023
1 parent 78f0532 commit 965a8d5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
13 changes: 4 additions & 9 deletions SETUP/tests/ProjectUtils.inc
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,14 @@ class ProjectUtils extends PHPUnit\Framework\TestCase

protected function add_page($project, $base)
{
$source_project_dir = sys_get_temp_dir();
$txt_file_name = "$base.txt";
$txt_file_path = "$source_project_dir/$txt_file_name";
$fp = fopen($txt_file_path, 'w');
fwrite($fp, $this->TEST_TEXT);
fclose($fp);
$txt_file_path = "$project->dir/$txt_file_name";
file_put_contents($txt_file_path, $this->TEST_TEXT);

$image_file_name = "$base.png";
$img_file_path = "{$project->dir}/$image_file_name";
$fp = fopen($img_file_path, 'w');
$img_file_path = "$project->dir/$image_file_name";
// write some data so file is not too short
fwrite($fp, str_repeat("This is a test image file", 10));
fclose($fp);
file_put_contents($img_file_path, str_repeat("This is a test image file", 10));

project_add_page($project->projectid, $base, $image_file_name, $txt_file_path, $this->TEST_USERNAME_PM, time());
}
Expand Down
5 changes: 4 additions & 1 deletion SETUP/tests/phpunit_bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
global $relPath, $forum_type;
global $relPath, $forum_type, $projects_dir, $aspell_temp_dir;
$relPath = '../../pinc/';
include_once($relPath.'base.inc');
include_once($relPath.'misc.inc');
Expand All @@ -9,3 +9,6 @@

include_once("phpunit_test_helpers.inc");
include_once("ProjectUtils.inc");

// Define top-level temporary directories
$projects_dir = $aspell_temp_dir = "/tmp";

0 comments on commit 965a8d5

Please sign in to comment.