1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
--TEST--
SPL: CachingIterator and offsetSet/Unset, getCache using flag FULL_CACHE
--FILE--
<?php
class MyFoo
{
function __toString()
{
return 'foo';
}
}
class MyCachingIterator extends CachingIterator
{
function __construct(Iterator $it, $flags = 0)
{
parent::__construct($it, $flags);
}
function testSet($ar)
{
echo __METHOD__ . "()\n";
foreach($ar as $k => $v)
{
echo "set($k,$v)\n";
$this->offsetSet($k, $v);
}
}
function testUnset($ar)
{
echo __METHOD__ . "()\n";
foreach($ar as $k => $v)
{
echo "unset($v)\n";
$this->offsetUnset($v);
}
}
function fill()
{
echo __METHOD__ . "()\n";
foreach($this as $v) ;
}
function show()
{
echo __METHOD__ . "()\n";
var_dump($this->getCache());
}
}
$it = new MyCachingIterator(new ArrayIterator(array(0, 'foo'=>1, 2, 'bar'=>3, 4)));
try
{
var_dump($it->offsetSet(0, 0));
}
catch(Exception $e)
{
echo "Exception: " . $e->getMessage() . "\n";
}
try
{
var_dump($it->offsetUnset(0));
}
catch(Exception $e)
{
echo "Exception: " . $e->getMessage() . "\n";
}
$it = new MyCachingIterator(new ArrayIterator(array(0, 1, 2, 3)), CachingIterator::FULL_CACHE);
var_dump($it->offsetSet());
var_dump($it->offsetSet(0));
var_dump($it->offsetUnset());
$checks = array(0 => 25, 1 => 42, 3 => 'FooBar');
$unsets = array(0, 2);
$it->testSet($checks);
$it->show();
$it->testUnset($unsets);
$it->show();
$it->fill();
$it->show();
$it->testSet($checks);
$it->show();
$it->testUnset($unsets);
$it->show();
?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
Exception: MyCachingIterator does not use a full cache (see CachingIterator::__construct)
Exception: MyCachingIterator does not use a full cache (see CachingIterator::__construct)
Warning: CachingIterator::offsetSet() expects exactly 2 parameters, 0 given in %siterator_045.php on line %d
NULL
Warning: CachingIterator::offsetSet() expects exactly 2 parameters, 1 given in %siterator_045.php on line %d
NULL
Warning: CachingIterator::offsetUnset() expects exactly 1 parameter, 0 given in %siterator_045.php on line %d
NULL
MyCachingIterator::testSet()
set(0,25)
set(1,42)
set(3,FooBar)
MyCachingIterator::show()
array(3) {
[0]=>
int(25)
[1]=>
int(42)
[3]=>
string(6) "FooBar"
}
MyCachingIterator::testUnset()
unset(0)
unset(2)
MyCachingIterator::show()
array(2) {
[1]=>
int(42)
[3]=>
string(6) "FooBar"
}
MyCachingIterator::fill()
MyCachingIterator::show()
array(4) {
[0]=>
int(0)
[1]=>
int(1)
[2]=>
int(2)
[3]=>
int(3)
}
MyCachingIterator::testSet()
set(0,25)
set(1,42)
set(3,FooBar)
MyCachingIterator::show()
array(4) {
[0]=>
int(25)
[1]=>
int(42)
[2]=>
int(2)
[3]=>
string(6) "FooBar"
}
MyCachingIterator::testUnset()
unset(0)
unset(2)
MyCachingIterator::show()
array(2) {
[1]=>
int(42)
[3]=>
string(6) "FooBar"
}
===DONE===
|