"Fossies" - the Fresh Open Source Software Archive

Member "php-7.2.27/ext/standard/tests/file/001.phpt" (22 Jan 2020, 3666 Bytes) of package /linux/www/php-7.2.27.tar.xz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "001.phpt": 7.3.12_vs_7.4.0.

    1 --TEST--
    2 File type functions
    3 --SKIPIF--
    4 <?php
    5 if (substr(PHP_OS, 0, 3) == 'WIN') {
    6     die('skip no symlinks on Windows');
    7 }
    8 if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
    9 ?>
   10 --FILE--
   11 <?php
   12 chdir(dirname(__FILE__));
   13 @unlink('test.file');
   14 @unlink('test.link');
   15 if (file_exists('test.file')) {
   16     echo "test.file exists\n";
   17 } else {
   18     echo "test.file does not exist\n";
   19 }
   20 fclose (fopen('test.file', 'w'));
   21 chmod ('test.file', 0744);
   22 if (file_exists('test.file')) {
   23     echo "test.file exists\n";
   24 } else {
   25     echo "test.file does not exist\n";
   26 }
   27 sleep (2);
   28 symlink('test.file','test.link');
   29 if (file_exists('test.link')) {
   30     echo "test.link exists\n";
   31 } else {
   32     echo "test.link does not exist\n";
   33 }
   34 if (is_link('test.file')) {
   35     echo "test.file is a symlink\n";
   36 } else {
   37     echo "test.file is not a symlink\n";
   38 }
   39 if (is_link('test.link')) {
   40     echo "test.link is a symlink\n";
   41 } else {
   42     echo "test.link is not a symlink\n";
   43 }
   44 if (file_exists('test.file')) {
   45     echo "test.file exists\n";
   46 } else {
   47     echo "test.file does not exist\n";
   48 }
   49 $s = stat ('test.file');
   50 $ls = lstat ('test.file');
   51 for ($i = 0; $i <= 12; $i++) {
   52     if ($ls[$i] != $s[$i]) {
   53 	echo "test.file lstat and stat differ at element $i\n";
   54     }
   55 }
   56 $s = stat ('test.link');
   57 $ls = lstat ('test.link');
   58 for ($i = 0; $i <= 11; $i++) {
   59     if ($ls[$i] != $s[$i]) {
   60 	if ($i != 6 && $i != 10 && $i != 11) echo "test.link lstat and stat differ at element $i\n";
   61     }
   62 }
   63 echo "test.file is " . filetype('test.file') . "\n";
   64 echo "test.link is " . filetype('test.link') . "\n";
   65 printf ("test.file permissions are 0%o\n", 0777 & fileperms('test.file'));
   66 echo "test.file size is " . filesize('test.file') . "\n";
   67 if (is_writeable('test.file')) {
   68     echo "test.file is writeable\n";
   69 } else {
   70     echo "test.file is not writeable\n";
   71 }
   72 if (is_readable('test.file')) {
   73     echo "test.file is readable\n";
   74 } else {
   75     echo "test.file is not readable\n";
   76 }
   77 if (is_executable('test.file')) {
   78     echo "test.file is executable\n";
   79 } else {
   80     echo "test.file is not executable\n";
   81 }
   82 if (is_file('test.file')) {
   83     echo "test.file is a regular file\n";
   84 } else {
   85     echo "test.file is not a regular file\n";
   86 }
   87 if (is_file('test.link')) {
   88     echo "test.link is a regular file\n";
   89 } else {
   90     echo "test.link is not a regular file\n";
   91 }
   92 if (is_dir('test.link')) {
   93     echo "test.link is a directory\n";
   94 } else {
   95     echo "test.link is not a directory\n";
   96 }
   97 if (is_dir('../file')) {
   98     echo "../file is a directory\n";
   99 } else {
  100     echo "../file is not a directory\n";
  101 }
  102 if (is_dir('test.file')) {
  103     echo "test.file is a directory\n";
  104 } else {
  105     echo "test.file is not a directory\n";
  106 }
  107 unlink('test.file');
  108 unlink('test.link');
  109 if (file_exists('test.file')) {
  110     echo "test.file exists (cached)\n";
  111 } else {
  112     echo "test.file does not exist\n";
  113 }
  114 clearstatcache();
  115 if (file_exists('test.file')) {
  116     echo "test.file exists\n";
  117 } else {
  118     echo "test.file does not exist\n";
  119 }
  120 ?>
  121 --EXPECT--
  122 test.file does not exist
  123 test.file exists
  124 test.link exists
  125 test.file is not a symlink
  126 test.link is a symlink
  127 test.file exists
  128 test.link lstat and stat differ at element 1
  129 test.link lstat and stat differ at element 2
  130 test.link lstat and stat differ at element 7
  131 test.link lstat and stat differ at element 8
  132 test.link lstat and stat differ at element 9
  133 test.file is file
  134 test.link is link
  135 test.file permissions are 0744
  136 test.file size is 0
  137 test.file is writeable
  138 test.file is readable
  139 test.file is executable
  140 test.file is a regular file
  141 test.link is a regular file
  142 test.link is not a directory
  143 ../file is a directory
  144 test.file is not a directory
  145 test.file does not exist
  146 test.file does not exist