[php-src] master: ext/session: simplify temp directory handling in tests (#24312)
| From: | Jorg Adam Sowa via GitHub | Date: | Wed, 14 Oct 2026 18:47:03 +0000 |
| Subject: | [php-src] master: ext/session: simplify temp directory handling in tests (#24312) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-142288@lists.php.net to get a copy of this message | ||
Author: Jorg Adam Sowa (jorgsowa)
Committer: GitHub (web-flow)
Pusher: jorgsowa
Date: 2026-10-14T20:46:59+02:00
Commit: https://github.com/php/php-src/commit/89561c83ef7dc4d98e977e10e5ba22244b48698c
Raw diff: https://github.com/php/php-src/commit/89561c83ef7dc4d98e977e10e5ba22244b48698c.diff
ext/session: simplify temp directory handling in tests (#24312)
Drop the pre-emptive rmdir() before mkdir(), move cleanup into --CLEAN--
sections, stop bug61470 from writing session files into the tests
directory, and remove a --CLEAN-- section in rfc1867_sid_invalid that
deleted a file nothing creates.
Changed paths:
M ext/session/tests/bug42596.phpt
M ext/session/tests/bug61470.phpt
M ext/session/tests/rfc1867_sid_invalid.phpt
M ext/session/tests/session_save_path_variation4.phpt
M ext/session/tests/session_save_path_variation5.phpt
Diff:
diff --git a/ext/session/tests/bug42596.phpt b/ext/session/tests/bug42596.phpt
index c5a1099c353b..26cb65fbd17d 100644
--- a/ext/session/tests/bug42596.phpt
+++ b/ext/session/tests/bug42596.phpt
@@ -17,20 +17,22 @@ session.serialize_handler=php
session.save_handler=files
--FILE--
<?php
-$sessdir = __DIR__.'/bug42596/';
-@rmdir($sessdir);
+$sessdir = __DIR__ . '/bug42596/';
mkdir($sessdir);
-$save_path = '0;0777;'.$sessdir;
umask(0);
-session_save_path($save_path);
+session_save_path('0;0777;' . $sessdir);
session_start();
echo "hello world\n";
session_write_close();
foreach (glob($sessdir. "*") as $sessfile) {
var_dump(decoct(fileperms($sessfile)));
- unlink($sessfile);
}
+?>
+--CLEAN--
+<?php
+$sessdir = __DIR__ . '/bug42596/';
+array_map('unlink', glob($sessdir . '*'));
rmdir($sessdir);
?>
--EXPECT--
diff --git a/ext/session/tests/bug61470.phpt b/ext/session/tests/bug61470.phpt
index de17015d9379..d4230beae427 100644
--- a/ext/session/tests/bug61470.phpt
+++ b/ext/session/tests/bug61470.phpt
@@ -7,7 +7,8 @@ session
--FILE--
<?php
ob_start();
-ini_set('session.save_path', __DIR__);
+mkdir(__DIR__ . '/bug61470');
+ini_set('session.save_path', __DIR__ . '/bug61470');
$path = ini_get('session.save_path') . '/sess_';
session_start();
// starts session & creates and locks file
@@ -18,10 +19,13 @@ session_regenerate_id();
// starts new session, but file is not create!
$file2 = $path . session_id();
var_dump(is_file($file2));
-
-// cleanup
-@unlink($file1);
-@unlink($file2);
+?>
+--CLEAN--
+<?php
+foreach (glob(__DIR__ . '/bug61470/sess_*') as $file) {
+ unlink($file);
+}
+rmdir(__DIR__ . '/bug61470');
?>
--EXPECT--
bool(true)
diff --git a/ext/session/tests/rfc1867_sid_invalid.phpt b/ext/session/tests/rfc1867_sid_invalid.phpt
index 3e7f15e7c749..687fbcd96b5d 100644
--- a/ext/session/tests/rfc1867_sid_invalid.phpt
+++ b/ext/session/tests/rfc1867_sid_invalid.phpt
@@ -46,10 +46,6 @@ var_dump($_FILES);
var_dump($_SESSION["upload_progress_" . basename(__FILE__)]);
session_destroy();
?>
---CLEAN--
-<?php
-@unlink(__DIR__ . DIRECTORY_SEPARATOR . "rfc1867_sid_invalid.post.txt");
-?>
--EXPECTF--
Warning: PHP Request Startup: Session ID is too long or contains illegal characters. Only the A-Z,
a-z, 0-9, "-", and "," characters are allowed in Unknown on line 0
diff --git a/ext/session/tests/session_save_path_variation4.phpt
b/ext/session/tests/session_save_path_variation4.phpt
index ec3acdd32392..8091688e92b6 100644
--- a/ext/session/tests/session_save_path_variation4.phpt
+++ b/ext/session/tests/session_save_path_variation4.phpt
@@ -16,15 +16,10 @@ ob_start();
echo "*** Testing session_save_path() : variation ***\n";
$initdir = __DIR__;
-$sessions = ($initdir."/session_save_path_variation4");
+$sessions = $initdir . "/session_save_path_variation4";
chdir($initdir);
-// Delete the existing directory
-if (file_exists($sessions) === TRUE) {
- @rmdir($sessions);
-}
-
var_dump(mkdir($sessions));
var_dump(chdir($sessions));
ini_set("session.save_path", $initdir);
@@ -39,9 +34,7 @@ ob_end_flush();
?>
--CLEAN--
<?php
-$initdir = __DIR__;
-$sessions = ($initdir."/session_save_path_variation4");
-rmdir($sessions);
+rmdir(__DIR__ . "/session_save_path_variation4");
?>
--EXPECTF--
*** Testing session_save_path() : variation ***
diff --git a/ext/session/tests/session_save_path_variation5.phpt
b/ext/session/tests/session_save_path_variation5.phpt
index 7d3defd66641..2f2f73d96705 100644
--- a/ext/session/tests/session_save_path_variation5.phpt
+++ b/ext/session/tests/session_save_path_variation5.phpt
@@ -17,15 +17,10 @@ session.name=PHPSESSID
ob_start();
echo "*** Testing session_save_path() : variation ***\n";
$directory = __DIR__;
-$sessions = ($directory."/session_save_path_variation5");
+$sessions = $directory . "/session_save_path_variation5";
chdir($directory);
ini_set('open_basedir', '.');
-// Delete the existing directory
-if (file_exists($sessions) === TRUE) {
- @rmdir($sessions);
-}
-
var_dump(mkdir($sessions));
var_dump(chdir($sessions));
ini_set('open_basedir', '.');
@@ -37,9 +32,7 @@ ob_end_flush();
?>
--CLEAN--
<?php
-$directory = __DIR__;
-$sessions = ($directory."/session_save_path_variation5");
-rmdir($sessions);
+rmdir(__DIR__ . "/session_save_path_variation5");
?>
--EXPECTF--
*** Testing session_save_path() : variation ***