mirror of
https://github.com/php/php-src.git
synced 2024-09-24 11:27:28 +00:00
- New tests for rewinddir() function
This commit is contained in:
parent
37ca3ca2b5
commit
d19f3990e3
78
ext/standard/tests/dir/rewinddir_basic.phpt
Normal file
78
ext/standard/tests/dir/rewinddir_basic.phpt
Normal file
@ -0,0 +1,78 @@
|
||||
--TEST--
|
||||
Test rewinddir() function : basic functionality
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : void rewinddir([resource $dir_handle])
|
||||
* Description: Rewind dir_handle back to the start
|
||||
* Source code: ext/standard/dir.c
|
||||
* Alias to functions: rewind
|
||||
*/
|
||||
|
||||
/*
|
||||
* Test basic functionality of rewinddir()
|
||||
*/
|
||||
|
||||
echo "*** Testing rewinddir() : basic functionality ***\n";
|
||||
|
||||
// include file.inc for create_files function
|
||||
include(dirname(__FILE__) . "/../file/file.inc");
|
||||
|
||||
$dir_path1 = dirname(__FILE__) . "/rewinddir_basic_dir1";
|
||||
$dir_path2 = dirname(__FILE__) . "/rewinddir_basic_dir2";
|
||||
mkdir($dir_path1);
|
||||
mkdir($dir_path2);
|
||||
|
||||
@create_files($dir_path1, 1);
|
||||
@create_files($dir_path2, 1, 'numeric', 0755, 1, 'w', 'file', 2);
|
||||
var_dump($dh1 = opendir($dir_path1));
|
||||
var_dump($dh2 = opendir($dir_path2));
|
||||
|
||||
echo "\n-- Read and rewind first directory (argument supplied) --\n";
|
||||
while(FALSE !== $file1 = readdir($dh1)) {
|
||||
var_dump($file1);
|
||||
}
|
||||
|
||||
var_dump(rewinddir($dh1));
|
||||
var_dump(readdir($dh1));
|
||||
|
||||
echo "\n-- Read and rewind second directory (no argument supplied) --\n";
|
||||
while(FALSE !== $file2 = readdir()) {
|
||||
var_dump($file2);
|
||||
}
|
||||
|
||||
var_dump(rewinddir());
|
||||
var_dump(readdir());
|
||||
|
||||
closedir($dh1);
|
||||
closedir($dh2);
|
||||
|
||||
delete_files($dir_path1, 1);
|
||||
delete_files($dir_path2, 1, 'file', 2);
|
||||
?>
|
||||
===DONE===
|
||||
--CLEAN--
|
||||
<?php
|
||||
$dir_path1 = dirname(__FILE__) . "/rewinddir_basic_dir1";
|
||||
$dir_path2 = dirname(__FILE__) . "/rewinddir_basic_dir2";
|
||||
rmdir($dir_path1);
|
||||
rmdir($dir_path2);
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing rewinddir() : basic functionality ***
|
||||
resource(%d) of type (stream)
|
||||
resource(%d) of type (stream)
|
||||
|
||||
-- Read and rewind first directory (argument supplied) --
|
||||
string(1) "."
|
||||
string(2) ".."
|
||||
string(9) "file1.tmp"
|
||||
NULL
|
||||
string(1) "."
|
||||
|
||||
-- Read and rewind second directory (no argument supplied) --
|
||||
string(1) "."
|
||||
string(2) ".."
|
||||
string(9) "file2.tmp"
|
||||
NULL
|
||||
string(1) "."
|
||||
===DONE===
|
42
ext/standard/tests/dir/rewinddir_error.phpt
Normal file
42
ext/standard/tests/dir/rewinddir_error.phpt
Normal file
@ -0,0 +1,42 @@
|
||||
--TEST--
|
||||
Test rewinddir() function : error conditions - incorrect number of args
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : void rewinddir([resource $dir_handle])
|
||||
* Description: Rewind dir_handle back to the start
|
||||
* Source code: ext/standard/dir.c
|
||||
* Alias to functions: rewind
|
||||
*/
|
||||
|
||||
/*
|
||||
* Pass incorrect number of arguments to rewinddir() to test behaviour
|
||||
*/
|
||||
|
||||
echo "*** Testing rewinddir() : error conditions ***\n";
|
||||
|
||||
|
||||
//Test rewinddir with one more than the expected number of arguments
|
||||
echo "\n-- Testing rewinddir() function with more than expected no. of arguments --\n";
|
||||
|
||||
$dir_path = dirname(__FILE__) . "/rewinddir_error";
|
||||
mkdir($dir_path);
|
||||
$dir_handle = opendir($dir_path);
|
||||
$extra_arg = 10;
|
||||
|
||||
var_dump( rewinddir($dir_handle, $extra_arg) );
|
||||
closedir($dir_handle);
|
||||
?>
|
||||
===DONE===
|
||||
--CLEAN--
|
||||
<?php
|
||||
$dir_path = dirname(__FILE__) . "/rewinddir_error";
|
||||
rmdir($dir_path);
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing rewinddir() : error conditions ***
|
||||
|
||||
-- Testing rewinddir() function with more than expected no. of arguments --
|
||||
|
||||
Warning: Wrong parameter count for rewinddir() in %s on line %d
|
||||
NULL
|
||||
===DONE===
|
211
ext/standard/tests/dir/rewinddir_variation1.phpt
Normal file
211
ext/standard/tests/dir/rewinddir_variation1.phpt
Normal file
@ -0,0 +1,211 @@
|
||||
--TEST--
|
||||
Test rewinddir() function : usage variations - different data types as $dir_handle arg
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : void rewinddir([resource $dir_handle])
|
||||
* Description: Rewind dir_handle back to the start
|
||||
* Source code: ext/standard/dir.c
|
||||
* Alias to functions: rewind
|
||||
*/
|
||||
|
||||
/*
|
||||
* Pass different data types as $dir_handle argument to rewinddir() to test behaviour
|
||||
*/
|
||||
|
||||
echo "*** Testing rewinddir() : usage variations ***\n";
|
||||
|
||||
//get an unset variable
|
||||
$unset_var = 10;
|
||||
unset ($unset_var);
|
||||
|
||||
// get a class
|
||||
class classA
|
||||
{
|
||||
public function __toString() {
|
||||
return "Class A object";
|
||||
}
|
||||
}
|
||||
|
||||
// heredoc string
|
||||
$heredoc = <<<EOT
|
||||
hello world
|
||||
EOT;
|
||||
|
||||
// unexpected values to be passed to $dir_handle argument
|
||||
$inputs = array(
|
||||
|
||||
// int data
|
||||
/*1*/ 0,
|
||||
1,
|
||||
12345,
|
||||
-2345,
|
||||
|
||||
// float data
|
||||
/*5*/ 10.5,
|
||||
-10.5,
|
||||
12.3456789000e10,
|
||||
12.3456789000E-10,
|
||||
.5,
|
||||
|
||||
// null data
|
||||
/*10*/ NULL,
|
||||
null,
|
||||
|
||||
// boolean data
|
||||
/*12*/ true,
|
||||
false,
|
||||
TRUE,
|
||||
FALSE,
|
||||
|
||||
// empty data
|
||||
/*16*/ "",
|
||||
'',
|
||||
array(),
|
||||
|
||||
// string data
|
||||
/*19*/ "string",
|
||||
'string',
|
||||
$heredoc,
|
||||
|
||||
// object data
|
||||
/*22*/ new classA(),
|
||||
|
||||
// undefined data
|
||||
/*23*/ @$undefined_var,
|
||||
|
||||
// unset data
|
||||
/*24*/ @$unset_var,
|
||||
);
|
||||
|
||||
// loop through each element of $inputs to check the behavior of rewinddir()
|
||||
$iterator = 1;
|
||||
foreach($inputs as $input) {
|
||||
echo "\n-- Iteration $iterator --\n";
|
||||
var_dump( rewinddir($input) );
|
||||
$iterator++;
|
||||
};
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing rewinddir() : usage variations ***
|
||||
|
||||
-- Iteration 1 --
|
||||
|
||||
Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Iteration 2 --
|
||||
|
||||
Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Iteration 3 --
|
||||
|
||||
Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Iteration 4 --
|
||||
|
||||
Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Iteration 5 --
|
||||
|
||||
Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Iteration 6 --
|
||||
|
||||
Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Iteration 7 --
|
||||
|
||||
Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Iteration 8 --
|
||||
|
||||
Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Iteration 9 --
|
||||
|
||||
Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Iteration 10 --
|
||||
|
||||
Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Iteration 11 --
|
||||
|
||||
Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Iteration 12 --
|
||||
|
||||
Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Iteration 13 --
|
||||
|
||||
Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Iteration 14 --
|
||||
|
||||
Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Iteration 15 --
|
||||
|
||||
Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Iteration 16 --
|
||||
|
||||
Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Iteration 17 --
|
||||
|
||||
Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Iteration 18 --
|
||||
|
||||
Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Iteration 19 --
|
||||
|
||||
Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Iteration 20 --
|
||||
|
||||
Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Iteration 21 --
|
||||
|
||||
Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Iteration 22 --
|
||||
|
||||
Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Iteration 23 --
|
||||
|
||||
Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Iteration 24 --
|
||||
|
||||
Warning: rewinddir(): supplied argument is not a valid Directory resource in %s on line %d
|
||||
bool(false)
|
||||
===DONE===
|
45
ext/standard/tests/dir/rewinddir_variation2.phpt
Normal file
45
ext/standard/tests/dir/rewinddir_variation2.phpt
Normal file
@ -0,0 +1,45 @@
|
||||
--TEST--
|
||||
Test rewinddir() function : usage variations - operate on a closed directory
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : void rewinddir([resource $dir_handle])
|
||||
* Description: Rewind dir_handle back to the start
|
||||
* Source code: ext/standard/dir.c
|
||||
* Alias to functions: rewind
|
||||
*/
|
||||
|
||||
/*
|
||||
* Open and close a directory handle then call rewinddir() to test behaviour
|
||||
*/
|
||||
|
||||
echo "*** Testing rewinddir() : usage variations ***\n";
|
||||
|
||||
$dir_path = dirname(__FILE__) . '/rewinddir_variation2';
|
||||
mkdir($dir_path);
|
||||
|
||||
echo "\n-- Create the directory handle, read and close the directory --\n";
|
||||
var_dump($dir_handle = opendir($dir_path));
|
||||
var_dump(readdir($dir_handle));
|
||||
closedir($dir_handle);
|
||||
|
||||
echo "\n-- Call to rewinddir() --\n";
|
||||
var_dump(rewinddir($dir_handle));
|
||||
?>
|
||||
===DONE===
|
||||
--CLEAN--
|
||||
<?php
|
||||
$dir_path = dirname(__FILE__) . '/rewinddir_variation2';
|
||||
rmdir($dir_path);
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing rewinddir() : usage variations ***
|
||||
|
||||
-- Create the directory handle, read and close the directory --
|
||||
resource(%d) of type (stream)
|
||||
string(1) "."
|
||||
|
||||
-- Call to rewinddir() --
|
||||
|
||||
Warning: rewinddir(): %d is not a valid Directory resource in %s on line %d
|
||||
bool(false)
|
||||
===DONE===
|
Loading…
Reference in New Issue
Block a user