1
0
mirror of https://github.com/php/php-src.git synced 2026-04-14 19:41:05 +02:00

add more tests (Felipe)

This commit is contained in:
Antony Dovgal
2008-06-07 14:10:42 +00:00
parent 5d6b1c6ead
commit c80f146f81
10 changed files with 185 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
--TEST--
SPL: FastArray: Trying to instantiate passing object to constructor parameter
--FILE--
<?php
$b = new stdClass;
$a = new SplFastArray($b);
?>
--EXPECTF--
Warning: SplFastArray::__construct() expects parameter 1 to be long, object given in %s on line %d

View File

@@ -0,0 +1,22 @@
--TEST--
SPL: FastArray: Assigning objects
--FILE--
<?php
$b = 10000;
$a = new SplFastArray($b);
try {
for ($i = 0; $i < 100; $i++) {
$a[] = new stdClass;
}
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
print "ok\n";
?>
--EXPECT--
Index invalid or out of range
ok

View File

@@ -0,0 +1,26 @@
--TEST--
SPL: FastArray: Assigning the itself object
--FILE--
<?php
$b = 10;
$a = new SplFastArray($b);
try {
$a[1] = $a;
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
foreach ($a as $c) {
if ($c) {
echo $c->getSize(), "\n";
}
}
print "ok\n";
?>
--EXPECT--
10
ok

View File

@@ -0,0 +1,30 @@
--TEST--
SPL: FastArray: Assigning the itself object testing the reference
--FILE--
<?php
$b = 3;
$a = new SplFastArray($b);
$a[0] = 1;
$a[1] = 2;
$a[2] = $a;
$a[2][0] = 3;
foreach ($a as $x) {
if (is_object($x)) {
var_dump($x[0]);
} else {
var_dump($x);
}
}
var_dump($a->getSize());
?>
--EXPECT--
int(3)
int(2)
int(3)
int(3)

View File

@@ -0,0 +1,10 @@
--TEST--
SPL: FastArray: Trying to instantiate passing string to construtor parameter
--FILE--
<?php
$a = new SplFastArray('FOO');
?>
--EXPECTF--
Warning: SplFastArray::__construct() expects parameter 1 to be long, string given in %s on line %d

View File

@@ -0,0 +1,16 @@
--TEST--
SPL: FastArray: Setting size to 0
--FILE--
<?php
$a = new SplFastArray(1);
$a[0] = 1;
$a->setSize(0);
print "ok\n";
?>
--EXPECT--
ok

View File

@@ -0,0 +1,14 @@
--TEST--
SPL: FastArray: Testing setSize() with NULL
--FILE--
<?php
$a = new SplFastArray(100);
$a->setSize(NULL);
print "ok\n";
?>
--EXPECT--
ok

View File

@@ -0,0 +1,19 @@
--TEST--
SPL: FastArray: Assigning the object to another variable using []
--FILE--
<?php
$a = new SplFastArray(100);
try {
$b = &$a[];
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
print "ok\n";
?>
--EXPECT--
Index invalid or out of range
ok

View File

@@ -0,0 +1,21 @@
--TEST--
SPL: FastArray: Passing the object using [] as parameter
--FILE--
<?php
$a = new SplFastArray(100);
function test(SplFastArray &$arr) {
print "ok\n";
}
try {
test($a[]);
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
Index invalid or out of range

View File

@@ -0,0 +1,15 @@
--TEST--
SPL: FastArray: Trying to access inexistent item
--FILE--
<?php
try {
$a = new SplFastArray(NULL);
echo $a[0]++;
} catch (Exception $e) {
echo $e->getMessage();
}
?>
--EXPECT--
Index invalid or out of range