summaryrefslogtreecommitdiff
path: root/ext/standard/tests/file/is_file_variation1.phpt
blob: 8f09e93aa6a03e8ff043a200b149a9689f260e2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
--TEST--
Test is_file() function: usage variations - diff. files
--FILE--
<?php
/* Prototype: bool is_file ( string $filename );
   Description: Tells whether the filename is a regular file
     Returns TRUE if the filename exists and is a regular file
*/

/* Testing is_file() with file containing data, truncating its size
     and the file created by touch() */

$file_path = dirname(__FILE__);

echo "-- Testing is_file() with file containing data --\n";
$filename = $file_path."/is_file_variation1.tmp";
$file_handle = fopen($filename, "w" );
fwrite( $file_handle, "Hello, world....." ); // exptected true
fclose($file_handle);
var_dump( is_file($filename) );
clearstatcache();

echo "\n-- Testing is_file() after truncating filesize to zero bytes --\n";
$file_handle = fopen( $file_path."/is_file_variation1.tmp", "r");
ftruncate($file_handle, 0);
fclose($file_handle);
var_dump( is_file($file_path."/is_file_variation1.tmp") ); // expected true
clearstatcache();
unlink($file_path."/is_file_variation1.tmp");

echo "\n-- Testing is_file() with an empty file --\n";
/* created by fopen() */
fclose( fopen($file_path."/is_file_variation1.tmp", "w") );
var_dump( is_file($file_path."/is_file_variation1.tmp") );  //expected true
clearstatcache();
unlink($file_path."/is_file_variation1.tmp");

/* created by touch() */
touch($file_path."/is_file_variation1.tmp");
var_dump( is_file($file_path."/is_file_variation1.tmp") ); // expected true
clearstatcache();
unlink($file_path."/is_file_variation1.tmp");

echo "\n*** Done ***";
?>
--EXPECTF--
-- Testing is_file() with file containing data --
bool(true)

-- Testing is_file() after truncating filesize to zero bytes --
bool(true)

-- Testing is_file() with an empty file --
bool(true)
bool(true)

*** Done ***