New tests from testfest

This commit is contained in:
Etienne Kneuss 2008-05-24 16:49:04 +00:00
parent 5d4b2d2a1c
commit 3623b134e1
2 changed files with 100 additions and 0 deletions

View File

@ -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==

View File

@ -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==