Skip to content

Commit 3be2b0d

Browse files
authoredDec 12, 2022
Add CLEAN section to some IO tests (#10081)
* Add CLEAN sections to file_(get|put)_contents() tests * Add CLEAN sections to file() tests
1 parent e36c600 commit 3be2b0d

25 files changed

+202
-55
lines changed
 

‎ext/standard/tests/file/file_get_contents_basic.phpt

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,15 @@ echo "\n-- Testing with empty file --\n";
2121

2222
create_files($file_path, 1, "empty", 0755, 100, "w", "file", 1, "byte");
2323
var_dump( file_get_contents($file_path."/file1.tmp") );
24-
delete_files($file_path, 1);
2524

2625
echo "\n*** Done ***";
2726
?>
27+
--CLEAN--
28+
<?php
29+
$file_path = __DIR__;
30+
include($file_path."/file.inc");
31+
delete_files($file_path, 1);
32+
?>
2833
--EXPECT--
2934
*** Testing the basic functionality of the file_get_contents() function ***
3035
-- Testing with simple valid data file --

‎ext/standard/tests/file/file_get_contents_variation1.phpt

+6-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ set_include_path($newpath);
2323
runtest();
2424
teardown_include_path();
2525
chdir("..");
26-
rmdir($thisTestDir);
2726

2827

2928
function runtest() {
@@ -36,6 +35,12 @@ function runtest() {
3635
unlink($secondFile);
3736
}
3837

38+
?>
39+
--CLEAN--
40+
<?php
41+
// TODO Clean up tmp files
42+
$thisTestDir = "fileGetContentsVar1.dir";
43+
rmdir($thisTestDir);
3944
?>
4045
--EXPECT--
4146
*** Testing file_get_contents() : variation ***

‎ext/standard/tests/file/file_get_contents_variation2.phpt

+6-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ set_include_path($newpath);
2424
runtest();
2525
teardown_include_path();
2626
chdir("..");
27-
rmdir($thisTestDir);
2827

2928

3029
function runtest() {
@@ -37,6 +36,12 @@ function runtest() {
3736
unlink($scriptLocFile);
3837
}
3938

39+
?>
40+
--CLEAN--
41+
<?php
42+
$thisTestDir = "FileGetContentsVar2.dir";
43+
// TODO Clean up tmp files?
44+
rmdir($thisTestDir);
4045
?>
4146
--EXPECT--
4247
*** Testing file_get_contents() : variation ***

‎ext/standard/tests/file/file_get_contents_variation7-win32-mb.phpt

+12-3
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,22 @@ for($i = 0; $i<count($allDirs); $i++) {
5454
var_dump(file_get_contents($dir."\\".$filename));
5555
}
5656

57-
unlink($absFile);
5857
chdir($old_dir_path);
59-
rmdir($absSubDir);
60-
rmdir($absMainDir);
6158

6259
echo "\n*** Done ***\n";
6360
?>
61+
--CLEAN--
62+
<?php
63+
$mainDir = "fileGetContentsVar7私はガラスを食べられます.dir";
64+
$subDir = "fileGetContentsVar7Sub私はガラスを食べられます";
65+
$absMainDir = __DIR__."/".$mainDir;
66+
$absSubDir = $absMainDir."/".$subDir;
67+
$filename = 'FileGetContentsVar7.tmp';
68+
$absFile = $absSubDir.'/'.$filename;
69+
unlink($absFile);
70+
rmdir($absSubDir);
71+
rmdir($absMainDir);
72+
?>
6473
--EXPECTF--
6574
*** Testing file_get_contents() : variation ***
6675

‎ext/standard/tests/file/file_get_contents_variation7-win32.phpt

+12-3
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,22 @@ for($i = 0; $i<count($allDirs); $i++) {
5454
var_dump(file_get_contents($dir."\\".$filename));
5555
}
5656

57-
unlink($absFile);
5857
chdir($old_dir_path);
59-
rmdir($absSubDir);
60-
rmdir($absMainDir);
6158

6259
echo "\n*** Done ***\n";
6360
?>
61+
--CLEAN--
62+
<?php
63+
$mainDir = "fileGetContentsVar7.dir";
64+
$subDir = "fileGetContentsVar7Sub";
65+
$absMainDir = __DIR__."/".$mainDir;
66+
$absSubDir = $absMainDir."/".$subDir;
67+
$filename = 'FileGetContentsVar7.tmp';
68+
$absFile = $absSubDir.'/'.$filename;
69+
unlink($absFile);
70+
rmdir($absSubDir);
71+
rmdir($absMainDir);
72+
?>
6473
--EXPECTF--
6574
*** Testing file_get_contents() : variation ***
6675

‎ext/standard/tests/file/file_get_contents_variation7.phpt

+11-2
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,20 @@ for($i = 0; $i<count($allDirs); $i++) {
4747
}
4848

4949
chdir($old_dir_path);
50+
51+
echo "\n*** Done ***\n";
52+
?>
53+
--CLEAN--
54+
<?php
55+
$mainDir = "fileGetContentsVar7.dir";
56+
$subDir = "fileGetContentsVar7Sub";
57+
$absMainDir = __DIR__."/".$mainDir;
58+
$absSubDir = $absMainDir."/".$subDir;
59+
$filename = 'FileGetContentsVar7.tmp';
60+
$absFile = $absSubDir.'/'.$filename;
5061
unlink($absFile);
5162
rmdir($absSubDir);
5263
rmdir($absMainDir);
53-
54-
echo "\n*** Done ***\n";
5564
?>
5665
--EXPECTF--
5766
*** Testing file_get_contents() : variation ***

‎ext/standard/tests/file/file_get_contents_variation9.phpt

+8-2
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,18 @@ var_dump(file_get_contents($chainlink));
3333
var_dump(file_get_contents($softlink));
3434
var_dump(file_get_contents($hardlink));
3535

36+
echo "\n*** Done ***\n";
37+
?>
38+
--CLEAN--
39+
<?php
40+
$filename = __DIR__.'/fileGetContentsVar9.tmp';
41+
$softlink = __DIR__.'/fileGetContentsVar9.SoftLink';
42+
$hardlink = __DIR__.'/fileGetContentsVar9.HardLink';
43+
$chainlink = __DIR__.'/fileGetContentsVar9.ChainLink';
3644
unlink($chainlink);
3745
unlink($softlink);
3846
unlink($hardlink);
3947
unlink($filename);
40-
41-
echo "\n*** Done ***\n";
4248
?>
4349
--EXPECT--
4450
*** Testing file_get_contents() : variation ***

‎ext/standard/tests/file/file_put_contents.phpt

+5-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ try {
2525
echo $e->getMessage(), "\n";
2626
}
2727

28-
@unlink($file);
29-
3028
echo "Done\n";
3129
?>
30+
--CLEAN--
31+
<?php
32+
$file = __DIR__."/file_put_contents.txt";
33+
unlink($file);
34+
?>
3235
--EXPECT--
3336
file_put_contents(): supplied resource is not a valid stream resource
3437
bool(false)

‎ext/standard/tests/file/file_put_contents_variation1.phpt

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ file_put_contents($filename, $data);
2121
echo filesize($filename)."\n";
2222
readfile($filename);
2323
echo "\n";
24-
unlink($filename);
2524

2625

26+
?>
27+
--CLEAN--
28+
<?php
29+
$filename = "FilePutContentsVar1.tmp";
30+
unlink($filename);
2731
?>
2832
--EXPECT--
2933
*** Testing file_put_contents() : variation ***

‎ext/standard/tests/file/file_put_contents_variation2.phpt

+5-1
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,12 @@ foreach($inputs as $key =>$value) {
100100
file_put_contents($filename, $value);
101101
readfile($filename);
102102
};
103-
unlink($filename);
104103

104+
?>
105+
--CLEAN--
106+
<?php
107+
$filename = __DIR__ . '/fwriteVar5.tmp';
108+
unlink($filename);
105109
?>
106110
--EXPECT--
107111
*** Testing file_put_contents() : usage variation ***

‎ext/standard/tests/file/file_put_contents_variation4.phpt

+7-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ runtest();
2222

2323
teardown_include_path();
2424
chdir("..");
25-
rmdir($thisTestDir);
26-
2725

2826
function runtest() {
2927
global $filename;
@@ -35,6 +33,13 @@ function runtest() {
3533
unlink($filename);
3634
}
3735

36+
?>
37+
--CLEAN--
38+
<?php
39+
$thisTestDir = basename(__FILE__, ".clean.php") . ".dir";
40+
$filename = basename(__FILE__, ".clean.php") . ".tmp";
41+
@unlink($filename);
42+
rmdir($thisTestDir);
3843
?>
3944
--EXPECT--
4045
File in include path

‎ext/standard/tests/file/file_put_contents_variation5.phpt

+10-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Dave Kelsey <d_kelsey@uk.ibm.com>
66
<?php
77

88

9-
$thisTestDir = __DIR__ . '/' .basename(__FILE__, ".php") . ".directory";
9+
$thisTestDir = __DIR__ . '/' .basename(__FILE__, ".php") . ".dir";
1010
mkdir($thisTestDir);
1111
chdir($thisTestDir);
1212

@@ -25,7 +25,6 @@ set_include_path(";; ; ;c:\\rubbish");
2525
runtest();
2626

2727
chdir(__DIR__);
28-
rmdir($thisTestDir);
2928

3029

3130
function runtest() {
@@ -41,6 +40,15 @@ function runtest() {
4140
}
4241
}
4342
?>
43+
--CLEAN--
44+
<?php
45+
$thisTestDir = __DIR__ . '/' . basename(__FILE__, ".clean.php") . ".dir";
46+
$filename = basename(__FILE__, ".clean.php") . ".tmp";
47+
$scriptLocFile = __DIR__."/".$filename;
48+
@unlink($filename);
49+
@unlink($scriptLocFile);
50+
rmdir($thisTestDir);
51+
?>
4452
--EXPECT--
4553
File written in working directory
4654
File written in working directory

‎ext/standard/tests/file/file_put_contents_variation6.phpt

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ runtest();
2424

2525
teardown_include_path();
2626
chdir("..");
27-
rmdir($thisTestDir);
2827

2928

3029
function runtest() {
@@ -40,6 +39,13 @@ function runtest() {
4039
unlink($filename);
4140
}
4241

42+
?>
43+
--CLEAN--
44+
<?php
45+
$thisTestDir = basename(__FILE__, ".clean.php") . ".dir";
46+
$filename = basename(__FILE__, ".clean.php") . ".tmp";
47+
@unlink($filename);
48+
rmdir($thisTestDir);
4349
?>
4450
--EXPECT--
4551
*** Testing file_put_contents() : variation ***

‎ext/standard/tests/file/file_put_contents_variation7-win32.phpt

+12-2
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,21 @@ for($i = 0; $i<count($allDirs); $i++) {
7171
}
7272

7373
chdir($old_dir_path);
74-
rmdir($absSubDir);
75-
rmdir($absMainDir);
7674

7775
echo "\n*** Done ***\n";
7876
?>
77+
--CLEAN--
78+
<?php
79+
$mainDir = "filePutContentsVar7.dir";
80+
$subDir = "filePutContentsVar7Sub";
81+
$absMainDir = __DIR__."/".$mainDir;
82+
$absSubDir = $absMainDir."/".$subDir;
83+
$filename = 'FileGetContentsVar7.tmp';
84+
$absFile = $absSubDir.'/'.$filename;
85+
@unlink($absFile);
86+
rmdir($absSubDir);
87+
rmdir($absMainDir);
88+
?>
7989
--EXPECTF--
8090
*** Testing file_put_contents() : usage variation ***
8191

‎ext/standard/tests/file/file_put_contents_variation7.phpt

+12-2
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,21 @@ for($i = 0; $i<count($allDirs); $i++) {
6363
}
6464

6565
chdir($old_dir_path);
66-
rmdir($absSubDir);
67-
rmdir($absMainDir);
6866

6967
echo "\n*** Done ***\n";
7068
?>
69+
--CLEAN--
70+
<?php
71+
$mainDir = "filePutContentsVar7.dir";
72+
$subDir = "filePutContentsVar7Sub";
73+
$absMainDir = __DIR__."/".$mainDir;
74+
$absSubDir = $absMainDir."/".$subDir;
75+
$filename = 'FileGetContentsVar7.tmp';
76+
$absFile = $absSubDir.'/'.$filename;
77+
@unlink($absFile);
78+
rmdir($absSubDir);
79+
rmdir($absMainDir);
80+
?>
7181
--EXPECTF--
7282
*** Testing file_put_contents() : usage variation ***
7383

‎ext/standard/tests/file/file_put_contents_variation8.phpt

+6-1
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,15 @@ for( $i=0; $i<count($names_arr); $i++ ) {
4848
echo get_class($e) . ': ' . $e->getMessage(), "\n";
4949
}
5050
}
51-
rmdir($dir);
5251

5352
echo "\n*** Done ***\n";
5453
?>
54+
--CLEAN--
55+
<?php
56+
$dir = __DIR__ . '/file_put_contents_variation8';
57+
// TODO Cleanup temp files?
58+
rmdir($dir);
59+
?>
5560
--EXPECTF--
5661
*** Testing file_put_contents() : usage variation ***
5762
-- Iteration 0 --

‎ext/standard/tests/file/file_put_contents_variation9.phpt

+11-6
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ file_put_contents($filename,"");
3131
link($filename, $hardlink);
3232
run_test($hardlink);
3333

34-
unlink($chainlink);
35-
unlink($softlink);
36-
unlink($hardlink);
37-
unlink($filename);
38-
39-
4034
function run_test($file) {
4135
$data = "Here is some data";
4236
$extra = ", more data";
@@ -49,6 +43,17 @@ function run_test($file) {
4943

5044
echo "\n*** Done ***\n";
5145
?>
46+
--CLEAN--
47+
<?php
48+
$filename = __DIR__.'/filePutContentsVar9.tmp';
49+
$softlink = __DIR__.'/filePutContentsVar9.SoftLink';
50+
$hardlink = __DIR__.'/filePutContentsVar9.HardLink';
51+
$chainlink = __DIR__.'/filePutContentsVar9.ChainLink';
52+
unlink($chainlink);
53+
unlink($softlink);
54+
unlink($hardlink);
55+
unlink($filename);
56+
?>
5257
--EXPECT--
5358
*** Testing file_put_contents() : usage variation ***
5459
int(17)

‎ext/standard/tests/file/file_variation5-win32-mb.phpt

+7-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ chdir($script_directory);
1414
$test_dirname = basename(__FILE__, ".php") . "私はガラスを食べられますtestdir";
1515
mkdir($test_dirname);
1616

17-
$filepath = __FILE__ . ".tmp";
17+
$filepath = __DIR__ . '/file_variation_5.tmp';
1818
$filename = basename($filepath);
1919
$fd = fopen($filepath, "w+");
2020
fwrite($fd, "Line 1\nLine 2\nLine 3");
@@ -31,10 +31,13 @@ chdir($test_dirname);
3131
var_dump(file("../$filename"));
3232
chdir($script_directory);
3333

34-
chdir($script_directory);
35-
unlink($filepath);
34+
?>
35+
--CLEAN--
36+
<?php
37+
$test_dirname = basename(__FILE__, ".clean.php") . "私はガラスを食べられますtestdir";
38+
$filepath = __DIR__ . '/file_variation_5.tmp';
3639
rmdir($test_dirname);
37-
40+
unlink($filepath);
3841
?>
3942
--EXPECT--
4043
file() on a path containing .. and .

0 commit comments

Comments
 (0)