helly Tue Apr 13 15:06:39 2004 EDT
Added files:
/php-src/ext/spl/tests array_001.phpt array_002.phpt array_003.phpt
array_004.phpt array_005.phpt
Removed files:
/php-src/ext/spl/tests array_iterator.phpt array_object.phpt
array_object_iterator.phpt
Log:
New tests (and ordering of tests)
http://cvs.php.net/co.php/php-src/ext/spl/tests/array_001.phpt?r=1.1&p=1
Index: php-src/ext/spl/tests/array_001.phpt
+++ php-src/ext/spl/tests/array_001.phpt
--TEST--
SPL: ArrayObject
--SKIPIF--
<?php if (!extension_loaded("spl")) print "skip"; ?>
--FILE--
<?php
$ar = array(0=>0, 1=>1);
$ar = new ArrayObject($ar);
var_dump($ar);
$ar[2] = 2;
var_dump($ar[2]);
var_dump($ar["3"] = 3);
var_dump(array_merge((array)$ar, array(4=>4, 5=>5)));
var_dump($ar["a"] = "a");
var_dump($ar);
var_dump($ar[0]);
var_dump($ar[6]);
var_dump($ar["b"]);
unset($ar[1]);
unset($ar["3"]);
unset($ar["a"]);
unset($ar[7]);
unset($ar["c"]);
var_dump($ar);
$ar[] = '3';
$ar[] = 4;
var_dump($ar);
?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
object(ArrayObject)#1 (2) {
[0]=>
int(0)
[1]=>
int(1)
}
int(2)
int(3)
array(6) {
[0]=>
int(0)
[1]=>
int(1)
[2]=>
int(2)
[3]=>
int(3)
[4]=>
int(4)
[5]=>
int(5)
}
string(1) "a"
object(ArrayObject)#1 (5) {
[0]=>
int(0)
[1]=>
int(1)
[2]=>
int(2)
[3]=>
int(3)
["a"]=>
string(1) "a"
}
int(0)
Notice: Undefined offset: 6 in %sarray_object.php on line %d
NULL
Notice: Undefined index: b in %sarray_object.php on line %d
NULL
Notice: Undefined offset: 7 in %sarray_object.php on line %d
Notice: Undefined index: c in %sarray_object.php on line %d
object(ArrayObject)#1 (2) {
[0]=>
int(0)
[2]=>
int(2)
}
object(ArrayObject)#1 (4) {
[0]=>
int(0)
[2]=>
int(2)
[4]=>
string(1) "3"
[5]=>
int(4)
}
===DONE===
http://cvs.php.net/co.php/php-src/ext/spl/tests/array_002.phpt?r=1.1&p=1
Index: php-src/ext/spl/tests/array_002.phpt
+++ php-src/ext/spl/tests/array_002.phpt
--TEST--
SPL: ArrayObject copy constructor
--SKIPIF--
<?php if (!extension_loaded("spl")) print "skip"; ?>
--FILE--
<?php
$array = array('1' => 'one',
'2' => 'two',
'3' => 'three');
$object = new ArrayObject($array);
$object[] = 'four';
$arrayObject = new ArrayObject($object);
$arrayObject[] = 'five';
var_dump($arrayObject);
?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
object(ArrayObject)#%d (5) {
[1]=>
string(3) "one"
[2]=>
string(3) "two"
[3]=>
string(5) "three"
[4]=>
string(4) "four"
[5]=>
string(4) "five"
}
===DONE===
http://cvs.php.net/co.php/php-src/ext/spl/tests/array_003.phpt?r=1.1&p=1
Index: php-src/ext/spl/tests/array_003.phpt
+++ php-src/ext/spl/tests/array_003.phpt
--TEST--
SPL: ArrayObject from object
--SKIPIF--
<?php if (!extension_loaded("spl")) print "skip"; ?>
--FILE--
<?php
class test
{
public $pub = "public";
protected $pro = "protected";
private $pri = "private";
function __construct()
{
$this->imp = "implicit";
}
};
$test = new test;
$test->dyn = "dynamic";
print_r($test);
$object = new ArrayObject($test);
print_r($object);
?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
test Object
(
[pub] => public
[pro:protected] => protected
[pri:private] => private
[imp] => implicit
[dyn] => dynamic
)
ArrayObject Object
(
[pub] => public
[pro:protected] => protected
[pri:private] => private
[imp] => implicit
[dyn] => dynamic
)
===DONE===
http://cvs.php.net/co.php/php-src/ext/spl/tests/array_004.phpt?r=1.1&p=1
Index: php-src/ext/spl/tests/array_004.phpt
+++ php-src/ext/spl/tests/array_004.phpt
--TEST--
SPL: ArrayIterator
--SKIPIF--
<?php if (!extension_loaded("spl")) print "skip"; ?>
--INI--
allow_call_time_pass_reference=1
--FILE--
<?php
echo "==Normal==\n";
$arr = array(0=>0, 1=>1, 2=>2);
$obj = new ArrayObject($arr);
foreach($obj as $ak=>$av) {
foreach($obj as $bk=>$bv) {
if ($ak==0 && $bk==0) {
$arr[0] = "modify";
}
echo "$ak=>$av - $bk=>$bv\n";
}
}
echo "==UseRef==\n";
$arr = array(0=>0, 1=>1, 2=>2);
$obj = new ArrayObject(&$arr);
foreach($obj as $ak=>$av) {
foreach($obj as $bk=>$bv) {
if ($ak==0 && $bk==0) {
$arr[0] = "modify";
}
echo "$ak=>$av - $bk=>$bv\n";
}
}
echo "==Modify==\n";
$arr = array(0=>0, 1=>1, 2=>2);
$obj = new ArrayObject(&$arr);
foreach($obj as $ak=>$av) {
foreach($obj as $bk=>$bv) {
if ($ak==0 && $bk==0) {
$arr[0] = "modify";
}
echo "$ak=>$av - $bk=>$bv\n";
}
}
echo "==Delete==\n";
$arr = array(0=>0, 1=>1, 2=>2);
$obj = new ArrayObject(&$arr);
foreach($obj as $ak=>$av) {
foreach($obj as $bk=>$bv) {
if ($ak==1 && $bk==1) {
unset($arr[1]);
}
echo "$ak=>$av - $bk=>$bv\n";
}
}
echo "==Change==\n";
$arr = array(0=>0, 1=>1, 2=>2);
$obj = new ArrayObject(&$arr);
foreach($obj as $ak=>$av) {
foreach($obj as $bk=>$bv) {
if ($ak==1 && $bk==1) {
$arr = NULL;
}
echo "$ak=>$av - $bk=>$bv\n";
}
}
echo "Done\n";
?>
--EXPECTF--
==Normal==
0=>0 - 0=>0
0=>0 - 1=>1
0=>0 - 2=>2
1=>1 - 0=>0
1=>1 - 1=>1
1=>1 - 2=>2
2=>2 - 0=>0
2=>2 - 1=>1
2=>2 - 2=>2
==UseRef==
0=>0 - 0=>0
0=>0 - 1=>1
0=>0 - 2=>2
1=>1 - 0=>modify
1=>1 - 1=>1
1=>1 - 2=>2
2=>2 - 0=>modify
2=>2 - 1=>1
2=>2 - 2=>2
==Modify==
0=>0 - 0=>0
0=>0 - 1=>1
0=>0 - 2=>2
1=>1 - 0=>modify
1=>1 - 1=>1
1=>1 - 2=>2
2=>2 - 0=>modify
2=>2 - 1=>1
2=>2 - 2=>2
==Delete==
0=>0 - 0=>0
0=>0 - 1=>1
0=>0 - 2=>2
1=>1 - 0=>0
1=>1 - 1=>1
Notice: ArrayIterator::next(): Array was modified outside object and internal position
is no longer valid in %sarray_iterator.php on line %d
1=>1 - 0=>0
1=>1 - 2=>2
Notice: ArrayIterator::next(): Array was modified outside object and internal position
is no longer valid in %sarray_iterator.php on line %d
0=>0 - 0=>0
0=>0 - 2=>2
2=>2 - 0=>0
2=>2 - 2=>2
==Change==
0=>0 - 0=>0
0=>0 - 1=>1
0=>0 - 2=>2
1=>1 - 0=>0
1=>1 - 1=>1
Notice: ArrayIterator::next(): Array was modified outside object and is no longer an
array in %sarray_iterator.php on line %d
Notice: ArrayIterator::valid(): Array was modified outside object and is no longer an
array in %sarray_iterator.php on line %d
Notice: ArrayIterator::next(): Array was modified outside object and is no longer an
array in %sarray_iterator.php on line %d
Notice: ArrayIterator::valid(): Array was modified outside object and is no longer an
array in %sarray_iterator.php on line %d
Done
http://cvs.php.net/co.php/php-src/ext/spl/tests/array_005.phpt?r=1.1&p=1
Index: php-src/ext/spl/tests/array_005.phpt
+++ php-src/ext/spl/tests/array_005.phpt
--TEST--
SPL: ArrayObject/Iterator interaction
--SKIPIF--
<?php if (!extension_loaded("spl")) print "skip"; ?>
--FILE--
<?php
class Student
{
private $id;
private $name;
public function __construct($id, $name)
{
$this->id = $id;
$this->name = $name;
}
public function __toString()
{
return $this->id . ', ' . $this->name;
}
public function getId()
{
return $this->id;
}
}
class StudentIdFilter extends FilterIterator
{
private $id;
public function __construct(ArrayObject $students, Student $other)
{
FilterIterator::__construct($students->getIterator());
$this->id = $other->getId();
}
public function accept()
{
echo "ACCEPT ".$this->current()->getId()." == ".$this->id."\n";
return $this->current()->getId() == $this->id;
}
}
class StudentList implements IteratorAggregate
{
private $students;
public function __construct()
{
$this->students = new ArrayObject(array());
}
public function add(Student $student)
{
if (!$this->contains($student)) {
$this->students[] = $student;
}
}
public function contains(Student $student)
{
foreach ($this->students as $s)
{
if ($s->getId() == $student->getId()) {
return true;
}
}
return false;
}
public function getIterator() {
return $this->students->getIterator();
}
}
$students = new StudentList();
$students->add(new Student('01234123', 'Joe'));
$students->add(new Student('00000014', 'Bob'));
$students->add(new Student('00000014', 'Foo'));
foreach ($students as $student) {
echo $student, "\n";
}
?>
===DONE===
<?php exit(0); ?>
--EXPECT--
01234123, Joe
00000014, Bob
===DONE===
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php