diff options
Diffstat (limited to 'ext/standard')
27 files changed, 1722 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..c3a2ccc17a --- /dev/null +++ b/ext/standard/tests/file/007_variation1.phpt @@ -0,0 +1,54 @@ +--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 *** diff --git a/ext/standard/tests/file/007_variation10.phpt b/ext/standard/tests/file/007_variation10.phpt new file mode 100644 index 0000000000..ce6d293a9e --- /dev/null +++ b/ext/standard/tests/file/007_variation10.phpt @@ -0,0 +1,58 @@ +--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 *** 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..94017e7e54 --- /dev/null +++ b/ext/standard/tests/file/007_variation11-win32.phpt @@ -0,0 +1,76 @@ +--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) +string(0) "" +int(0) +bool(true) +string(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..aa75dfad77 --- /dev/null +++ b/ext/standard/tests/file/007_variation11.phpt @@ -0,0 +1,76 @@ +--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) +string(0) "" +int(0) +bool(true) +string(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..e439f441b8 --- /dev/null +++ b/ext/standard/tests/file/007_variation12-win32.phpt @@ -0,0 +1,78 @@ +--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 *** diff --git a/ext/standard/tests/file/007_variation12.phpt b/ext/standard/tests/file/007_variation12.phpt new file mode 100644 index 0000000000..bb6634fd0b --- /dev/null +++ b/ext/standard/tests/file/007_variation12.phpt @@ -0,0 +1,78 @@ +--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 *** 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..fa6c6db394 --- /dev/null +++ b/ext/standard/tests/file/007_variation13-win32.phpt @@ -0,0 +1,65 @@ +--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) +string(0) "" +int(0) +bool(true) +string(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..a0489ee770 --- /dev/null +++ b/ext/standard/tests/file/007_variation13.phpt @@ -0,0 +1,65 @@ +--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) +string(0) "" +int(0) +bool(true) +string(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..21f515c968 --- /dev/null +++ b/ext/standard/tests/file/007_variation14.phpt @@ -0,0 +1,62 @@ +--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 *** diff --git a/ext/standard/tests/file/007_variation15.phpt b/ext/standard/tests/file/007_variation15.phpt new file mode 100644 index 0000000000..018df41599 --- /dev/null +++ b/ext/standard/tests/file/007_variation15.phpt @@ -0,0 +1,58 @@ +--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) +string(0) "" +int(0) +bool(true) +string(7) "Unknown" + +Warning: fopen(%s): failed to open stream: File exists in %s on line %s +*** 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..8857338ccb --- /dev/null +++ b/ext/standard/tests/file/007_variation16.phpt @@ -0,0 +1,60 @@ +--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 *** diff --git a/ext/standard/tests/file/007_variation17.phpt b/ext/standard/tests/file/007_variation17.phpt new file mode 100644 index 0000000000..fd8dcc326a --- /dev/null +++ b/ext/standard/tests/file/007_variation17.phpt @@ -0,0 +1,54 @@ +--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 *** diff --git a/ext/standard/tests/file/007_variation18.phpt b/ext/standard/tests/file/007_variation18.phpt new file mode 100644 index 0000000000..2b43b5c3c9 --- /dev/null +++ b/ext/standard/tests/file/007_variation18.phpt @@ -0,0 +1,58 @@ +--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 *** diff --git a/ext/standard/tests/file/007_variation19.phpt b/ext/standard/tests/file/007_variation19.phpt new file mode 100644 index 0000000000..74f9ebe34b --- /dev/null +++ b/ext/standard/tests/file/007_variation19.phpt @@ -0,0 +1,71 @@ +--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) +string(0) "" +int(0) +bool(true) +string(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..774e4af87a --- /dev/null +++ b/ext/standard/tests/file/007_variation2.phpt @@ -0,0 +1,58 @@ +--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 ***
\ No newline at end of file diff --git a/ext/standard/tests/file/007_variation20.phpt b/ext/standard/tests/file/007_variation20.phpt new file mode 100644 index 0000000000..5a67beda2e --- /dev/null +++ b/ext/standard/tests/file/007_variation20.phpt @@ -0,0 +1,73 @@ +--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 *** diff --git a/ext/standard/tests/file/007_variation21.phpt b/ext/standard/tests/file/007_variation21.phpt new file mode 100644 index 0000000000..ccef2db300 --- /dev/null +++ b/ext/standard/tests/file/007_variation21.phpt @@ -0,0 +1,60 @@ +--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) +string(0) "" +int(0) +bool(true) +string(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..61c80e2229 --- /dev/null +++ b/ext/standard/tests/file/007_variation22.phpt @@ -0,0 +1,62 @@ +--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 *** diff --git a/ext/standard/tests/file/007_variation23.phpt b/ext/standard/tests/file/007_variation23.phpt new file mode 100644 index 0000000000..5f21164c5f --- /dev/null +++ b/ext/standard/tests/file/007_variation23.phpt @@ -0,0 +1,58 @@ +--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) +string(0) "" +int(0) +bool(true) +string(7) "Unknown" + +Warning: fopen(%s): failed to open stream: File exists in %s on line %s +*** 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..26130b55b1 --- /dev/null +++ b/ext/standard/tests/file/007_variation24.phpt @@ -0,0 +1,60 @@ +--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 *** diff --git a/ext/standard/tests/file/007_variation3.phpt b/ext/standard/tests/file/007_variation3.phpt new file mode 100644 index 0000000000..728f6e2c8a --- /dev/null +++ b/ext/standard/tests/file/007_variation3.phpt @@ -0,0 +1,71 @@ +--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: 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 "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) +string(0) "" +int(0) +bool(true) +string(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..b86e534ab1 --- /dev/null +++ b/ext/standard/tests/file/007_variation4.phpt @@ -0,0 +1,73 @@ +--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 ***
\ No newline at end of file diff --git a/ext/standard/tests/file/007_variation5.phpt b/ext/standard/tests/file/007_variation5.phpt new file mode 100644 index 0000000000..5cb9f44401 --- /dev/null +++ b/ext/standard/tests/file/007_variation5.phpt @@ -0,0 +1,60 @@ +--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) +string(0) "" +int(0) +bool(true) +string(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..4cd6494c18 --- /dev/null +++ b/ext/standard/tests/file/007_variation6.phpt @@ -0,0 +1,62 @@ +--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 *** diff --git a/ext/standard/tests/file/007_variation7.phpt b/ext/standard/tests/file/007_variation7.phpt new file mode 100644 index 0000000000..ffb97e38a6 --- /dev/null +++ b/ext/standard/tests/file/007_variation7.phpt @@ -0,0 +1,58 @@ +--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) +string(0) "" +int(0) +bool(true) +string(7) "Unknown" + +Warning: fopen(%s): failed to open stream: File exists in %s on line %s +*** 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..bad41136db --- /dev/null +++ b/ext/standard/tests/file/007_variation8.phpt @@ -0,0 +1,60 @@ +--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 *** diff --git a/ext/standard/tests/file/007_variation9.phpt b/ext/standard/tests/file/007_variation9.phpt new file mode 100644 index 0000000000..b9cc004f88 --- /dev/null +++ b/ext/standard/tests/file/007_variation9.phpt @@ -0,0 +1,54 @@ +--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 *** |