Skip to content

Commit bab7b04

Browse files
committed
ext/standard/tests/file: Fix most tests and remove ZPP tests
1 parent 4e6031b commit bab7b04

32 files changed

+131
-801
lines changed

ext/standard/tests/file/005_variation2.phpt

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,15 @@ $dir = __DIR__ . '/005_variation2';
3333
mkdir($dir);
3434
chdir($dir);
3535

36-
$b = touch(false);
3736
$c = touch('');
3837
$d = touch(' ');
3938
$e = touch('|');
4039

41-
var_dump($a);
42-
var_dump($b);
4340
var_dump($c);
4441
var_dump($d);
4542
var_dump($e);
4643

4744
echo "\n*** testing file info ***";
48-
stat_fn(false);
4945
stat_fn('');
5046
stat_fn(' ');
5147
stat_fn('|');
@@ -60,10 +56,6 @@ echo "Done";
6056
*** Testing fileattime(), filemtime(), filectime() & touch() : usage variations ***
6157

6258
*** testing touch ***
63-
64-
Warning: Undefined variable $a in %s on line %d
65-
NULL
66-
bool(false)
6759
bool(false)
6860
bool(true)
6961
bool(true)
@@ -74,11 +66,6 @@ bool(true)
7466
-- File modification time is =>
7567
-- inode change time is =>
7668

77-
-- File '' --
78-
-- File access time is =>
79-
-- File modification time is =>
80-
-- inode change time is =>
81-
8269
-- File ' ' --
8370
-- File access time is => %d
8471
-- File modification time is => %d

ext/standard/tests/file/file_exists_variation1.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ Dave Kelsey <[email protected]>
66
<?php
77
echo "*** Testing file_exists() : usage variations ***\n";
88

9-
var_dump(file_exists(false));
109
var_dump(file_exists(''));
1110
var_dump(file_exists(' '));
1211
var_dump(file_exists('|'));
@@ -17,5 +16,4 @@ echo "Done";
1716
bool(false)
1817
bool(false)
1918
bool(false)
20-
bool(false)
2119
Done

ext/standard/tests/file/file_get_contents_file_put_contents_variation1.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ $buffer_types = array("text", "numeric", "text_with_new_line", "alphanumeric");
1515
foreach( $buffer_types as $type) {
1616
fill_buffer($buffer, $type, 100);
1717
file_put_contents( $file_path."/file_put_contents_variation1.tmp", $buffer);
18-
var_dump( file_get_contents($file_path."/file_put_contents_variation1.tmp", 0) );
19-
var_dump( file_get_contents($file_path."/file_put_contents_variation1.tmp", 1) );
20-
var_dump( file_get_contents($file_path."/file_put_contents_variation1.tmp", 0, NULL, 5) );
21-
var_dump( file_get_contents($file_path."/file_put_contents_variation1.tmp", 1, NULL, 5) );
22-
var_dump( file_get_contents($file_path."/file_put_contents_variation1.tmp", 0, NULL, 5, 20) );
23-
var_dump( file_get_contents($file_path."/file_put_contents_variation1.tmp", 1, NULL, 5, 20) );
18+
var_dump( file_get_contents($file_path."/file_put_contents_variation1.tmp", false) );
19+
var_dump( file_get_contents($file_path."/file_put_contents_variation1.tmp", true) );
20+
var_dump( file_get_contents($file_path."/file_put_contents_variation1.tmp", false, NULL, 5) );
21+
var_dump( file_get_contents($file_path."/file_put_contents_variation1.tmp", true, NULL, 5) );
22+
var_dump( file_get_contents($file_path."/file_put_contents_variation1.tmp", false, NULL, 5, 20) );
23+
var_dump( file_get_contents($file_path."/file_put_contents_variation1.tmp", true, NULL, 5, 20) );
2424

2525
}
2626

ext/standard/tests/file/file_get_contents_file_put_contents_variation2.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ file_put_contents( $filename, $buffer );
2020
fill_buffer( $buffer, "numeric", 100);
2121
file_put_contents( $filename, $buffer, FILE_APPEND, NULL );
2222
file_put_contents( $filename, $data_array, FILE_APPEND, NULL );
23-
var_dump( file_get_contents($filename, 0) );
24-
var_dump( file_get_contents($filename, 1) );
25-
var_dump( file_get_contents($filename, 0, NULL, 5) );
26-
var_dump( file_get_contents($filename, 1, NULL, 5) );
27-
var_dump( file_get_contents($filename, 0, NULL, 5, 20) );
28-
var_dump( file_get_contents($filename, 1, NULL, 5, 20) );
23+
var_dump( file_get_contents($filename, false) );
24+
var_dump( file_get_contents($filename, true) );
25+
var_dump( file_get_contents($filename, false, NULL, 5) );
26+
var_dump( file_get_contents($filename, true, NULL, 5) );
27+
var_dump( file_get_contents($filename, false, NULL, 5, 20) );
28+
var_dump( file_get_contents($filename, true, NULL, 5, 20) );
2929

3030
echo "--- Done ---";
3131
?>

ext/standard/tests/file/file_get_contents_variation8.phpt

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,60 +14,40 @@ obscure_filename
1414
<?php
1515
echo "*** Testing file_get_contents() : variation ***\n";
1616
/* An array of filenames */
17-
$names_arr = array(
17+
$names = [
1818
/* Invalid args */
19-
-1,
20-
TRUE,
21-
FALSE,
19+
'-1',
2220
"",
2321
" ",
2422
"\0",
25-
array(),
26-
2723
/* prefix with path separator of a non existing directory*/
2824
"/no/such/file/dir",
29-
"php/php"
30-
31-
);
25+
"php/php",
26+
];
3227

33-
for( $i=0; $i<count($names_arr); $i++ ) {
34-
echo "-- Iteration $i --\n";
28+
foreach ($names as $name) {
3529
try {
36-
var_dump(file_get_contents($names_arr[$i]));
37-
} catch (\TypeError|\ValueError $e) {
38-
echo get_class($e) . ': ' . $e->getMessage(), "\n";
30+
var_dump(file_get_contents($name));
31+
} catch (\Throwable $e) {
32+
echo $e::class, ': ', $e->getMessage(), "\n";
3933
}
4034
}
4135

4236
echo "\n*** Done ***\n";
4337
?>
4438
--EXPECTF--
4539
*** Testing file_get_contents() : variation ***
46-
-- Iteration 0 --
4740

4841
Warning: file_get_contents(-1): Failed to open stream: No such file or directory in %s on line %d
4942
bool(false)
50-
-- Iteration 1 --
51-
52-
Warning: file_get_contents(1): Failed to open stream: No such file or directory in %s on line %d
53-
bool(false)
54-
-- Iteration 2 --
55-
ValueError: Path must not be empty
56-
-- Iteration 3 --
5743
ValueError: Path must not be empty
58-
-- Iteration 4 --
5944

6045
Warning: file_get_contents( ): Failed to open stream: No such file or directory in %s on line %d
6146
bool(false)
62-
-- Iteration 5 --
6347
ValueError: file_get_contents(): Argument #1 ($filename) must not contain any null bytes
64-
-- Iteration 6 --
65-
TypeError: file_get_contents(): Argument #1 ($filename) must be of type string, array given
66-
-- Iteration 7 --
6748

6849
Warning: file_get_contents(/no/such/file/dir): Failed to open stream: No such file or directory in %s on line %d
6950
bool(false)
70-
-- Iteration 8 --
7151

7252
Warning: file_get_contents(php/php): Failed to open stream: No such file or directory in %s on line %d
7353
bool(false)

ext/standard/tests/file/file_put_contents_variation8.phpt

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,28 @@ mkdir($dir);
1818
chdir($dir);
1919

2020
/* An array of filenames */
21-
$names_arr = array(
22-
-1,
23-
TRUE,
24-
FALSE,
21+
$names = [
22+
/* Invalid args */
23+
'-1',
2524
"",
2625
" ",
27-
//this one also generates a java message rather than our own so we don't replicate php message
2826
"\0",
29-
array(),
30-
31-
//the next 2 generate java messages so we don't replicate the php messages
27+
/* prefix with path separator of a non existing directory*/
3228
"/no/such/file/dir",
33-
"php/php"
34-
35-
);
29+
"php/php",
30+
];
3631

37-
for( $i=0; $i<count($names_arr); $i++ ) {
38-
echo "-- Iteration $i --\n";
32+
foreach ($names as $name) {
3933
try {
40-
$res = file_put_contents($names_arr[$i], "Some data");
34+
$res = file_put_contents($name, "Some data");
4135
if ($res !== false && $res != null) {
42-
echo "$res bytes written to: '$names_arr[$i]'\n";
43-
unlink($names_arr[$i]);
36+
echo "$res bytes written to: '$name'\n";
37+
unlink($name);
4438
} else {
45-
echo "Failed to write data to: '$names_arr[$i]'\n";
39+
echo "Failed to write data to: '$name'\n";
4640
}
47-
} catch (\TypeError|\ValueError $e) {
48-
echo get_class($e) . ': ' . $e->getMessage(), "\n";
41+
} catch (\Throwable $e) {
42+
echo $e::class, ': ', $e->getMessage(), "\n";
4943
}
5044
}
5145

@@ -59,25 +53,13 @@ rmdir($dir);
5953
?>
6054
--EXPECTF--
6155
*** Testing file_put_contents() : usage variation ***
62-
-- Iteration 0 --
6356
9 bytes written to: '-1'
64-
-- Iteration 1 --
65-
9 bytes written to: '1'
66-
-- Iteration 2 --
67-
ValueError: Path must not be empty
68-
-- Iteration 3 --
6957
ValueError: Path must not be empty
70-
-- Iteration 4 --
7158
9 bytes written to: ' '
72-
-- Iteration 5 --
7359
ValueError: file_put_contents(): Argument #1 ($filename) must not contain any null bytes
74-
-- Iteration 6 --
75-
TypeError: file_put_contents(): Argument #1 ($filename) must be of type string, array given
76-
-- Iteration 7 --
7760

7861
Warning: file_put_contents(%sdir): Failed to open stream: %s in %s on line %d
7962
Failed to write data to: '%sir'
80-
-- Iteration 8 --
8163

8264
Warning: file_put_contents(%sphp): Failed to open stream: %s in %s on line %d
8365
Failed to write data to: '%sphp'

ext/standard/tests/file/filegroup_variation2.phpt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,16 @@ obscure_filename
1111
$file_path = __DIR__;
1212

1313
echo "*** Testing Invalid file types ***\n";
14-
$filenames = array(
14+
$filenames = [
1515
/* Invalid filenames */
1616
-2.34555,
1717
" ",
1818
"",
19-
TRUE,
20-
FALSE,
21-
2219
/* scalars */
2320
1234,
24-
0
25-
);
21+
0,
22+
1,
23+
];
2624

2725
/* loop through to test each element the above array */
2826
foreach( $filenames as $filename ) {
@@ -40,12 +38,11 @@ Warning: filegroup(): stat failed for in %s on line %d
4038
bool(false)
4139
bool(false)
4240

43-
Warning: filegroup(): stat failed for 1 in %s on line %d
44-
bool(false)
45-
bool(false)
46-
4741
Warning: filegroup(): stat failed for 1234 in %s on line %d
4842
bool(false)
4943

5044
Warning: filegroup(): stat failed for 0 in %s on line %d
5145
bool(false)
46+
47+
Warning: filegroup(): stat failed for 1 in %s on line %d
48+
bool(false)

ext/standard/tests/file/fileinode_variation2.phpt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,16 @@ obscure_filename
1111
$file_path = __DIR__;
1212

1313
echo "*** Testing Invalid file types ***\n";
14-
$filenames = array(
14+
$filenames = [
1515
/* Invalid filenames */
1616
-2.34555,
1717
" ",
1818
"",
19-
TRUE,
20-
FALSE,
21-
2219
/* scalars */
2320
1234,
24-
0
25-
);
21+
0,
22+
1,
23+
];
2624

2725
/* loop through to test each element the above array */
2826
foreach( $filenames as $filename ) {
@@ -40,12 +38,11 @@ Warning: fileinode(): stat failed for in %s on line %d
4038
bool(false)
4139
bool(false)
4240

43-
Warning: fileinode(): stat failed for 1 in %s on line %d
44-
bool(false)
45-
bool(false)
46-
4741
Warning: fileinode(): stat failed for 1234 in %s on line %d
4842
bool(false)
4943

5044
Warning: fileinode(): stat failed for 0 in %s on line %d
5145
bool(false)
46+
47+
Warning: fileinode(): stat failed for 1 in %s on line %d
48+
bool(false)

ext/standard/tests/file/fileowner_variation2.phpt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,16 @@ obscure_filename
1212
$file_path = __DIR__;
1313

1414
echo "*** Testing Invalid file types ***\n";
15-
$filenames = array(
15+
$filenames = [
1616
/* Invalid filenames */
1717
-2.34555,
1818
" ",
1919
"",
20-
TRUE,
21-
FALSE,
22-
2320
/* scalars */
2421
1234,
25-
0
26-
);
22+
0,
23+
1,
24+
];
2725

2826
/* loop through to test each element the above array */
2927
foreach( $filenames as $filename ) {
@@ -41,12 +39,11 @@ Warning: fileowner(): stat failed for in %s on line %d
4139
bool(false)
4240
bool(false)
4341

44-
Warning: fileowner(): stat failed for 1 in %s on line %d
45-
bool(false)
46-
bool(false)
47-
4842
Warning: fileowner(): stat failed for 1234 in %s on line %d
4943
bool(false)
5044

5145
Warning: fileowner(): stat failed for 0 in %s on line %d
5246
bool(false)
47+
48+
Warning: fileowner(): stat failed for 1 in %s on line %d
49+
bool(false)

ext/standard/tests/file/fileperms_variation2.phpt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,16 @@ obscure_filename
1111
$file_path = __DIR__;
1212

1313
echo "*** Testing Invalid file types ***\n";
14-
$filenames = array(
14+
$filenames = [
1515
/* Invalid filenames */
1616
-2.34555,
1717
" ",
1818
"",
19-
TRUE,
20-
FALSE,
21-
2219
/* scalars */
2320
1234,
24-
0
25-
);
21+
0,
22+
1,
23+
];
2624

2725
/* loop through to test each element the above array */
2826
foreach( $filenames as $filename ) {
@@ -40,12 +38,11 @@ Warning: fileperms(): stat failed for in %s on line %d
4038
bool(false)
4139
bool(false)
4240

43-
Warning: fileperms(): stat failed for 1 in %s on line %d
44-
bool(false)
45-
bool(false)
46-
4741
Warning: fileperms(): stat failed for 1234 in %s on line %d
4842
bool(false)
4943

5044
Warning: fileperms(): stat failed for 0 in %s on line %d
5145
bool(false)
46+
47+
Warning: fileperms(): stat failed for 1 in %s on line %d
48+
bool(false)

0 commit comments

Comments
 (0)