]> granicus.if.org Git - php/commitdiff
Commiting testfest tests from tek
authorZoe Slattery <zoe@php.net>
Wed, 3 Jun 2009 12:30:40 +0000 (12:30 +0000)
committerZoe Slattery <zoe@php.net>
Wed, 3 Jun 2009 12:30:40 +0000 (12:30 +0000)
12 files changed:
ext/spl/tests/SplFileObject_fflush_basic_001.phpt [new file with mode: 0644]
ext/spl/tests/SplFileObject_fpassthru_basic.phpt [new file with mode: 0644]
ext/spl/tests/SplFileObject_fscanf_basic.phpt [new file with mode: 0644]
ext/spl/tests/SplFileObject_fseek_error_001.phpt [new file with mode: 0644]
ext/spl/tests/SplFileObject_ftruncate_error_001.phpt [new file with mode: 0644]
ext/spl/tests/SplFileObject_fwrite_error_001.phpt [new file with mode: 0644]
ext/spl/tests/SplFileObject_fwrite_variation_001.phpt [new file with mode: 0644]
ext/spl/tests/SplFileObject_fwrite_variation_002.phpt [new file with mode: 0644]
ext/spl/tests/SplFileObject_fwrite_variation_003.phpt [new file with mode: 0644]
ext/spl/tests/SplFileObject_getCsvControl_basic_001.phpt [new file with mode: 0644]
ext/spl/tests/SplFileObject_seek_error_001.phpt [new file with mode: 0644]
ext/spl/tests/SplFileObject_testinput.csv [new file with mode: 0644]

diff --git a/ext/spl/tests/SplFileObject_fflush_basic_001.phpt b/ext/spl/tests/SplFileObject_fflush_basic_001.phpt
new file mode 100644 (file)
index 0000000..baab156
--- /dev/null
@@ -0,0 +1,35 @@
+--TEST--
+SplFileObject::fflush function - basic test 
+--FILE--
+<?php
+/*
+ * test a successful flush
+*/
+$obj = New SplFileObject(dirname(__FILE__).'/SplFileObject_testinput.csv');
+var_dump($obj->fflush());
+
+/*
+ * test a unsuccessful flush
+*/
+//create a basic stream class
+class VariableStream {
+    var $position;
+    var $varname;
+
+    function stream_open($path, $mode, $options, &$opened_path)
+    {  
+        return true;
+    }
+}
+stream_wrapper_register("SPLtest", "VariableStream");
+$ftruncate_test = "";
+//end creating stream
+
+//open an SplFileObject using the above test stream
+$obj = New SplFileObject("SPLtest://ftruncate_test");
+var_dump($obj->fflush());
+
+?>
+--EXPECTF--
+bool(true)
+bool(false)
diff --git a/ext/spl/tests/SplFileObject_fpassthru_basic.phpt b/ext/spl/tests/SplFileObject_fpassthru_basic.phpt
new file mode 100644 (file)
index 0000000..55b7481
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+SplFileObject::fpassthru function - basic functionality test 
+--FILE--
+<?php
+$obj = New SplFileObject(dirname(__FILE__).'/SplFileObject_testinput.csv');
+$obj->fpassthru();
+?>
+--EXPECT--
+first,second,third
+1,2,3
+4,5,6
+7,8,9
+0,0,0
diff --git a/ext/spl/tests/SplFileObject_fscanf_basic.phpt b/ext/spl/tests/SplFileObject_fscanf_basic.phpt
new file mode 100644 (file)
index 0000000..5279039
--- /dev/null
@@ -0,0 +1,12 @@
+--TEST--
+SplFileObject::fscanf function - basic functionality test 
+--FILE--
+<?php
+$obj = New SplFileObject(dirname(__FILE__).'/SplFileObject_testinput.csv');
+var_dump($obj->fscanf('%s'));
+?>
+--EXPECT--
+array(1) {
+  [0]=>
+  string(18) "first,second,third"
+}
diff --git a/ext/spl/tests/SplFileObject_fseek_error_001.phpt b/ext/spl/tests/SplFileObject_fseek_error_001.phpt
new file mode 100644 (file)
index 0000000..0efeb98
--- /dev/null
@@ -0,0 +1,12 @@
+--TEST--
+SplFileObject::fseek function - parameters test
+--FILE--
+<?php
+$obj = New SplFileObject(__FILE__);
+$obj->fseek(1,2,3);
+$obj->fseek();
+?>
+--EXPECTF--
+Warning: SplFileObject::fseek() expects at most 2 parameters, 3 given %s
+
+Warning: SplFileObject::fseek() expects at least 1 parameter, 0 given %s
diff --git a/ext/spl/tests/SplFileObject_ftruncate_error_001.phpt b/ext/spl/tests/SplFileObject_ftruncate_error_001.phpt
new file mode 100644 (file)
index 0000000..90b27ec
--- /dev/null
@@ -0,0 +1,29 @@
+--TEST--
+SplFileObject::ftruncate function - truncating with stream that does not support truncation 
+--FILE--
+<?php
+
+//create a basic stream class
+class VariableStream {
+    var $position;
+    var $varname;
+
+    function stream_open($path, $mode, $options, &$opened_path)
+    {
+        return true;
+    }
+}
+stream_wrapper_register("SPLtest", "VariableStream");
+$ftruncate_test = "";
+//end creating stream
+
+//open an SplFileObject using the above test stream
+$obj = New SplFileObject("SPLtest://ftruncate_test"); 
+try {
+       $obj->ftruncate(1);
+} catch (LogicException $e) {
+       echo($e->getMessage());
+}
+?>
+--EXPECTF--
+Can't truncate file %s
diff --git a/ext/spl/tests/SplFileObject_fwrite_error_001.phpt b/ext/spl/tests/SplFileObject_fwrite_error_001.phpt
new file mode 100644 (file)
index 0000000..296a1f3
--- /dev/null
@@ -0,0 +1,12 @@
+--TEST--
+SplFileObject::fpassthru function - parameters test 
+--FILE--
+<?php
+$obj = New SplFileObject(dirname(__FILE__).'/SplFileObject_testinput.csv');
+$obj->fwrite();
+$obj->fwrite('6,6,6',25,null);
+?>
+--EXPECTF--
+Warning: SplFileObject::fwrite() expects at least 1 parameter, 0 given in %s
+
+Warning: SplFileObject::fwrite() expects at most 2 parameters, 3 given in %s
diff --git a/ext/spl/tests/SplFileObject_fwrite_variation_001.phpt b/ext/spl/tests/SplFileObject_fwrite_variation_001.phpt
new file mode 100644 (file)
index 0000000..f8d518f
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+SplFileObject::fwrite function - writing with two parameters length < input string length
+--FILE--
+<?php
+$file = dirname(__FILE__).'/SplFileObject_fwrite_variation_001.txt';
+if(file_exists($file)) {
+       unlink($file);
+}
+$obj = New SplFileObject($file,'w');
+$obj->fwrite('test_write',4);
+var_dump(file_get_contents($file));
+if(file_exists($file)) {
+       unlink($file);
+}
+?>
+--EXPECT--
+string(4) "test"
diff --git a/ext/spl/tests/SplFileObject_fwrite_variation_002.phpt b/ext/spl/tests/SplFileObject_fwrite_variation_002.phpt
new file mode 100644 (file)
index 0000000..47b1332
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+SplFileObject::fwrite function - writing with two parameters, length > input string length
+--FILE--
+<?php
+$file = dirname(__FILE__).'/SplFileObject_fwrite_variation_002.txt';
+if(file_exists($file)) {
+       unlink($file);
+}
+$obj = New SplFileObject($file,'w');
+$obj->fwrite('test_write',12);
+var_dump(file_get_contents($file));
+if(file_exists($file)) {
+       unlink($file);
+}
+?>
+--EXPECT--
+string(10) "test_write"
diff --git a/ext/spl/tests/SplFileObject_fwrite_variation_003.phpt b/ext/spl/tests/SplFileObject_fwrite_variation_003.phpt
new file mode 100644 (file)
index 0000000..8e5c88e
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+SplFileObject::fwrite function - writing with magic_quotes_runtime ini set 
+--FILE--
+<?php
+ini_set('magic_quotes_runtime',true);
+$file = dirname(__FILE__).'/SplFileObject_fwrite_variation_002.txt';
+if(file_exists($file)) {
+       unlink($file);
+}
+$obj = New SplFileObject($file,'w');
+$obj->fwrite('"test" \'write\'');
+var_dump(file_get_contents($file));
+if(file_exists($file)) {
+       unlink($file);
+}
+?>
+--EXPECT--
+string(18) "\"test\" \'write\'"
diff --git a/ext/spl/tests/SplFileObject_getCsvControl_basic_001.phpt b/ext/spl/tests/SplFileObject_getCsvControl_basic_001.phpt
new file mode 100644 (file)
index 0000000..e21f08f
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+SplFileObject::getCsvControl function - basic test 
+--FILE--
+<?php
+$obj = New SplFileObject(dirname(__FILE__).'/SplFileObject_testinput.csv');
+var_dump($obj->getCsvControl());
+
+?>
+--EXPECTF--
+array(2) {
+  [0]=>
+  %unicode|string%(1) ","
+  [1]=>
+  %unicode|string%(1) """
+}
diff --git a/ext/spl/tests/SplFileObject_seek_error_001.phpt b/ext/spl/tests/SplFileObject_seek_error_001.phpt
new file mode 100644 (file)
index 0000000..bcf44b0
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+SplFileObject::seek function - test parameters
+--FILE--
+<?php
+$obj = New SplFileObject(__FILE__);
+$obj->seek(1,2);
+$obj->seek();
+try {
+       $obj->seek(-1);
+} catch (LogicException $e) {
+       echo($e->getMessage());
+}
+?>
+--EXPECTF--
+
+Warning: SplFileObject::seek() expects exactly 1 parameter, 2 given in %s
+
+Warning: SplFileObject::seek() expects exactly 1 parameter, 0 given in %s
+Can't seek file %s to negative line %s
diff --git a/ext/spl/tests/SplFileObject_testinput.csv b/ext/spl/tests/SplFileObject_testinput.csv
new file mode 100644 (file)
index 0000000..41a9e31
--- /dev/null
@@ -0,0 +1,5 @@
+first,second,third
+1,2,3
+4,5,6
+7,8,9
+0,0,0