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

1.1     ! misho       1: --TEST--
        !             2: SPL: AppendIterator::append() rewinds when neccessary
        !             3: --FILE--
        !             4: <?php
        !             5: 
        !             6: class MyArrayIterator extends ArrayIterator
        !             7: {
        !             8:        function rewind()
        !             9:        {
        !            10:                echo __METHOD__ . "\n";
        !            11:                parent::rewind();
        !            12:        }
        !            13: }
        !            14: 
        !            15: $it = new MyArrayIterator(array(1,2));
        !            16: 
        !            17: foreach($it as $k=>$v)
        !            18: {
        !            19:        echo "$k=>$v\n";
        !            20: }
        !            21: 
        !            22: class MyAppendIterator extends AppendIterator
        !            23: {
        !            24:        function __construct()
        !            25:        {
        !            26:                echo __METHOD__ . "\n";
        !            27:        }
        !            28: 
        !            29:        function rewind()
        !            30:        {
        !            31:                echo __METHOD__ . "\n";
        !            32:                parent::rewind();
        !            33:        }
        !            34: 
        !            35:        function valid()
        !            36:        {
        !            37:                echo __METHOD__ . "\n";
        !            38:                return parent::valid();
        !            39:        }
        !            40:        
        !            41:        function append(Iterator $what)
        !            42:        {
        !            43:                echo __METHOD__ . "\n";
        !            44:                parent::append($what);
        !            45:        }
        !            46:        
        !            47:        function parent__construct()
        !            48:        {
        !            49:                parent::__construct();
        !            50:        }
        !            51: }
        !            52: 
        !            53: $ap = new MyAppendIterator;
        !            54: 
        !            55: try
        !            56: {
        !            57:        $ap->append($it);
        !            58: }
        !            59: catch(LogicException $e)
        !            60: {
        !            61:        echo $e->getMessage() . "\n";
        !            62: }
        !            63: 
        !            64: $ap->parent__construct();
        !            65: 
        !            66: try
        !            67: {
        !            68:        $ap->parent__construct($it);
        !            69: }
        !            70: catch(BadMethodCallException $e)
        !            71: {
        !            72:        echo $e->getMessage() . "\n";
        !            73: }
        !            74: 
        !            75: $ap->append($it);
        !            76: $ap->append($it);
        !            77: $ap->append($it);
        !            78: 
        !            79: foreach($ap as $k=>$v)
        !            80: {
        !            81:        echo "$k=>$v\n";
        !            82: }
        !            83: 
        !            84: ?>
        !            85: ===DONE===
        !            86: <?php exit(0); ?>
        !            87: --EXPECT--
        !            88: MyArrayIterator::rewind
        !            89: 0=>1
        !            90: 1=>2
        !            91: MyAppendIterator::__construct
        !            92: MyAppendIterator::append
        !            93: The object is in an invalid state as the parent constructor was not called
        !            94: AppendIterator::getIterator() must be called exactly once per instance
        !            95: MyAppendIterator::append
        !            96: MyArrayIterator::rewind
        !            97: MyAppendIterator::append
        !            98: MyAppendIterator::append
        !            99: MyAppendIterator::rewind
        !           100: MyArrayIterator::rewind
        !           101: MyAppendIterator::valid
        !           102: 0=>1
        !           103: MyAppendIterator::valid
        !           104: 1=>2
        !           105: MyArrayIterator::rewind
        !           106: MyAppendIterator::valid
        !           107: 0=>1
        !           108: MyAppendIterator::valid
        !           109: 1=>2
        !           110: MyArrayIterator::rewind
        !           111: MyAppendIterator::valid
        !           112: 0=>1
        !           113: MyAppendIterator::valid
        !           114: 1=>2
        !           115: MyAppendIterator::valid
        !           116: ===DONE===

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