diff options
author | Raghubansh Kumar <kraghuba@php.net> | 2007-08-12 05:14:13 +0000 |
---|---|---|
committer | Raghubansh Kumar <kraghuba@php.net> | 2007-08-12 05:14:13 +0000 |
commit | c7d2d62a02c6f0d47c31f72f36ceb24eed6817af (patch) | |
tree | 4d2a012e153a848568ea747894dbc9dcf7e2f9d1 /ext | |
parent | 424d842729b202c81b0e0a28f9b8cc588a8538c8 (diff) | |
download | php-git-c7d2d62a02c6f0d47c31f72f36ceb24eed6817af.tar.gz |
More new testcases for fopen() & fclose() functions
Diffstat (limited to 'ext')
27 files changed, 2147 insertions, 0 deletions
diff --git a/ext/standard/tests/file/007_variation1.phpt b/ext/standard/tests/file/007_variation1.phpt new file mode 100644 index 0000000000..6796994bbd --- /dev/null +++ b/ext/standard/tests/file/007_variation1.phpt @@ -0,0 +1,68 @@ +--TEST-- +Test fopen and fclose() functions - usage variations - "r" mode +--FILE-- +<?php +/* + fopen() function: + Prototype: resource fopen(string $filename, string $mode + [, bool $use_include_path [, resource $context]] ); + Description: Opens file or URL. +*/ +/* + fclose() function: + Prototype: bool fclose ( resource $handle ); + Description: Closes an open file pointer +*/ + +/* Test fopen() and fclose(): Opening the file in "r" mode, + checking for the file creation, write & read operations, + checking for the file pointer position, + and fclose function +*/ +$file_path = dirname(__FILE__); +require($file_path."/file.inc"); + +create_files($file_path, 1, "text_with_new_line", 0755, 20, "w", "007_variation", 1, "bytes"); +$file = $file_path."/007_variation1.tmp"; +$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; + +echo "*** Test fopen() & fclose() functions: with 'r' mode ***\n"; +$file_handle = fopen($file, "r"); //opening the file in "r" mode +var_dump($file_handle); //Check for the content of handle +var_dump( get_resource_type($file_handle) ); //Check for the type of resource +var_dump( ftell($file_handle) ); //Initial position of file pointer +var_dump( fread($file_handle, 100) ); //Check for read operation +var_dump( fwrite($file_handle, $string) ); //Check for write operation; fails; expected: 0 bytes +var_dump( fclose($file_handle) ); //Check for close operation on the file handle +var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation +echo "*** Done ***\n"; +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/007_variation1.tmp"); +?> +--EXPECTF-- +*** Test fopen() & fclose() functions: with 'r' mode *** +resource(8) of type (stream) +string(6) "stream" +int(0) +string(20) "line +line of text +li" +int(0) +bool(true) +string(7) "Unknown" +*** Done *** +--UEXPECTF-- +*** Test fopen() & fclose() functions: with 'r' mode *** +resource(8) of type (stream) +unicode(6) "stream" +int(0) +string(20) "line +line of text +li" + +Notice: fwrite(): 37 character unicode buffer downcoded for binary stream runtime_encoding in %s on line %d +int(0) +bool(true) +unicode(7) "Unknown" +*** Done *** diff --git a/ext/standard/tests/file/007_variation10.phpt b/ext/standard/tests/file/007_variation10.phpt new file mode 100644 index 0000000000..22b132e3ba --- /dev/null +++ b/ext/standard/tests/file/007_variation10.phpt @@ -0,0 +1,72 @@ +--TEST-- +Test fopen and fclose() functions - usage variations - "r+t" mode +--FILE-- +<?php +/* + fopen() function: + Prototype: resource fopen(string $filename, string $mode + [, bool $use_include_path [, resource $context]] ); + Description: Opens file or URL. +*/ +/* + fclose() function: + Prototype: bool fclose ( resource $handle ); + Description: Closes an open file pointer +*/ + +/* Test fopen() and fclose(): Opening the file in "r+t" mode, + checking for the file creation, write & read operations, + checking for the file pointer position, + and fclose function +*/ +$file_path = dirname(__FILE__); +require($file_path."/file.inc"); + +create_files($file_path, 1, "text_with_new_line", 0755, 20, "w", "007_variation", 10, "bytes"); +$file = $file_path."/007_variation10.tmp"; +$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; + +echo "*** Test fopen() & fclose() functions: with 'r+t' mode ***\n"; +$file_handle = fopen($file, "r+t"); //opening the file in "r+t" mode +var_dump($file_handle); //Check for the content of handle +var_dump( get_resource_type($file_handle) ); //Check for the type of resource +var_dump( ftell($file_handle) ); //Initial file pointer position, expected at the begining of the file +var_dump( fread($file_handle, 100) ); //Check for read operation +var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the end of the file +var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string +var_dump( ftell($file_handle) ); //File pointer position after write operation, expected at the end of the file +var_dump( fclose($file_handle) ); //Check for close operation on the file handle +var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation +echo "*** Done ***\n"; +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/007_variation10.tmp"); +?> +--EXPECTF-- +*** Test fopen() & fclose() functions: with 'r+t' mode *** +resource(8) of type (stream) +string(6) "stream" +int(0) +string(20) "line +line of text +li" +int(20) +int(37) +int(57) +bool(true) +string(7) "Unknown" +*** Done *** +--UEXPECTF-- +*** Test fopen() & fclose() functions: with 'r+t' mode *** +resource(8) of type (stream) +unicode(6) "stream" +int(0) +unicode(20) "line +line of text +li" +int(20) +int(37) +int(57) +bool(true) +unicode(7) "Unknown" +*** Done ***
\ No newline at end of file diff --git a/ext/standard/tests/file/007_variation11-win32.phpt b/ext/standard/tests/file/007_variation11-win32.phpt new file mode 100644 index 0000000000..6e56760f5c --- /dev/null +++ b/ext/standard/tests/file/007_variation11-win32.phpt @@ -0,0 +1,91 @@ +--TEST-- +Test fopen and fclose() functions - usage variations - "wt" mode +--SKIPIF-- +<?php +if( substr(PHP_OS, 0, 3) != "WIN" ) + die('skip Run only on Windows'); +?> +--FILE-- +<?php +/* + fopen() function: + Prototype: resource fopen(string $filename, string $mode + [, bool $use_include_path [, resource $context]] ); + Description: Opens file or URL. +*/ +/* + fclose() function: + Prototype: bool fclose ( resource $handle ); + Description: Closes an open file pointer +*/ + +/* Test fopen() and fclose(): Opening the file in "wt" mode, + checking for the file creation, write & read operations, + checking for the file pointer position, + checking for the file truncation when trying to open an existing file in "wt" mode, + and fclose function +*/ +$file_path = dirname(__FILE__); +require($file_path."/file.inc"); + +create_files($file_path, 1, "text_with_new_line", 0755, 20, "wt", "007_variation", 11, "bytes"); +$file = $file_path."/007_variation11.tmp"; +$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; + +echo "*** Test fopen() & fclose() functions: with 'wt' mode ***\n"; +$file_handle = fopen($file, "wt"); //opening the file "wt" mode +var_dump($file_handle); //Check for the content of handle +var_dump( get_resource_type($file_handle) ); //Check for the type of resource +var_dump( ftell($file_handle) ); //Initial file pointer position, expected at the begining of the file +var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string +var_dump( ftell($file_handle) ); //File pointer position after write operation, expected at the end of the file +rewind($file_handle); +var_dump( fread($file_handle, 100) ); //Check for read operation; fails; expected: empty string +var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the begining of the file +var_dump( fclose($file_handle) ); //Check for close operation on the file handle +var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation + +var_dump( filesize($file) ); //Check for size of existing data file before opening the file in "wt" mode again, expected: size of content +clearstatcache(); +fclose( fopen($file, "wt") ); //Opening the existing data file again in "wt" mode +var_dump( filesize($file) ); //Check for size of existing data file after opening the file in "wt" mode again, expected: 0 bytes +clearstatcache(); + +unlink($file); //Deleting the file +fclose( fopen($file, "wt") ); //Opening the non-existing file in "wt" mode, which will be created +var_dump( file_exists($file) ); //Check for the existance of file +echo "*** Done ***\n"; +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/007_variation11.tmp"); +?> +--EXPECTF-- +*** Test fopen() & fclose() functions: with 'wt' mode *** +resource(8) of type (stream) +string(6) "stream" +int(0) +int(37) +int(37) +bool(false) +int(0) +bool(true) +string(7) "Unknown" +int(39) +int(0) +bool(true) +*** Done *** +--UEXPECTF-- +*** Test fopen() & fclose() functions: with 'wt' mode *** +resource(8) of type (stream) +unicode(6) "stream" +int(0) +int(37) +int(37) +bool(false) +int(0) +bool(true) +unicode(7) "Unknown" +int(39) +int(0) +bool(true) +*** Done *** diff --git a/ext/standard/tests/file/007_variation11.phpt b/ext/standard/tests/file/007_variation11.phpt new file mode 100644 index 0000000000..e6be30e95c --- /dev/null +++ b/ext/standard/tests/file/007_variation11.phpt @@ -0,0 +1,91 @@ +--TEST-- +Test fopen and fclose() functions - usage variations - "wt" mode +--SKIPIF-- +<?php +if( substr(PHP_OS, 0, 3) == "WIN" ) + die('skip Do not run on Windows'); +?> +--FILE-- +<?php +/* + fopen() function: + Prototype: resource fopen(string $filename, string $mode + [, bool $use_include_path [, resource $context]] ); + Description: Opens file or URL. +*/ +/* + fclose() function: + Prototype: bool fclose ( resource $handle ); + Description: Closes an open file pointer +*/ + +/* Test fopen() and fclose(): Opening the file in "wt" mode, + checking for the file creation, write & read operations, + checking for the file pointer position, + checking for the file truncation when trying to open an existing file in "wt" mode, + and fclose function +*/ +$file_path = dirname(__FILE__); +require($file_path."/file.inc"); + +create_files($file_path, 1, "text_with_new_line", 0755, 20, "wt", "007_variation", 11, "bytes"); +$file = $file_path."/007_variation11.tmp"; +$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; + +echo "*** Test fopen() & fclose() functions: with 'wt' mode ***\n"; +$file_handle = fopen($file, "wt"); //opening the file "wt" mode +var_dump($file_handle); //Check for the content of handle +var_dump( get_resource_type($file_handle) ); //Check for the type of resource +var_dump( ftell($file_handle) ); //Initial file pointer position, expected at the begining of the file +var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string +var_dump( ftell($file_handle) ); //File pointer position after write operation, expected at the end of the file +rewind($file_handle); +var_dump( fread($file_handle, 100) ); //Check for read operation; fails; expected: empty string +var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the begining of the file +var_dump( fclose($file_handle) ); //Check for close operation on the file handle +var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation + +var_dump( filesize($file) ); //Check for size of existing data file before opening the file in "wt" mode again, expected: size of content +clearstatcache(); +fclose( fopen($file, "wt") ); //Opening the existing data file again in "wt" mode +var_dump( filesize($file) ); //Check for size of existing data file after opening the file in "wt" mode again, expected: 0 bytes +clearstatcache(); + +unlink($file); //Deleting the file +fclose( fopen($file, "wt") ); //Opening the non-existing file in "wt" mode, which will be created +var_dump( file_exists($file) ); //Check for the existance of file +echo "*** Done ***\n"; +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/007_variation11.tmp"); +?> +--EXPECTF-- +*** Test fopen() & fclose() functions: with 'wt' mode *** +resource(8) of type (stream) +string(6) "stream" +int(0) +int(37) +int(37) +bool(false) +int(0) +bool(true) +string(7) "Unknown" +int(37) +int(0) +bool(true) +*** Done *** +--UEXPECTF-- +*** Test fopen() & fclose() functions: with 'wt' mode *** +resource(8) of type (stream) +unicode(6) "stream" +int(0) +int(37) +int(37) +bool(false) +int(0) +bool(true) +unicode(7) "Unknown" +int(37) +int(0) +bool(true) +*** Done *** diff --git a/ext/standard/tests/file/007_variation12-win32.phpt b/ext/standard/tests/file/007_variation12-win32.phpt new file mode 100644 index 0000000000..beadfd9819 --- /dev/null +++ b/ext/standard/tests/file/007_variation12-win32.phpt @@ -0,0 +1,95 @@ +--TEST-- +Test fopen and fclose() functions - usage variations - "w+t" mode +--SKIPIF-- +<?php +if( substr(PHP_OS, 0, 3) != "WIN" ) + die('skip Run only on Windows'); +?> +--FILE-- +<?php +/* + fopen() function: + Prototype: resource fopen(string $filename, string $mode + [, bool $use_include_path [, resource $context]] ); + Description: Opens file or URL. +*/ +/* + fclose() function: + Prototype: bool fclose ( resource $handle ); + Description: Closes an open file pointer +*/ + +/* Test fopen() and fclose(): Opening the file in "w+t" mode, + checking for the file creation, write & read operations, + checking for the file pointer position, + checking for the file truncation when trying to open an existing file in "w+t" mode, + and fclose function +*/ +$file_path = dirname(__FILE__); +require($file_path."/file.inc"); + +create_files($file_path, 1, "text_with_new_line", 0755, 20, "w", "007_variation", 12, "bytes"); +$file = $file_path."/007_variation12.tmp"; +$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; + +echo "*** Test fopen() & fclose() functions: with 'w+t' mode ***\n"; +$file_handle = fopen($file, "w+t"); //opening the file "w+t" mode +var_dump($file_handle); //Check for the content of handle +var_dump( get_resource_type($file_handle) ); //Check for the type of resource +var_dump( ftell($file_handle) ); //Initial file pointer position, expected at the begining of the file +var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string +var_dump( ftell($file_handle) ); //File pointer position after write operation, expected at the end of the file +rewind($file_handle); +var_dump( fread($file_handle, 100) ); //Check for read operation; passes; expected: content of file +var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the end of the file +var_dump( fclose($file_handle) ); //Check for close operation on the file handle +var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation + +var_dump( filesize($file) ); //Check for size of existing data file before opening the file in "w+t" mode again, expected: size of content +clearstatcache(); +fclose( fopen($file, "w+t") ); //Opening the existing data file again in "w+t" mode +var_dump( filesize($file) ); //Check for size of existing data file after opening the file in "w+t" mode again, expected: 0 bytes +clearstatcache(); + +unlink($file); //Deleting the file +fclose( fopen($file, "w+t") ); //Opening the non-existing file in "w+t" mode, which will be created +var_dump( file_exists($file) ); //Check for the existance of file +echo "*** Done ***\n"; +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/007_variation12.tmp"); +?> +--EXPECTF-- +*** Test fopen() & fclose() functions: with 'w+t' mode *** +resource(8) of type (stream) +string(6) "stream" +int(0) +int(37) +int(37) +string(37) "abcdefghij +mnopqrst uvwxyz +0123456789" +int(37) +bool(true) +string(7) "Unknown" +int(39) +int(0) +bool(true) +*** Done *** +--UEXPECTF-- +*** Test fopen() & fclose() functions: with 'w+t' mode *** +resource(8) of type (stream) +unicode(6) "stream" +int(0) +int(37) +int(37) +unicode(37) "abcdefghij +mnopqrst uvwxyz +0123456789" +int(37) +bool(true) +unicode(7) "Unknown" +int(39) +int(0) +bool(true) +*** Done *** diff --git a/ext/standard/tests/file/007_variation12.phpt b/ext/standard/tests/file/007_variation12.phpt new file mode 100644 index 0000000000..00163d2aca --- /dev/null +++ b/ext/standard/tests/file/007_variation12.phpt @@ -0,0 +1,95 @@ +--TEST-- +Test fopen and fclose() functions - usage variations - "w+t" mode +--SKIPIF-- +<?php +if( substr(PHP_OS, 0, 3) == "WIN" ) + die('skip Do not run on Windows'); +?> +--FILE-- +<?php +/* + fopen() function: + Prototype: resource fopen(string $filename, string $mode + [, bool $use_include_path [, resource $context]] ); + Description: Opens file or URL. +*/ +/* + fclose() function: + Prototype: bool fclose ( resource $handle ); + Description: Closes an open file pointer +*/ + +/* Test fopen() and fclose(): Opening the file in "w+t" mode, + checking for the file creation, write & read operations, + checking for the file pointer position, + checking for the file truncation when trying to open an existing file in "w+t" mode, + and fclose function +*/ +$file_path = dirname(__FILE__); +require($file_path."/file.inc"); + +create_files($file_path, 1, "text_with_new_line", 0755, 20, "w", "007_variation", 12, "bytes"); +$file = $file_path."/007_variation12.tmp"; +$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; + +echo "*** Test fopen() & fclose() functions: with 'w+t' mode ***\n"; +$file_handle = fopen($file, "w+t"); //opening the file "w+t" mode +var_dump($file_handle); //Check for the content of handle +var_dump( get_resource_type($file_handle) ); //Check for the type of resource +var_dump( ftell($file_handle) ); //Initial file pointer position, expected at the begining of the file +var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string +var_dump( ftell($file_handle) ); //File pointer position after write operation, expected at the end of the file +rewind($file_handle); +var_dump( fread($file_handle, 100) ); //Check for read operation; passes; expected: content of file +var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the end of the file +var_dump( fclose($file_handle) ); //Check for close operation on the file handle +var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation + +var_dump( filesize($file) ); //Check for size of existing data file before opening the file in "w+t" mode again, expected: size of content +clearstatcache(); +fclose( fopen($file, "w+t") ); //Opening the existing data file again in "w+t" mode +var_dump( filesize($file) ); //Check for size of existing data file after opening the file in "w+t" mode again, expected: 0 bytes +clearstatcache(); + +unlink($file); //Deleting the file +fclose( fopen($file, "w+t") ); //Opening the non-existing file in "w+t" mode, which will be created +var_dump( file_exists($file) ); //Check for the existance of file +echo "*** Done ***\n"; +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/007_variation12.tmp"); +?> +--EXPECTF-- +*** Test fopen() & fclose() functions: with 'w+t' mode *** +resource(8) of type (stream) +string(6) "stream" +int(0) +int(37) +int(37) +string(37) "abcdefghij +mnopqrst uvwxyz +0123456789" +int(37) +bool(true) +string(7) "Unknown" +int(37) +int(0) +bool(true) +*** Done *** +--UEXPECTF-- +*** Test fopen() & fclose() functions: with 'w+t' mode *** +resource(8) of type (stream) +unicode(6) "stream" +int(0) +int(37) +int(37) +unicode(37) "abcdefghij +mnopqrst uvwxyz +0123456789" +int(37) +bool(true) +unicode(7) "Unknown" +int(37) +int(0) +bool(true) +*** Done *** diff --git a/ext/standard/tests/file/007_variation13-win32.phpt b/ext/standard/tests/file/007_variation13-win32.phpt new file mode 100644 index 0000000000..3d764bc136 --- /dev/null +++ b/ext/standard/tests/file/007_variation13-win32.phpt @@ -0,0 +1,77 @@ +--TEST-- +Test fopen and fclose() functions - usage variations - "at" mode +--SKIPIF-- +<?php +if( substr(PHP_OS, 0, 3) != "WIN" ) + die('skip Run only on Windows'); +?> +--FILE-- +<?php +/* + fopen() function: + Prototype: resource fopen(string $filename, string $mode + [, bool $use_include_path [, resource $context]] ); + Description: Opens file or URL. +*/ +/* + fclose() function: + Prototype: bool fclose ( resource $handle ); + Description: Closes an open file pointer +*/ + +/* Test fopen() and fclose(): Opening the file in "at" mode, + checking for the file creation, write & read operations, + checking for the file pointer position, + and fclose function +*/ +$file_path = dirname(__FILE__); +require($file_path."/file.inc"); + +create_files($file_path, 1, "text_with_new_line", 0755, 20, "w", "007_variation", 13, "bytes"); +$file = $file_path."/007_variation13.tmp"; +$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; + +echo "*** Test fopen() & fclose() functions: with 'at' mode ***\n"; +$file_handle = fopen($file, "at"); //opening the file "at" mode +var_dump($file_handle); //Check for the content of handle +var_dump( get_resource_type($file_handle) ); //Check for the type of resource +var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string +rewind($file_handle); +var_dump( fread($file_handle, 100) ); //Check for read operation; fails; expected: empty string +var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the end of the file +var_dump( fclose($file_handle) ); //Check for close operation on the file handle +var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation +var_dump( filesize($file) ); //Check that data hasn't over written; Expected: Size of (initial data + newly added data) + +unlink($file); //Deleting the file +fclose( fopen($file, "at") ); //Opening the non-existing file in "at" mode, which will be created +var_dump( file_exists($file) ); //Check for the existance of file +echo "*** Done ***\n"; +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/007_variation13.tmp"); +?> +--EXPECTF-- +*** Test fopen() & fclose() functions: with 'at' mode *** +resource(8) of type (stream) +string(6) "stream" +int(37) +bool(false) +int(0) +bool(true) +string(7) "Unknown" +int(59) +bool(true) +*** Done *** +--UEXPECTF-- +*** Test fopen() & fclose() functions: with 'at' mode *** +resource(8) of type (stream) +unicode(6) "stream" +int(37) +bool(false) +int(0) +bool(true) +unicode(7) "Unknown" +int(59) +bool(true) +*** Done *** diff --git a/ext/standard/tests/file/007_variation13.phpt b/ext/standard/tests/file/007_variation13.phpt new file mode 100644 index 0000000000..ddb4555963 --- /dev/null +++ b/ext/standard/tests/file/007_variation13.phpt @@ -0,0 +1,77 @@ +--TEST-- +Test fopen and fclose() functions - usage variations - "at" mode +--SKIPIF-- +<?php +if( substr(PHP_OS, 0, 3) == "WIN" ) + die('skip Do not run on Windows'); +?> +--FILE-- +<?php +/* + fopen() function: + Prototype: resource fopen(string $filename, string $mode + [, bool $use_include_path [, resource $context]] ); + Description: Opens file or URL. +*/ +/* + fclose() function: + Prototype: bool fclose ( resource $handle ); + Description: Closes an open file pointer +*/ + +/* Test fopen() and fclose(): Opening the file in "at" mode, + checking for the file creation, write & read operations, + checking for the file pointer position, + and fclose function +*/ +$file_path = dirname(__FILE__); +require($file_path."/file.inc"); + +create_files($file_path, 1, "text_with_new_line", 0755, 20, "w", "007_variation", 13, "bytes"); +$file = $file_path."/007_variation13.tmp"; +$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; + +echo "*** Test fopen() & fclose() functions: with 'at' mode ***\n"; +$file_handle = fopen($file, "at"); //opening the file "at" mode +var_dump($file_handle); //Check for the content of handle +var_dump( get_resource_type($file_handle) ); //Check for the type of resource +var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string +rewind($file_handle); +var_dump( fread($file_handle, 100) ); //Check for read operation; fails; expected: empty string +var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the end of the file +var_dump( fclose($file_handle) ); //Check for close operation on the file handle +var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation +var_dump( filesize($file) ); //Check that data hasn't over written; Expected: Size of (initial data + newly added data) + +unlink($file); //Deleting the file +fclose( fopen($file, "at") ); //Opening the non-existing file in "at" mode, which will be created +var_dump( file_exists($file) ); //Check for the existance of file +echo "*** Done ***\n"; +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/007_variation13.tmp"); +?> +--EXPECTF-- +*** Test fopen() & fclose() functions: with 'at' mode *** +resource(8) of type (stream) +string(6) "stream" +int(37) +bool(false) +int(0) +bool(true) +string(7) "Unknown" +int(57) +bool(true) +*** Done *** +--UEXPECTF-- +*** Test fopen() & fclose() functions: with 'at' mode *** +resource(8) of type (stream) +unicode(6) "stream" +int(37) +bool(false) +int(0) +bool(true) +unicode(7) "Unknown" +int(57) +bool(true) +*** Done *** diff --git a/ext/standard/tests/file/007_variation14.phpt b/ext/standard/tests/file/007_variation14.phpt new file mode 100644 index 0000000000..c12593a84a --- /dev/null +++ b/ext/standard/tests/file/007_variation14.phpt @@ -0,0 +1,77 @@ +--TEST-- +Test fopen and fclose() functions - usage variations - "a+t" mode +--FILE-- +<?php +/* + fopen() function: + Prototype: resource fopen(string $filename, string $mode + [, bool $use_include_path [, resource $context]] ); + Description: Opens file or URL. +*/ +/* + fclose() function: + Prototype: bool fclose ( resource $handle ); + Description: Closes an open file pointer +*/ + +/* Test fopen() and fclose(): Opening the file in "a+t" mode, + checking for the file creation, write & read operations, + checking for the file pointer position, + and fclose function +*/ +$file_path = dirname(__FILE__); +require($file_path."/file.inc"); + +create_files($file_path, 1, "text_with_new_line", 0755, 20, "w", "007_variation", 14, "bytes"); +$file = $file_path."/007_variation14.tmp"; +$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; + +echo "*** Test fopen() & fclose() functions: with 'a+t' mode ***\n"; +$file_handle = fopen($file, "a+t"); //opening the file "a+t" mode +var_dump($file_handle); //Check for the content of handle +var_dump( get_resource_type($file_handle) ); //Check for the type of resource +var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string +rewind($file_handle); +var_dump( fread($file_handle, 100) ); //Check for read operation; passes; expected: content of file +var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the end of the file +var_dump( fclose($file_handle) ); //Check for close operation on the file handle +var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation + +unlink($file); //Deleting the file +fclose( fopen($file, "a+t") ); //Opening the non-existing file in "a+t" mode, which will be created +var_dump( file_exists($file) ); //Check for the existance of file +echo "*** Done ***\n"; +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/007_variation14.tmp"); +?> +--EXPECTF-- +*** Test fopen() & fclose() functions: with 'a+t' mode *** +resource(8) of type (stream) +string(6) "stream" +int(37) +string(57) "line +line of text +liabcdefghij +mnopqrst uvwxyz +0123456789" +int(57) +bool(true) +string(7) "Unknown" +bool(true) +*** Done *** +--UEXPECTF-- +*** Test fopen() & fclose() functions: with 'a+t' mode *** +resource(8) of type (stream) +unicode(6) "stream" +int(37) +unicode(57) "line +line of text +liabcdefghij +mnopqrst uvwxyz +0123456789" +int(57) +bool(true) +unicode(7) "Unknown" +bool(true) +*** Done ***
\ No newline at end of file diff --git a/ext/standard/tests/file/007_variation15.phpt b/ext/standard/tests/file/007_variation15.phpt new file mode 100644 index 0000000000..9f3ae6b180 --- /dev/null +++ b/ext/standard/tests/file/007_variation15.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test fopen and fclose() functions - usage variations - "xt" mode +--FILE-- +<?php +/* + fopen() function: + Prototype: resource fopen(string $filename, string $mode + [, bool $use_include_path [, resource $context]] ); + Description: Opens file or URL. +*/ +/* + fclose() function: + Prototype: bool fclose ( resource $handle ); + Description: Closes an open file pointer +*/ + +/* Test fopen() and fclose(): Opening the file in "xt" mode, + checking for the file creation, write & read operations, + checking for the file pointer position, + checking for the warning msg when trying to open an existing file in "xt" mode, + and fclose function +*/ +$file_path = dirname(__FILE__); +$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; +$file = $file_path."/007_variation15.tmp"; + +echo "*** Test fopen() & fclose() functions: with 'xt' mode ***\n"; +$file_handle = fopen($file, "xt"); //opening the non-existing file in "xt" mode, file will be created +var_dump($file_handle); //Check for the content of handle +var_dump( get_resource_type($file_handle) ); //Check for the type of resource +var_dump( ftell($file_handle) ); //Initial file pointer position, expected at the begining of the file +var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string +var_dump( ftell($file_handle) ); //File pointer position after write operation, expected at the end of the file +rewind($file_handle); +var_dump( fread($file_handle, 100) ); //Check for read operation; fails; expected: empty string +var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the begining of the file +var_dump( fclose($file_handle) ); //Check for close operation on the file handle +var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation +$file_handle = fopen($file, "xt"); //Opening the existing data file in 'xt' mode to check for the warning message +echo "*** Done ***\n"; +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/007_variation15.tmp"); +?> +--EXPECTF-- +*** Test fopen() & fclose() functions: with 'xt' mode *** +resource(5) of type (stream) +string(6) "stream" +int(0) +int(37) +int(37) +bool(false) +int(0) +bool(true) +string(7) "Unknown" + +Warning: fopen(%s): failed to open stream: File exists in %s on line %d +*** Done *** +--UEXPECTF-- +*** Test fopen() & fclose() functions: with 'xt' mode *** +resource(5) of type (stream) +unicode(6) "stream" +int(0) + +Notice: fwrite(): 37 character unicode buffer downcoded for binary stream runtime_encoding in %s on line %d +int(37) +int(37) +bool(false) +int(0) +bool(true) +unicode(7) "Unknown" + +Warning: fopen(%s): failed to open stream: File exists in %s on line %d +*** Done *** diff --git a/ext/standard/tests/file/007_variation16.phpt b/ext/standard/tests/file/007_variation16.phpt new file mode 100644 index 0000000000..6f50293254 --- /dev/null +++ b/ext/standard/tests/file/007_variation16.phpt @@ -0,0 +1,76 @@ +--TEST-- +Test fopen and fclose() functions - usage variations - "x+t" mode +--FILE-- +<?php +/* + fopen() function: + Prototype: resource fopen(string $filename, string $mode + [, bool $use_include_path [, resource $context]] ); + Description: Opens file or URL. +*/ +/* + fclose() function: + Prototype: bool fclose ( resource $handle ); + Description: Closes an open file pointer +*/ + +/* Test fopen() and fclose(): Opening the file in "x+t" mode, + checking for the file creation, write & read operations, + checking for the file pointer position, + checking for the warning msg when trying to open an existing file in "x+t" mode, + and fclose function +*/ +$file_path = dirname(__FILE__); +$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; +$file = $file_path."/007_variation16.tmp"; + +echo "*** Test fopen() & fclose() functions: with 'x+t' mode ***\n"; +$file_handle = fopen($file, "x+t"); //opening the non-existing file in "x+t" mode, file will be created +var_dump($file_handle); //Check for the content of handle +var_dump( get_resource_type($file_handle) ); //Check for the type of resource +var_dump( ftell($file_handle) ); //Initial file pointer position, expected at the begining of the file +var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string +var_dump( ftell($file_handle) ); //File pointer position after write operation, expected at the end of the file +rewind($file_handle); +var_dump( fread($file_handle, 100) ); //Check for read operation; passes; expected: content of the file +var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the end of the file +var_dump( fclose($file_handle) ); //Check for close operation on the file handle +var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation +$file_handle = fopen($file, "x+t"); //Opening the existing data file in "x+t" mode to check for the warning message +echo "*** Done ***\n"; +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/007_variation16.tmp"); +?> +--EXPECTF-- +*** Test fopen() & fclose() functions: with 'x+t' mode *** +resource(5) of type (stream) +string(6) "stream" +int(0) +int(37) +int(37) +string(37) "abcdefghij +mnopqrst uvwxyz +0123456789" +int(37) +bool(true) +string(7) "Unknown" + +Warning: fopen(%s): failed to open stream: File exists in %s on line %d +*** Done *** +--UEXPECTF-- +*** Test fopen() & fclose() functions: with 'x+t' mode *** +resource(5) of type (stream) +unicode(6) "stream" +int(0) +int(37) +int(37) +unicode(37) "abcdefghij +mnopqrst uvwxyz +0123456789" +int(37) +bool(true) +unicode(7) "Unknown" + +Warning: fopen(%s): failed to open stream: File exists in %s on line %d +*** Done *** diff --git a/ext/standard/tests/file/007_variation17.phpt b/ext/standard/tests/file/007_variation17.phpt new file mode 100644 index 0000000000..63b60cf683 --- /dev/null +++ b/ext/standard/tests/file/007_variation17.phpt @@ -0,0 +1,68 @@ +--TEST-- +Test fopen and fclose() functions - usage variations - "rb" mode +--FILE-- +<?php +/* + fopen() function: + Prototype: resource fopen(string $filename, string $mode + [, bool $use_include_path [, resource $context]] ); + Description: Opens file or URL. +*/ +/* + fclose() function: + Prototype: bool fclose ( resource $handle ); + Description: Closes an open file pointer +*/ + +/* Test fopen() and fclose(): Opening the file in "rb" mode, + checking for the file creation, write & read operations, + checking for the file pointer position, + and fclose function +*/ +$file_path = dirname(__FILE__); +require($file_path."/file.inc"); + +create_files($file_path, 1, "text_with_new_line", 0755, 20, "w", "007_variation", 17, "bytes"); +$file = $file_path."/007_variation17.tmp"; +$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; + +echo "*** Test fopen() & fclose() functions: with 'rb' mode ***\n"; +$file_handle = fopen($file, "rb"); //opening the file in "rb" mode +var_dump($file_handle); //Check for the content of handle +var_dump( get_resource_type($file_handle) ); //Check for the type of resource +var_dump( ftell($file_handle) ); //Initial position of file pointer +var_dump( fread($file_handle, 100) ); //Check for read operation +var_dump( fwrite($file_handle, $string) ); //Check for write operation; fails; expected: 0 bytes +var_dump( fclose($file_handle) ); //Check for close operation on the file handle +var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation +echo "*** Done ***\n"; +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/007_variation17.tmp"); +?> +--EXPECTF-- +*** Test fopen() & fclose() functions: with 'rb' mode *** +resource(8) of type (stream) +string(6) "stream" +int(0) +string(20) "line +line of text +li" +int(0) +bool(true) +string(7) "Unknown" +*** Done *** +--UEXPECTF-- +*** Test fopen() & fclose() functions: with 'rb' mode *** +resource(8) of type (stream) +unicode(6) "stream" +int(0) +string(20) "line +line of text +li" + +Notice: fwrite(): 37 character unicode buffer downcoded for binary stream runtime_encoding in %s on line %d +int(0) +bool(true) +unicode(7) "Unknown" +*** Done *** diff --git a/ext/standard/tests/file/007_variation18.phpt b/ext/standard/tests/file/007_variation18.phpt new file mode 100644 index 0000000000..277195c190 --- /dev/null +++ b/ext/standard/tests/file/007_variation18.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test fopen and fclose() functions - usage variations - "r+b" mode +--FILE-- +<?php +/* + fopen() function: + Prototype: resource fopen(string $filename, string $mode + [, bool $use_include_path [, resource $context]] ); + Description: Opens file or URL. +*/ +/* + fclose() function: + Prototype: bool fclose ( resource $handle ); + Description: Closes an open file pointer +*/ + +/* Test fopen() and fclose(): Opening the file in "r+b" mode, + checking for the file creation, write & read operations, + checking for the file pointer position, + and fclose function +*/ +$file_path = dirname(__FILE__); +require($file_path."/file.inc"); + +create_files($file_path, 1, "text_with_new_line", 0755, 20, "w", "007_variation", 18, "bytes"); +$file = $file_path."/007_variation18.tmp"; +$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; + +echo "*** Test fopen() & fclose() functions: with 'r+b' mode ***\n"; +$file_handle = fopen($file, "r+b"); //opening the file in "r+b" mode +var_dump($file_handle); //Check for the content of handle +var_dump( get_resource_type($file_handle) ); //Check for the type of resource +var_dump( ftell($file_handle) ); //Initial file pointer position, expected at the begining of the file +var_dump( fread($file_handle, 100) ); //Check for read operation +var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the end of the file +var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string +var_dump( ftell($file_handle) ); //File pointer position after write operation, expected at the end of the file +var_dump( fclose($file_handle) ); //Check for close operation on the file handle +var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation +echo "*** Done ***\n"; +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/007_variation18.tmp"); +?> +--EXPECTF-- +*** Test fopen() & fclose() functions: with 'r+b' mode *** +resource(8) of type (stream) +string(6) "stream" +int(0) +string(20) "line +line of text +li" +int(20) +int(37) +int(57) +bool(true) +string(7) "Unknown" +*** Done *** +--UEXPECTF-- +*** Test fopen() & fclose() functions: with 'r+b' mode *** +resource(8) of type (stream) +unicode(6) "stream" +int(0) +string(20) "line +line of text +li" +int(20) + +Notice: fwrite(): 37 character unicode buffer downcoded for binary stream runtime_encoding in %s on line %d +int(37) +int(57) +bool(true) +unicode(7) "Unknown" +*** Done *** diff --git a/ext/standard/tests/file/007_variation19.phpt b/ext/standard/tests/file/007_variation19.phpt new file mode 100644 index 0000000000..594c3e25b2 --- /dev/null +++ b/ext/standard/tests/file/007_variation19.phpt @@ -0,0 +1,88 @@ +--TEST-- +Test fopen and fclose() functions - usage variations - "wb" mode +--FILE-- +<?php +/* + fopen() function: + Prototype: resource fopen(string $filename, string $mode + [, bool $use_include_path [, resource $context]] ); + Description: Opens file or URL. +*/ +/* + fclose() function: + Prototype: bool fclose ( resource $handle ); + Description: Closes an open file pointer +*/ + +/* Test fopen() and fclose(): Opening the file in "wb" mode, + checking for the file creation, write & read operations, + checking for the file pointer position, + checking for the file truncation when trying to open an existing file in "wb" mode, + and fclose function +*/ +$file_path = dirname(__FILE__); +require($file_path."/file.inc"); + +create_files($file_path, 1, "text_with_new_line", 0755, 20, "wb", "007_variation", 19, "bytes"); +$file = $file_path."/007_variation19.tmp"; +$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; + +echo "*** Test fopen() & fclose() functions: with 'wb' mode ***\n"; +$file_handle = fopen($file, "wb"); //opening the file "wb" mode +var_dump($file_handle); //Check for the content of handle +var_dump( get_resource_type($file_handle) ); //Check for the type of resource +var_dump( ftell($file_handle) ); //Initial file pointer position, expected at the begining of the file +var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string +var_dump( ftell($file_handle) ); //File pointer position after write operation, expected at the end of the file +rewind($file_handle); +var_dump( fread($file_handle, 100) ); //Check for read operation; fails; expected: empty string +var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the begining of the file +var_dump( fclose($file_handle) ); //Check for close operation on the file handle +var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation + +var_dump( filesize($file) ); //Check for size of existing data file before opening the file in "wb" mode again, expected: size of content +clearstatcache(); +fclose( fopen($file, "wb") ); //Opening the existing data file again in "wb" mode +var_dump( filesize($file) ); //Check for size of existing data file after opening the file in "wb" mode again, expected: 0 bytes +clearstatcache(); + +unlink($file); //Deleting the file +fclose( fopen($file, "wb") ); //Opening the non-existing file in "wb" mode, which will be created +var_dump( file_exists($file) ); //Check for the existance of file +echo "*** Done ***\n"; +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/007_variation19.tmp"); +?> +--EXPECTF-- +*** Test fopen() & fclose() functions: with 'wb' mode *** +resource(8) of type (stream) +string(6) "stream" +int(0) +int(37) +int(37) +bool(false) +int(0) +bool(true) +string(7) "Unknown" +int(37) +int(0) +bool(true) +*** Done *** +--UEXPECTF-- +*** Test fopen() & fclose() functions: with 'wb' mode *** +resource(8) of type (stream) +unicode(6) "stream" +int(0) + +Notice: fwrite(): 37 character unicode buffer downcoded for binary stream runtime_encoding in %s on line %d +int(37) +int(37) +bool(false) +int(0) +bool(true) +unicode(7) "Unknown" +int(37) +int(0) +bool(true) +*** Done *** diff --git a/ext/standard/tests/file/007_variation2.phpt b/ext/standard/tests/file/007_variation2.phpt new file mode 100644 index 0000000000..b2ef137cda --- /dev/null +++ b/ext/standard/tests/file/007_variation2.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test fopen and fclose() functions - usage variations - "r+" mode +--FILE-- +<?php +/* + fopen() function: + Prototype: resource fopen(string $filename, string $mode + [, bool $use_include_path [, resource $context]] ); + Description: Opens file or URL. +*/ +/* + fclose() function: + Prototype: bool fclose ( resource $handle ); + Description: Closes an open file pointer +*/ + +/* Test fopen() and fclose(): Opening the file in "r+" mode, + checking for the file creation, write & read operations, + checking for the file pointer position, + and fclose function +*/ +$file_path = dirname(__FILE__); +require($file_path."/file.inc"); + +create_files($file_path, 1, "text_with_new_line", 0755, 20, "w", "007_variation", 2, "bytes"); +$file = $file_path."/007_variation2.tmp"; +$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; + +echo "*** Test fopen() & fclose() functions: with 'r+' mode ***\n"; +$file_handle = fopen($file, "r+"); //opening the file in "r+" mode +var_dump($file_handle); //Check for the content of handle +var_dump( get_resource_type($file_handle) ); //Check for the type of resource +var_dump( ftell($file_handle) ); //Initial file pointer position, expected at the begining of the file +var_dump( fread($file_handle, 100) ); //Check for read operation +var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the end of the file +var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string +var_dump( ftell($file_handle) ); //File pointer position after write operation, expected at the end of the file +var_dump( fclose($file_handle) ); //Check for close operation on the file handle +var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation +echo "*** Done ***\n"; +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/007_variation2.tmp"); +?> +--EXPECTF-- +*** Test fopen() & fclose() functions: with 'r+' mode *** +resource(8) of type (stream) +string(6) "stream" +int(0) +string(20) "line +line of text +li" +int(20) +int(37) +int(57) +bool(true) +string(7) "Unknown" +*** Done *** +--UEXPECTF-- +*** Test fopen() & fclose() functions: with 'r+' mode *** +resource(8) of type (stream) +unicode(6) "stream" +int(0) +string(20) "line +line of text +li" +int(20) + +Notice: fwrite(): 37 character unicode buffer downcoded for binary stream runtime_encoding in %s on line %d +int(37) +int(57) +bool(true) +unicode(7) "Unknown" +*** Done *** diff --git a/ext/standard/tests/file/007_variation20.phpt b/ext/standard/tests/file/007_variation20.phpt new file mode 100644 index 0000000000..ed4cf10f6d --- /dev/null +++ b/ext/standard/tests/file/007_variation20.phpt @@ -0,0 +1,92 @@ +--TEST-- +Test fopen and fclose() functions - usage variations - "w+b" mode +--FILE-- +<?php +/* + fopen() function: + Prototype: resource fopen(string $filename, string $mode + [, bool $use_include_path [, resource $context]] ); + Description: Opens file or URL. +*/ +/* + fclose() function: + Prototype: bool fclose ( resource $handle ); + Description: Closes an open file pointer +*/ + +/* Test fopen() and fclose(): Opening the file in "w+b" mode, + checking for the file creation, write & read operations, + checking for the file pointer position, + checking for the file truncation when trying to open an existing file in "w+b" mode, + and fclose function +*/ +$file_path = dirname(__FILE__); +require($file_path."/file.inc"); + +create_files($file_path, 1, "text_with_new_line", 0755, 20, "w", "007_variation", 20, "bytes"); +$file = $file_path."/007_variation20.tmp"; +$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; + +echo "*** Test fopen() & fclose() functions: with 'w+b' mode ***\n"; +$file_handle = fopen($file, "w+b"); //opening the file "w+b" mode +var_dump($file_handle); //Check for the content of handle +var_dump( get_resource_type($file_handle) ); //Check for the type of resource +var_dump( ftell($file_handle) ); //Initial file pointer position, expected at the begining of the file +var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string +var_dump( ftell($file_handle) ); //File pointer position after write operation, expected at the end of the file +rewind($file_handle); +var_dump( fread($file_handle, 100) ); //Check for read operation; passes; expected: content of file +var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the end of the file +var_dump( fclose($file_handle) ); //Check for close operation on the file handle +var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation + +var_dump( filesize($file) ); //Check for size of existing data file before opening the file in "w+b" mode again, expected: size of content +clearstatcache(); +fclose( fopen($file, "w+b") ); //Opening the existing data file again in "w+b" mode +var_dump( filesize($file) ); //Check for size of existing data file after opening the file in "w+b" mode again, expected: 0 bytes +clearstatcache(); + +unlink($file); //Deleting the file +fclose( fopen($file, "w+b") ); //Opening the non-existing file in "w+b" mode, which will be created +var_dump( file_exists($file) ); //Check for the existance of file +echo "*** Done ***\n"; +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/007_variation20.tmp"); +?> +--EXPECTF-- +*** Test fopen() & fclose() functions: with 'w+b' mode *** +resource(8) of type (stream) +string(6) "stream" +int(0) +int(37) +int(37) +string(37) "abcdefghij +mnopqrst uvwxyz +0123456789" +int(37) +bool(true) +string(7) "Unknown" +int(37) +int(0) +bool(true) +*** Done *** +--UEXPECTF-- +*** Test fopen() & fclose() functions: with 'w+b' mode *** +resource(8) of type (stream) +unicode(6) "stream" +int(0) + +Notice: fwrite(): 37 character unicode buffer downcoded for binary stream runtime_encoding in %s on line %d +int(37) +int(37) +string(37) "abcdefghij +mnopqrst uvwxyz +0123456789" +int(37) +bool(true) +unicode(7) "Unknown" +int(37) +int(0) +bool(true) +*** Done *** diff --git a/ext/standard/tests/file/007_variation21.phpt b/ext/standard/tests/file/007_variation21.phpt new file mode 100644 index 0000000000..4a2fbb5d9c --- /dev/null +++ b/ext/standard/tests/file/007_variation21.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test fopen and fclose() functions - usage variations - "ab" mode +--FILE-- +<?php +/* + fopen() function: + Prototype: resource fopen(string $filename, string $mode + [, bool $use_include_path [, resource $context]] ); + Description: Opens file or URL. +*/ +/* + fclose() function: + Prototype: bool fclose ( resource $handle ); + Description: Closes an open file pointer +*/ + +/* Test fopen() and fclose(): Opening the file in "ab" mode, + checking for the file creation, write & read operations, + checking for the file pointer position, + and fclose function +*/ +$file_path = dirname(__FILE__); +require($file_path."/file.inc"); + +create_files($file_path, 1, "text_with_new_line", 0755, 20, "w", "007_variation", 21, "bytes"); +$file = $file_path."/007_variation21.tmp"; +$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; + +echo "*** Test fopen() & fclose() functions: with 'ab' mode ***\n"; +$file_handle = fopen($file, "ab"); //opening the file "ab" mode +var_dump($file_handle); //Check for the content of handle +var_dump( get_resource_type($file_handle) ); //Check for the type of resource +var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string +rewind($file_handle); +var_dump( fread($file_handle, 100) ); //Check for read operation; fails; expected: empty string +var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the end of the file +var_dump( fclose($file_handle) ); //Check for close operation on the file handle +var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation +var_dump( filesize($file) ); //Check that data hasn't over written; Expected: Size of (initial data + newly added data) + +unlink($file); //Deleting the file +fclose( fopen($file, "ab") ); //Opening the non-existing file in "ab" mode, which will be created +var_dump( file_exists($file) ); //Check for the existance of file +echo "*** Done ***\n"; +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/007_variation21.tmp"); +?> +--EXPECTF-- +*** Test fopen() & fclose() functions: with 'ab' mode *** +resource(8) of type (stream) +string(6) "stream" +int(37) +bool(false) +int(0) +bool(true) +string(7) "Unknown" +int(57) +bool(true) +*** Done *** +--UEXPECTF-- +*** Test fopen() & fclose() functions: with 'ab' mode *** +resource(8) of type (stream) +unicode(6) "stream" + +Notice: fwrite(): 37 character unicode buffer downcoded for binary stream runtime_encoding in %s on line %d +int(37) +bool(false) +int(0) +bool(true) +unicode(7) "Unknown" +int(57) +bool(true) +*** Done *** diff --git a/ext/standard/tests/file/007_variation22.phpt b/ext/standard/tests/file/007_variation22.phpt new file mode 100644 index 0000000000..28af71b2e1 --- /dev/null +++ b/ext/standard/tests/file/007_variation22.phpt @@ -0,0 +1,79 @@ +--TEST-- +Test fopen and fclose() functions - usage variations - "a+b" mode +--FILE-- +<?php +/* + fopen() function: + Prototype: resource fopen(string $filename, string $mode + [, bool $use_include_path [, resource $context]] ); + Description: Opens file or URL. +*/ +/* + fclose() function: + Prototype: bool fclose ( resource $handle ); + Description: Closes an open file pointer +*/ + +/* Test fopen() and fclose(): Opening the file in "a+b" mode, + checking for the file creation, write & read operations, + checking for the file pointer position, + and fclose function +*/ +$file_path = dirname(__FILE__); +require($file_path."/file.inc"); + +create_files($file_path, 1, "text_with_new_line", 0755, 20, "w", "007_variation", 22, "bytes"); +$file = $file_path."/007_variation22.tmp"; +$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; + +echo "*** Test fopen() & fclose() functions: with 'a+b' mode ***\n"; +$file_handle = fopen($file, "a+b"); //opening the file "a+b" mode +var_dump($file_handle); //Check for the content of handle +var_dump( get_resource_type($file_handle) ); //Check for the type of resource +var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string +rewind($file_handle); +var_dump( fread($file_handle, 100) ); //Check for read operation; passes; expected: content of file +var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the end of the file +var_dump( fclose($file_handle) ); //Check for close operation on the file handle +var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation + +unlink($file); //Deleting the file +fclose( fopen($file, "a+b") ); //Opening the non-existing file in "a+b" mode, which will be created +var_dump( file_exists($file) ); //Check for the existance of file +echo "*** Done ***\n"; +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/007_variation22.tmp"); +?> +--EXPECTF-- +*** Test fopen() & fclose() functions: with 'a+b' mode *** +resource(8) of type (stream) +string(6) "stream" +int(37) +string(57) "line +line of text +liabcdefghij +mnopqrst uvwxyz +0123456789" +int(57) +bool(true) +string(7) "Unknown" +bool(true) +*** Done *** +--UEXPECTF-- +*** Test fopen() & fclose() functions: with 'a+b' mode *** +resource(8) of type (stream) +unicode(6) "stream" + +Notice: fwrite(): 37 character unicode buffer downcoded for binary stream runtime_encoding in %s on line %d +int(37) +string(57) "line +line of text +liabcdefghij +mnopqrst uvwxyz +0123456789" +int(57) +bool(true) +unicode(7) "Unknown" +bool(true) +*** Done *** diff --git a/ext/standard/tests/file/007_variation23.phpt b/ext/standard/tests/file/007_variation23.phpt new file mode 100644 index 0000000000..e84a496a2e --- /dev/null +++ b/ext/standard/tests/file/007_variation23.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test fopen and fclose() functions - usage variations - "xb" mode +--FILE-- +<?php +/* + fopen() function: + Prototype: resource fopen(string $filename, string $mode + [, bool $use_include_path [, resource $context]] ); + Description: Opens file or URL. +*/ +/* + fclose() function: + Prototype: bool fclose ( resource $handle ); + Description: Closes an open file pointer +*/ + +/* Test fopen() and fclose(): Opening the file in "xb" mode, + checking for the file creation, write & read operations, + checking for the file pointer position, + checking for the warning msg when trying to open an existing file in "xb" mode, + and fclose function +*/ +$file_path = dirname(__FILE__); +$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; +$file = $file_path."/007_variation23.tmp"; + +echo "*** Test fopen() & fclose() functions: with 'xb' mode ***\n"; +$file_handle = fopen($file, "xb"); //opening the non-existing file in "xb" mode, file will be created +var_dump($file_handle); //Check for the content of handle +var_dump( get_resource_type($file_handle) ); //Check for the type of resource +var_dump( ftell($file_handle) ); //Initial file pointer position, expected at the begining of the file +var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string +var_dump( ftell($file_handle) ); //File pointer position after write operation, expected at the end of the file +rewind($file_handle); +var_dump( fread($file_handle, 100) ); //Check for read operation; fails; expected: empty string +var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the begining of the file +var_dump( fclose($file_handle) ); //Check for close operation on the file handle +var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation +$file_handle = fopen($file, "xb"); //Opening the existing data file in 'xb' mode to check for the warning message +echo "*** Done ***\n"; +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/007_variation23.tmp"); +?> +--EXPECTF-- +*** Test fopen() & fclose() functions: with 'xb' mode *** +resource(5) of type (stream) +string(6) "stream" +int(0) +int(37) +int(37) +bool(false) +int(0) +bool(true) +string(7) "Unknown" + +Warning: fopen(%s): failed to open stream: File exists in %s on line %d +*** Done *** +--UEXPECTF-- +*** Test fopen() & fclose() functions: with 'xb' mode *** +resource(5) of type (stream) +unicode(6) "stream" +int(0) + +Notice: fwrite(): 37 character unicode buffer downcoded for binary stream runtime_encoding in %s on line %d +int(37) +int(37) +bool(false) +int(0) +bool(true) +unicode(7) "Unknown" + +Warning: fopen(%s): failed to open stream: File exists in %s on line %d +*** Done *** diff --git a/ext/standard/tests/file/007_variation24.phpt b/ext/standard/tests/file/007_variation24.phpt new file mode 100644 index 0000000000..fa8706e573 --- /dev/null +++ b/ext/standard/tests/file/007_variation24.phpt @@ -0,0 +1,78 @@ +--TEST-- +Test fopen and fclose() functions - usage variations - "x+b" mode +--FILE-- +<?php +/* + fopen() function: + Prototype: resource fopen(string $filename, string $mode + [, bool $use_include_path [, resource $context]] ); + Description: Opens file or URL. +*/ +/* + fclose() function: + Prototype: bool fclose ( resource $handle ); + Description: Closes an open file pointer +*/ + +/* Test fopen() and fclose(): Opening the file in "x+b" mode, + checking for the file creation, write & read operations, + checking for the file pointer position, + checking for the warning msg when trying to open an existing file in "x+b" mode, + and fclose function +*/ +$file_path = dirname(__FILE__); +$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; +$file = $file_path."/007_variation24.tmp"; + +echo "*** Test fopen() & fclose() functions: with 'x+b' mode ***\n"; +$file_handle = fopen($file, "x+b"); //opening the non-existing file in "x+b" mode, file will be created +var_dump($file_handle); //Check for the content of handle +var_dump( get_resource_type($file_handle) ); //Check for the type of resource +var_dump( ftell($file_handle) ); //Initial file pointer position, expected at the begining of the file +var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string +var_dump( ftell($file_handle) ); //File pointer position after write operation, expected at the end of the file +rewind($file_handle); +var_dump( fread($file_handle, 100) ); //Check for read operation; passes; expected: content of the file +var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the end of the file +var_dump( fclose($file_handle) ); //Check for close operation on the file handle +var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation +$file_handle = fopen($file, "x+b"); //Opening the existing data file in "x+b" mode to check for the warning message +echo "*** Done ***\n"; +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/007_variation24.tmp"); +?> +--EXPECTF-- +*** Test fopen() & fclose() functions: with 'x+b' mode *** +resource(5) of type (stream) +string(6) "stream" +int(0) +int(37) +int(37) +string(37) "abcdefghij +mnopqrst uvwxyz +0123456789" +int(37) +bool(true) +string(7) "Unknown" + +Warning: fopen(%s): failed to open stream: File exists in %s on line %d +*** Done *** +--UEXPECTF-- +*** Test fopen() & fclose() functions: with 'x+b' mode *** +resource(5) of type (stream) +unicode(6) "stream" +int(0) + +Notice: fwrite(): 37 character unicode buffer downcoded for binary stream runtime_encoding in %s on line %d +int(37) +int(37) +string(37) "abcdefghij +mnopqrst uvwxyz +0123456789" +int(37) +bool(true) +unicode(7) "Unknown" + +Warning: fopen(%s): failed to open stream: File exists in %s on line %d +*** Done *** diff --git a/ext/standard/tests/file/007_variation3.phpt b/ext/standard/tests/file/007_variation3.phpt new file mode 100644 index 0000000000..c209e06c36 --- /dev/null +++ b/ext/standard/tests/file/007_variation3.phpt @@ -0,0 +1,88 @@ +--TEST-- +Test fopen and fclose() functions - usage variations - "w" mode +--FILE-- +<?php +/* + fopen() function: + Prototype: resource fopen(string $filename, string $mode + [, bool $use_include_path [, resource $context]] ); + Description: Opens file or URL. +*/ +/* + fclose() function: + Prototype: bool fclose ( resource $handle ); + Description: Closes an open file pointer +*/ + +/* Test fopen() and fclose(): Opening the file in "w" mode, + checking for the file creation, write & read operations, + checking for the file pointer position, + checking for the file truncation when trying to open an existing file in "w" mode, + and fclose function +*/ +$file_path = dirname(__FILE__); +require($file_path."/file.inc"); + +create_files($file_path, 1, "text_with_new_line", 0755, 20, "w", "007_variation", 3, "bytes"); +$file = $file_path."/007_variation3.tmp"; +$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; + +echo "*** Test fopen() & fclose() functions: with 'w' mode ***\n"; +$file_handle = fopen($file, "w"); //opening the file "w" mode +var_dump($file_handle); //Check for the content of handle +var_dump( get_resource_type($file_handle) ); //Check for the type of resource +var_dump( ftell($file_handle) ); //Initial file pointer position, expected at the begining of the file +var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string +var_dump( ftell($file_handle) ); //File pointer position after write operation, expected at the end of the file +rewind($file_handle); +var_dump( fread($file_handle, 100) ); //Check for read operation; fails; expected: bool(false) +var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the begining of the file +var_dump( fclose($file_handle) ); //Check for close operation on the file handle +var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation + +var_dump( filesize($file) ); //Check for size of existing data file before opening the file in "w" mode again, expected: size of content +clearstatcache(); +fclose( fopen($file, "w") ); //Opening the existing data file again in "w" mode +var_dump( filesize($file) ); //Check for size of existing data file after opening the file in "w" mode again, expected: 0 bytes +clearstatcache(); + +unlink($file); //Deleting the file +fclose( fopen($file, "w") ); //Opening the non-existing file in "w" mode, which will be created +var_dump( file_exists($file) ); //Check for the existance of file +echo "*** Done ***\n"; +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/007_variation3.tmp"); +?> +--EXPECTF-- +*** Test fopen() & fclose() functions: with 'w' mode *** +resource(8) of type (stream) +string(6) "stream" +int(0) +int(37) +int(37) +bool(false) +int(0) +bool(true) +string(7) "Unknown" +int(37) +int(0) +bool(true) +*** Done *** +--UEXPECTF-- +*** Test fopen() & fclose() functions: with 'w' mode *** +resource(8) of type (stream) +unicode(6) "stream" +int(0) + +Notice: fwrite(): 37 character unicode buffer downcoded for binary stream runtime_encoding in %s on line %d +int(37) +int(37) +bool(false) +int(0) +bool(true) +unicode(7) "Unknown" +int(37) +int(0) +bool(true) +*** Done *** diff --git a/ext/standard/tests/file/007_variation4.phpt b/ext/standard/tests/file/007_variation4.phpt new file mode 100644 index 0000000000..1837a9c15b --- /dev/null +++ b/ext/standard/tests/file/007_variation4.phpt @@ -0,0 +1,92 @@ +--TEST-- +Test fopen and fclose() functions - usage variations - "w+" mode +--FILE-- +<?php +/* + fopen() function: + Prototype: resource fopen(string $filename, string $mode + [, bool $use_include_path [, resource $context]] ); + Description: Opens file or URL. +*/ +/* + fclose() function: + Prototype: bool fclose ( resource $handle ); + Description: Closes an open file pointer +*/ + +/* Test fopen() and fclose(): Opening the file in "w+" mode, + checking for the file creation, write & read operations, + checking for the file pointer position, + checking for the file truncation when trying to open an existing file in "w+" mode, + and fclose function +*/ +$file_path = dirname(__FILE__); +require($file_path."/file.inc"); + +create_files($file_path, 1, "text_with_new_line", 0755, 20, "w", "007_variation", 4, "bytes"); +$file = $file_path."/007_variation4.tmp"; +$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; + +echo "*** Test fopen() & fclose() functions: with 'w+' mode ***\n"; +$file_handle = fopen($file, "w+"); //opening the file "w+" mode +var_dump($file_handle); //Check for the content of handle +var_dump( get_resource_type($file_handle) ); //Check for the type of resource +var_dump( ftell($file_handle) ); //Initial file pointer position, expected at the begining of the file +var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string +var_dump( ftell($file_handle) ); //File pointer position after write operation, expected at the end of the file +rewind($file_handle); +var_dump( fread($file_handle, 100) ); //Check for read operation; passes; expected: content of file +var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the end of the file +var_dump( fclose($file_handle) ); //Check for close operation on the file handle +var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation + +var_dump( filesize($file) ); //Check for size of existing data file before opening the file in "w+" mode again, expected: size of content +clearstatcache(); +fclose( fopen($file, "w+") ); //Opening the existing data file again in "w+" mode +var_dump( filesize($file) ); //Check for size of existing data file after opening the file in "w+" mode again, expected: 0 bytes +clearstatcache(); + +unlink($file); //Deleting the file +fclose( fopen($file, "w+") ); //Opening the non-existing file in "w+" mode, which will be created +var_dump( file_exists($file) ); //Check for the existance of file +echo "*** Done ***\n"; +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/007_variation4.tmp"); +?> +--EXPECTF-- +*** Test fopen() & fclose() functions: with 'w+' mode *** +resource(8) of type (stream) +string(6) "stream" +int(0) +int(37) +int(37) +string(37) "abcdefghij +mnopqrst uvwxyz +0123456789" +int(37) +bool(true) +string(7) "Unknown" +int(37) +int(0) +bool(true) +*** Done *** +--UEXPECTF-- +*** Test fopen() & fclose() functions: with 'w+' mode *** +resource(8) of type (stream) +unicode(6) "stream" +int(0) + +Notice: fwrite(): 37 character unicode buffer downcoded for binary stream runtime_encoding in %s on line %d +int(37) +int(37) +string(37) "abcdefghij +mnopqrst uvwxyz +0123456789" +int(37) +bool(true) +unicode(7) "Unknown" +int(37) +int(0) +bool(true) +*** Done *** diff --git a/ext/standard/tests/file/007_variation5.phpt b/ext/standard/tests/file/007_variation5.phpt new file mode 100644 index 0000000000..2bc28b0e90 --- /dev/null +++ b/ext/standard/tests/file/007_variation5.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test fopen and fclose() functions - usage variations - "a" mode +--FILE-- +<?php +/* + fopen() function: + Prototype: resource fopen(string $filename, string $mode + [, bool $use_include_path [, resource $context]] ); + Description: Opens file or URL. +*/ +/* + fclose() function: + Prototype: bool fclose ( resource $handle ); + Description: Closes an open file pointer +*/ + +/* Test fopen() and fclose(): Opening the file in "a" mode, + checking for the file creation, write & read operations, + checking for the file pointer position, + and fclose function +*/ +$file_path = dirname(__FILE__); +require($file_path."/file.inc"); + +create_files($file_path, 1, "text_with_new_line", 0755, 20, "w", "007_variation", 5, "bytes"); +$file = $file_path."/007_variation5.tmp"; +$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; + +echo "*** Test fopen() & fclose() functions: with 'a' mode ***\n"; +$file_handle = fopen($file, "a"); //opening the file "a" mode +var_dump($file_handle); //Check for the content of handle +var_dump( get_resource_type($file_handle) ); //Check for the type of resource +var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string +rewind($file_handle); +var_dump( fread($file_handle, 100) ); //Check for read operation; fails; expected: empty string +var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the end of the file +var_dump( fclose($file_handle) ); //Check for close operation on the file handle +var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation +var_dump( filesize($file) ); //Check that data hasn't over written; Expected: Size of (initial data + newly added data) + +unlink($file); //Deleting the file +fclose( fopen($file, "a") ); //Opening the non-existing file in "a" mode, which will be created +var_dump( file_exists($file) ); //Check for the existance of file +echo "*** Done ***\n"; +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/007_variation5.tmp"); +?> +--EXPECTF-- +*** Test fopen() & fclose() functions: with 'a' mode *** +resource(8) of type (stream) +string(6) "stream" +int(37) +bool(false) +int(0) +bool(true) +string(7) "Unknown" +int(57) +bool(true) +*** Done *** +--UEXPECTF-- +*** Test fopen() & fclose() functions: with 'a' mode *** +resource(8) of type (stream) +unicode(6) "stream" + +Notice: fwrite(): 37 character unicode buffer downcoded for binary stream runtime_encoding in %s on line %d +int(37) +bool(false) +int(0) +bool(true) +unicode(7) "Unknown" +int(57) +bool(true) +*** Done *** diff --git a/ext/standard/tests/file/007_variation6.phpt b/ext/standard/tests/file/007_variation6.phpt new file mode 100644 index 0000000000..48e93e2aeb --- /dev/null +++ b/ext/standard/tests/file/007_variation6.phpt @@ -0,0 +1,79 @@ +--TEST-- +Test fopen and fclose() functions - usage variations - "a+" mode +--FILE-- +<?php +/* + fopen() function: + Prototype: resource fopen(string $filename, string $mode + [, bool $use_include_path [, resource $context]] ); + Description: Opens file or URL. +*/ +/* + fclose() function: + Prototype: bool fclose ( resource $handle ); + Description: Closes an open file pointer +*/ + +/* Test fopen() and fclose(): Opening the file in "a+" mode, + checking for the file creation, write & read operations, + checking for the file pointer position, + and fclose function +*/ +$file_path = dirname(__FILE__); +require($file_path."/file.inc"); + +create_files($file_path, 1, "text_with_new_line", 0755, 20, "w", "007_variation", 6, "bytes"); +$file = $file_path."/007_variation6.tmp"; +$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; + +echo "*** Test fopen() & fclose() functions: with 'a+' mode ***\n"; +$file_handle = fopen($file, "a+"); //opening the file "a+" mode +var_dump($file_handle); //Check for the content of handle +var_dump( get_resource_type($file_handle) ); //Check for the type of resource +var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string +rewind($file_handle); +var_dump( fread($file_handle, 100) ); //Check for read operation; passes; expected: content of file +var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the end of the file +var_dump( fclose($file_handle) ); //Check for close operation on the file handle +var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation + +unlink($file); //Deleting the file +fclose( fopen($file, "a+") ); //Opening the non-existing file in "a+" mode, which will be created +var_dump( file_exists($file) ); //Check for the existance of file +echo "*** Done ***\n"; +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/007_variation6.tmp"); +?> +--EXPECTF-- +*** Test fopen() & fclose() functions: with 'a+' mode *** +resource(8) of type (stream) +string(6) "stream" +int(37) +string(57) "line +line of text +liabcdefghij +mnopqrst uvwxyz +0123456789" +int(57) +bool(true) +string(7) "Unknown" +bool(true) +*** Done *** +--UEXPECTF-- +*** Test fopen() & fclose() functions: with 'a+' mode *** +resource(8) of type (stream) +unicode(6) "stream" + +Notice: fwrite(): 37 character unicode buffer downcoded for binary stream runtime_encoding in %s on line %d +int(37) +string(57) "line +line of text +liabcdefghij +mnopqrst uvwxyz +0123456789" +int(57) +bool(true) +unicode(7) "Unknown" +bool(true) +*** Done *** diff --git a/ext/standard/tests/file/007_variation7.phpt b/ext/standard/tests/file/007_variation7.phpt new file mode 100644 index 0000000000..ad9736d4a2 --- /dev/null +++ b/ext/standard/tests/file/007_variation7.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test fopen and fclose() functions - usage variations - "x" mode +--FILE-- +<?php +/* + fopen() function: + Prototype: resource fopen(string $filename, string $mode + [, bool $use_include_path [, resource $context]] ); + Description: Opens file or URL. +*/ +/* + fclose() function: + Prototype: bool fclose ( resource $handle ); + Description: Closes an open file pointer +*/ + +/* Test fopen() and fclose(): Opening the file in "x" mode, + checking for the file creation, write & read operations, + checking for the file pointer position, + checking for the warning msg when trying to open an existing file in "x" mode, + and fclose function +*/ +$file_path = dirname(__FILE__); +$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; +$file = $file_path."/007_variation7.tmp"; + +echo "*** Test fopen() & fclose() functions: with 'x' mode ***\n"; +$file_handle = fopen($file, "x"); //opening the non-existing file in "x" mode, file will be created +var_dump($file_handle); //Check for the content of handle +var_dump( get_resource_type($file_handle) ); //Check for the type of resource +var_dump( ftell($file_handle) ); //Initial file pointer position, expected at the begining of the file +var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string +var_dump( ftell($file_handle) ); //File pointer position after write operation, expected at the end of the file +rewind($file_handle); +var_dump( fread($file_handle, 100) ); //Check for read operation; fails; expected: empty string +var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the begining of the file +var_dump( fclose($file_handle) ); //Check for close operation on the file handle +var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation +$file_handle = fopen($file, "x"); //Opening the existing data file in 'x' mode to check for the warning message +echo "*** Done ***\n"; +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/007_variation7.tmp"); +?> +--EXPECTF-- +*** Test fopen() & fclose() functions: with 'x' mode *** +resource(5) of type (stream) +string(6) "stream" +int(0) +int(37) +int(37) +bool(false) +int(0) +bool(true) +string(7) "Unknown" + +Warning: fopen(%s): failed to open stream: File exists in %s on line %s +*** Done *** +--UEXPECTF-- +*** Test fopen() & fclose() functions: with 'x' mode *** +resource(5) of type (stream) +unicode(6) "stream" +int(0) + +Notice: fwrite(): 37 character unicode buffer downcoded for binary stream runtime_encoding in %s on line %d +int(37) +int(37) +bool(false) +int(0) +bool(true) +unicode(7) "Unknown" + +Warning: fopen(%s): failed to open stream: File exists in %s on line %d +*** Done *** diff --git a/ext/standard/tests/file/007_variation8.phpt b/ext/standard/tests/file/007_variation8.phpt new file mode 100644 index 0000000000..d0a0e93b4a --- /dev/null +++ b/ext/standard/tests/file/007_variation8.phpt @@ -0,0 +1,78 @@ +--TEST-- +Test fopen and fclose() functions - usage variations - "x+" mode +--FILE-- +<?php +/* + fopen() function: + Prototype: resource fopen(string $filename, string $mode + [, bool $use_include_path [, resource $context]] ); + Description: Opens file or URL. +*/ +/* + fclose() function: + Prototype: bool fclose ( resource $handle ); + Description: Closes an open file pointer +*/ + +/* Test fopen() and fclose(): Opening the file in "x+" mode, + checking for the file creation, write & read operations, + checking for the file pointer position, + checking for the warning msg when trying to open an existing file in "x+" mode, + and fclose function +*/ +$file_path = dirname(__FILE__); +$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; +$file = $file_path."/007_variation8.tmp"; + +echo "*** Test fopen() & fclose() functions: with 'x+' mode ***\n"; +$file_handle = fopen($file, "x+"); //opening the non-existing file in "x+" mode, file will be created +var_dump($file_handle); //Check for the content of handle +var_dump( get_resource_type($file_handle) ); //Check for the type of resource +var_dump( ftell($file_handle) ); //Initial file pointer position, expected at the begining of the file +var_dump( fwrite($file_handle, $string) ); //Check for write operation; passes; expected:size of the $string +var_dump( ftell($file_handle) ); //File pointer position after write operation, expected at the end of the file +rewind($file_handle); +var_dump( fread($file_handle, 100) ); //Check for read operation; passes; expected: content of the file +var_dump( ftell($file_handle) ); //File pointer position after read operation, expected at the end of the file +var_dump( fclose($file_handle) ); //Check for close operation on the file handle +var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation +$file_handle = fopen($file, "x+"); //Opening the existing data file in "x+" mode to check for the warning message +echo "*** Done ***\n"; +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/007_variation8.tmp"); +?> +--EXPECTF-- +*** Test fopen() & fclose() functions: with 'x+' mode *** +resource(5) of type (stream) +string(6) "stream" +int(0) +int(37) +int(37) +string(37) "abcdefghij +mnopqrst uvwxyz +0123456789" +int(37) +bool(true) +string(7) "Unknown" + +Warning: fopen(%s): failed to open stream: File exists in %s on line %d +*** Done *** +--UEXPECTF-- +*** Test fopen() & fclose() functions: with 'x+' mode *** +resource(5) of type (stream) +unicode(6) "stream" +int(0) + +Notice: fwrite(): 37 character unicode buffer downcoded for binary stream runtime_encoding in %s on line %d +int(37) +int(37) +string(37) "abcdefghij +mnopqrst uvwxyz +0123456789" +int(37) +bool(true) +unicode(7) "Unknown" + +Warning: fopen(%s): failed to open stream: File exists in %s on line %d +*** Done *** diff --git a/ext/standard/tests/file/007_variation9.phpt b/ext/standard/tests/file/007_variation9.phpt new file mode 100644 index 0000000000..e69b66625e --- /dev/null +++ b/ext/standard/tests/file/007_variation9.phpt @@ -0,0 +1,68 @@ +--TEST-- +Test fopen and fclose() functions - usage variations - "rt" mode +--FILE-- +<?php +/* + fopen() function: + Prototype: resource fopen(string $filename, string $mode + [, bool $use_include_path [, resource $context]] ); + Description: Opens file or URL. +*/ +/* + fclose() function: + Prototype: bool fclose ( resource $handle ); + Description: Closes an open file pointer +*/ + +/* Test fopen() and fclose(): Opening the file in "rt" mode, + checking for the file creation, write & read operations, + checking for the file pointer position, + and fclose function +*/ +$file_path = dirname(__FILE__); +require($file_path."/file.inc"); + +create_files($file_path, 1, "text_with_new_line", 0755, 20, "w", "007_variation", 9, "bytes"); +$file = $file_path."/007_variation9.tmp"; +$string = "abcdefghij\nmnopqrst\tuvwxyz\n0123456789"; + +echo "*** Test fopen() & fclose() functions: with 'rt' mode ***\n"; +$file_handle = fopen($file, "rt"); //opening the file in "rt" mode +var_dump($file_handle); //Check for the content of handle +var_dump( get_resource_type($file_handle) ); //Check for the type of resource +var_dump( ftell($file_handle) ); //Initial position of file pointer +var_dump( fread($file_handle, 100) ); //Check for read operation +var_dump( fwrite($file_handle, $string) ); //Check for write operation; fails; expected: 0 bytes +var_dump( fclose($file_handle) ); //Check for close operation on the file handle +var_dump( get_resource_type($file_handle) ); //Check whether resource is lost after close operation +echo "*** Done ***\n"; +--CLEAN-- +<?php +unlink(dirname(__FILE__)."/007_variation9.tmp"); +?> +--EXPECTF-- +*** Test fopen() & fclose() functions: with 'rt' mode *** +resource(8) of type (stream) +string(6) "stream" +int(0) +string(20) "line +line of text +li" +int(0) +bool(true) +string(7) "Unknown" +*** Done *** +--UEXPECTF-- +*** Test fopen() & fclose() functions: with 'rt' mode *** +resource(8) of type (stream) +unicode(6) "stream" +int(0) +unicode(20) "line +line of text +li" + +Notice: fwrite(): 37 character unicode buffer downcoded for binary stream runtime_encoding in %s on line %d +int(0) +bool(true) +unicode(7) "Unknown" +*** Done *** |