folderweb/devel/tests/helpers/get_subdirectories.phpt

40 lines
819 B
Text
Raw Permalink Normal View History

--TEST--
getSubdirectories: returns only subdirectory names, ignores files
--FILE--
<?php
require '/var/www/app/helpers.php';
$dir = sys_get_temp_dir() . '/phpt_subdirs_' . getmypid();
mkdir($dir);
// Empty directory
$result = getSubdirectories($dir);
echo (empty($result) ? 'empty' : 'not empty') . "\n";
// Non-existent directory
echo count(getSubdirectories($dir . '/nope')) . "\n";
// Add subdirectories and a file
mkdir("$dir/alpha");
mkdir("$dir/beta");
touch("$dir/file.txt");
$result = array_values(getSubdirectories($dir));
sort($result);
echo implode("\n", $result) . "\n";
// Files are not included
echo in_array('file.txt', $result) ? "file included\n" : "file excluded\n";
unlink("$dir/file.txt");
rmdir("$dir/alpha");
rmdir("$dir/beta");
rmdir($dir);
?>
--EXPECT--
empty
0
alpha
beta
file excluded