- New tests for closedir() function

This commit is contained in:
Josie Messa 2008-03-07 16:00:24 +00:00
parent 51a57fe26e
commit 37ca3ca2b5
4 changed files with 364 additions and 0 deletions

View File

@ -0,0 +1,56 @@
--TEST--
Test closedir() function : basic functionality
--FILE--
<?php
/* Prototype : void closedir([resource $dir_handle])
* Description: Close directory connection identified by the dir_handle
* Source code: ext/standard/dir.c
* Alias to functions: close
*/
/*
* Test basic functionality of closedir()
*/
echo "*** Testing closedir() : basic functionality ***\n";
$base_dir = dirname(__FILE__);
$dir_path = $base_dir . '/closedir_basic';
mkdir($dir_path);
echo "\n-- Call closedir() with no arguments: --\n";
$dh1 = opendir($dir_path);
var_dump(closedir());
echo "-- Check Directory Handle: --\n";
var_dump($dh1);
echo "\n-- Call closedir() with \$dir_handle argument supplied: --\n";
$dh2 = opendir($dir_path);
if ((int)$dh1 === (int)$dh2) {
echo "\nNo new resource created\n";
}
var_dump(closedir($dh2));
echo "-- Check Directory Handle: --\n";
var_dump($dh2);
?>
===DONE===
--CLEAN--
<?php
$base_dir = dirname(__FILE__);
$dir_path = $base_dir . '\closedir_basic';
rmdir($dir_path);
?>
--EXPECTF--
*** Testing closedir() : basic functionality ***
-- Call closedir() with no arguments: --
NULL
-- Check Directory Handle: --
resource(%d) of type (Unknown)
-- Call closedir() with $dir_handle argument supplied: --
NULL
-- Check Directory Handle: --
resource(%d) of type (Unknown)
===DONE===

View File

@ -0,0 +1,45 @@
--TEST--
Test closedir() function : error conditions - Pass incorrect number of arguments
--FILE--
<?php
/* Prototype : void closedir([resource $dir_handle])
* Description: Close directory connection identified by the dir_handle
* Source code: ext/standard/dir.c
* Alias to functions: close
*/
/*
* Pass incorrect number of arguments to closedir() to test behaviour
*/
echo "*** Testing closedir() : error conditions ***\n";
//Test closedir with one more than the expected number of arguments
echo "\n-- Testing closedir() function with more than expected no. of arguments --\n";
$dir_path = dirname(__FILE__) . '\closedir_error';
mkdir($dir_path);
$dir_handle = opendir($dir_path);
$extra_arg = 10;
var_dump( closedir($dir_handle, $extra_arg) );
//successfully close the directory handle so can delete in CLEAN section
closedir($dir_handle);
?>
===DONE===
--CLEAN--
<?php
$base_dir = dirname(__FILE__);
$dir_path = $base_dir . '\closedir_error';
rmdir($dir_path);
?>
--EXPECTF--
*** Testing closedir() : error conditions ***
-- Testing closedir() function with more than expected no. of arguments --
Warning: Wrong parameter count for closedir() in %s on line %d
NULL
===DONE===

View File

@ -0,0 +1,212 @@
--TEST--
Test closedir() function : usage variations - different data types as $dir_handle arg
--FILE--
<?php
/* Prototype : void closedir([resource $dir_handle])
* Description: Close directory connection identified by the dir_handle
* Source code: ext/standard/dir.c
* Alias to functions: close
*/
/*
* Pass different data types as $dir_handle argument to closedir() to test behaviour
*/
echo "*** Testing closedir() : 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 closedir()
$iterator = 1;
foreach($inputs as $input) {
echo "\n-- Iteration $iterator --\n";
var_dump( closedir($input) );
$iterator++;
};
?>
===DONE===
--EXPECTF--
*** Testing closedir() : usage variations ***
-- Iteration 1 --
Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d
bool(false)
-- Iteration 2 --
Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d
bool(false)
-- Iteration 3 --
Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d
bool(false)
-- Iteration 4 --
Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d
bool(false)
-- Iteration 5 --
Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d
bool(false)
-- Iteration 6 --
Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d
bool(false)
-- Iteration 7 --
Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d
bool(false)
-- Iteration 8 --
Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d
bool(false)
-- Iteration 9 --
Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d
bool(false)
-- Iteration 10 --
Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d
bool(false)
-- Iteration 11 --
Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d
bool(false)
-- Iteration 12 --
Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d
bool(false)
-- Iteration 13 --
Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d
bool(false)
-- Iteration 14 --
Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d
bool(false)
-- Iteration 15 --
Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d
bool(false)
-- Iteration 16 --
Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d
bool(false)
-- Iteration 17 --
Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d
bool(false)
-- Iteration 18 --
Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d
bool(false)
-- Iteration 19 --
Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d
bool(false)
-- Iteration 20 --
Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d
bool(false)
-- Iteration 21 --
Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d
bool(false)
-- Iteration 22 --
Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d
bool(false)
-- Iteration 23 --
Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d
bool(false)
-- Iteration 24 --
Warning: closedir(): supplied argument is not a valid Directory resource in %s on line %d
bool(false)
===DONE===

View File

@ -0,0 +1,51 @@
--TEST--
Test closedir() function : usage variations - close directory handle twice
--FILE--
<?php
/* Prototype : void closedir([resource $dir_handle])
* Description: Close directory connection identified by the dir_handle
* Source code: ext/standard/dir.c
* Alias to functions: close
*/
/*
* close the directory handle twice using closedir() to test behaviour
*/
echo "*** Testing closedir() : usage variations ***\n";
//create temporary directory for test, removed in CLEAN section
$directory = dirname(__FILE__) . "/closedir_variation2";
mkdir($directory);
$dh = opendir($directory);
echo "\n-- Close directory handle first time: --\n";
var_dump(closedir($dh));
echo "Directory Handle: ";
var_dump($dh);
echo "\n-- Close directory handle second time: --\n";
var_dump(closedir($dh));
echo "Directory Handle: ";
var_dump($dh);
?>
===DONE===
--CLEAN--
<?php
$directory = dirname(__FILE__) . "/closedir_variation2";
rmdir($directory);
?>
--EXPECTF--
*** Testing closedir() : usage variations ***
-- Close directory handle first time: --
NULL
Directory Handle: resource(%d) of type (Unknown)
-- Close directory handle second time: --
Warning: closedir(): %d is not a valid Directory resource in %s on line %d
bool(false)
Directory Handle: resource(%d) of type (Unknown)
===DONE===