]> granicus.if.org Git - php/commitdiff
New tests from testfest
authorEtienne Kneuss <colder@php.net>
Sat, 24 May 2008 16:49:04 +0000 (16:49 +0000)
committerEtienne Kneuss <colder@php.net>
Sat, 24 May 2008 16:49:04 +0000 (16:49 +0000)
ext/spl/tests/fileobject_005.phpt [new file with mode: 0644]
ext/spl/tests/heap_009.phpt [new file with mode: 0644]

diff --git a/ext/spl/tests/fileobject_005.phpt b/ext/spl/tests/fileobject_005.phpt
new file mode 100644 (file)
index 0000000..c65da83
--- /dev/null
@@ -0,0 +1,42 @@
+--TEST--
+SPL: SplFileObject truncate tests
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--CREDITS--
+Mark Ammann
+#Hackday Webtuesday 2008-05-24
+--FILE--
+<?php
+
+set_include_path(dirname(dirname(__FILE__)));
+
+$path = dirname(__FILE__).DIRECTORY_SEPARATOR.'fileobject_005.txt';
+touch($path);
+
+$fo = new SplFileObject('tests'.DIRECTORY_SEPARATOR.'fileobject_005.txt', 'w+', true);
+$fo->fwrite("blahlubba");
+var_dump($fo->ftruncate(4));
+
+$fo->rewind();
+var_dump($fo->fgets(8));
+
+$fo->rewind();
+$fo->fwrite("blahlubba");
+
+// This should throw a warning and return NULL since an argument is missing 
+var_dump($fo->ftruncate());
+
+?>
+==DONE==
+--CLEAN--
+<?php
+$path = dirname(__FILE__).DIRECTORY_SEPARATOR.'fileobject_005.txt';
+unlink($path);
+?>
+--EXPECTF--
+bool(true)
+string(4) "blah"
+
+Warning: SplFileObject::ftruncate() expects exactly 1 parameter, 0 given in %s on line %d
+NULL
+==DONE==
diff --git a/ext/spl/tests/heap_009.phpt b/ext/spl/tests/heap_009.phpt
new file mode 100644 (file)
index 0000000..b6dad3d
--- /dev/null
@@ -0,0 +1,58 @@
+--TEST--
+SPL: SplHeap and friends, throw: An iterator cannot be used with foreach by reference
+--CREDITS--
+Thomas Koch <thomas@koch.ro>
+#Hackday Webtuesday 2008-05-24
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--FILE--
+<?php
+function testForException( $heap )
+{
+    try
+    {
+        foreach( $heap as &$item );
+    }
+    catch( RuntimeException $e )
+    {
+        echo $e->getMessage(),"\n";
+    }
+}
+
+// 1. SplMinHeap emtpy
+$heap = new SplMinHeap;
+testForException( $heap );
+
+// 2. SplMinHeap non-emtpy
+$heap = new SplMinHeap;
+$heap->insert( 1 );
+testForException( $heap );
+
+// 3. SplMaxHeap emtpy
+$heap = new SplMaxHeap;
+testForException( $heap );
+
+// 4. SplMaxHeap non-emtpy
+$heap = new SplMaxHeap;
+$heap->insert( 1 );
+testForException( $heap );
+
+// 5. SplPriorityQueue empty
+$heap = new SplPriorityQueue;
+testForException( $heap );
+
+// 6. SplPriorityQueue non-empty
+$heap = new SplPriorityQueue;
+$heap->insert( 1, 2 );
+testForException( $heap );
+
+?>
+==DONE==
+--EXPECT--
+An iterator cannot be used with foreach by reference
+An iterator cannot be used with foreach by reference
+An iterator cannot be used with foreach by reference
+An iterator cannot be used with foreach by reference
+An iterator cannot be used with foreach by reference
+An iterator cannot be used with foreach by reference
+==DONE==