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

1.1     ! misho       1: --TEST--
        !             2: SPL: CachingIterator and __toString
        !             3: --FILE--
        !             4: <?php
        !             5: 
        !             6: function test($ar, $flags)
        !             7: {
        !             8:        echo "===$flags===\n";
        !             9:        $it = new CachingIterator($ar, 0);
        !            10:        try
        !            11:        {
        !            12:                $it->setFlags($flags);
        !            13:        }
        !            14:        catch (Exception $e)
        !            15:        {
        !            16:                echo 'Exception: ' . $e->getMessage() . "\n";
        !            17:                var_dump($it->getFlags());
        !            18:                return;
        !            19:        }
        !            20:        var_dump($it->getFlags());
        !            21:        try
        !            22:        {
        !            23:                foreach($it as $v)
        !            24:                {
        !            25:                        var_dump((string)$it);
        !            26:                }
        !            27:        }
        !            28:        catch (Exception $e)
        !            29:        {
        !            30:                echo 'Exception: ' . $e->getMessage() . "\n";
        !            31:        }
        !            32: }
        !            33: 
        !            34: class MyItem
        !            35: {
        !            36:        function __construct($value)
        !            37:        {
        !            38:                $this->value = $value;
        !            39:        }
        !            40: 
        !            41:        function __toString()
        !            42:        {
        !            43:                return (string)$this->value;
        !            44:        }
        !            45: }
        !            46: 
        !            47: class MyArrayIterator extends ArrayIterator
        !            48: {
        !            49:        function __toString()
        !            50:        {
        !            51:                return $this->key() . ':' . $this->current();
        !            52:        }
        !            53: }
        !            54: 
        !            55: $ar = new MyArrayIterator(array(1, 2, 3));
        !            56: 
        !            57: test($ar, CachingIterator::CALL_TOSTRING);
        !            58: test($ar, CachingIterator::TOSTRING_USE_KEY);
        !            59: test($ar, CachingIterator::TOSTRING_USE_CURRENT);
        !            60: 
        !            61: $ar = new MyArrayIterator(array(new MyItem(1), new MyItem(2), new MyItem(3)));
        !            62: 
        !            63: test($ar, CachingIterator::TOSTRING_USE_INNER);
        !            64: test($ar, CachingIterator::CALL_TOSTRING | CachingIterator::TOSTRING_USE_KEY);
        !            65: test($ar, CachingIterator::CALL_TOSTRING | CachingIterator::TOSTRING_USE_CURRENT);
        !            66: test($ar, CachingIterator::CALL_TOSTRING | CachingIterator::TOSTRING_USE_INNER);
        !            67: test($ar, CachingIterator::TOSTRING_USE_KEY | CachingIterator::TOSTRING_USE_CURRENT);
        !            68: test($ar, CachingIterator::TOSTRING_USE_KEY | CachingIterator::TOSTRING_USE_INNER);
        !            69: 
        !            70: echo "===X===\n";
        !            71: try
        !            72: {
        !            73:        $it = new CachingIterator($ar, CachingIterator::CALL_TOSTRING);
        !            74:        $it->setFlags(0);
        !            75: }
        !            76: catch (Exception $e)
        !            77: {
        !            78:        echo 'Exception: ' . $e->getMessage() . "\n";
        !            79: }
        !            80: try
        !            81: {
        !            82:        $it = new CachingIterator($ar, CachingIterator::TOSTRING_USE_INNER);
        !            83:        $it->setFlags(0);
        !            84: }
        !            85: catch (Exception $e)
        !            86: {
        !            87:        echo 'Exception: ' . $e->getMessage() . "\n";
        !            88: }
        !            89: 
        !            90: ?>
        !            91: ===DONE===
        !            92: --EXPECTF--    
        !            93: ===1===
        !            94: int(1)
        !            95: string(1) "1"
        !            96: string(1) "2"
        !            97: string(1) "3"
        !            98: ===2===
        !            99: int(2)
        !           100: string(1) "0"
        !           101: string(1) "1"
        !           102: string(1) "2"
        !           103: ===4===
        !           104: int(4)
        !           105: string(1) "1"
        !           106: string(1) "2"
        !           107: string(1) "3"
        !           108: ===8===
        !           109: int(8)
        !           110: string(3) "0:1"
        !           111: string(3) "1:2"
        !           112: string(3) "2:3"
        !           113: ===3===
        !           114: Exception: Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER
        !           115: int(0)
        !           116: ===5===
        !           117: Exception: Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER
        !           118: int(0)
        !           119: ===9===
        !           120: Exception: Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER
        !           121: int(0)
        !           122: ===6===
        !           123: Exception: Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER
        !           124: int(0)
        !           125: ===10===
        !           126: Exception: Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER
        !           127: int(0)
        !           128: ===X===
        !           129: Exception: Unsetting flag CALL_TO_STRING is not possible
        !           130: Exception: Unsetting flag TOSTRING_USE_INNER is not possible
        !           131: ===DONE===

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