Annotation of embedaddon/php/ext/spl/tests/iterator_045.phpt, revision 1.1

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>