Annotation of embedaddon/php/ext/mbstring/tests/mb_substr_count_variation2.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: Test mb_substr_count() function : usage variations - pass different data types as $needle arg 
        !             3: --SKIPIF--
        !             4: <?php
        !             5: extension_loaded('mbstring') or die('skip');
        !             6: function_exists('mb_substr_count') or die("skip mb_substr_count() is not available in this build");
        !             7: ?>
        !             8: --FILE--
        !             9: <?php
        !            10: /* Prototype  : int mb_substr_count(string $haystack, string $needle [, string $encoding])
        !            11:  * Description: Count the number of substring occurrences 
        !            12:  * Source code: ext/mbstring/mbstring.c
        !            13:  */
        !            14: 
        !            15: /*
        !            16:  * Pass different data types as $needle to mb_substr_count() to test behaviour
        !            17:  */
        !            18: 
        !            19: echo "*** Testing mb_substr_count() : usage variations ***\n";
        !            20: 
        !            21: // Initialise function arguments not being substituted (if any)
        !            22: $haystack = 'hello, world';
        !            23: 
        !            24: //get an unset variable
        !            25: $unset_var = 10;
        !            26: unset ($unset_var);
        !            27: 
        !            28: // get a class
        !            29: class classA
        !            30: {
        !            31:   public function __toString() {
        !            32:     return "world";
        !            33:   }
        !            34: }
        !            35: 
        !            36: // heredoc string
        !            37: $heredoc = <<<EOT
        !            38: world
        !            39: EOT;
        !            40: 
        !            41: // get a resource variable
        !            42: $fp = fopen(__FILE__, "r");
        !            43: 
        !            44: // unexpected values to be passed to $needle argument
        !            45: $inputs = array(
        !            46: 
        !            47:        // int data
        !            48: /*1*/  0,
        !            49:        1,
        !            50:        12345,
        !            51:        -2345,
        !            52: 
        !            53:        // float data
        !            54: /*5*/  10.5,
        !            55:        -10.5,
        !            56:        12.3456789000e10,
        !            57:        12.3456789000E-10,
        !            58:        .5,
        !            59: 
        !            60:        // null data
        !            61: /*10*/ NULL,
        !            62:        null,
        !            63: 
        !            64:        // boolean data
        !            65: /*12*/ true,
        !            66:        false,
        !            67:        TRUE,
        !            68:        FALSE,
        !            69:        
        !            70:        // empty data
        !            71: /*16*/ "",
        !            72:        '',
        !            73: 
        !            74:        // string data
        !            75: /*18*/ "world",
        !            76:        'world',
        !            77:        $heredoc,
        !            78:        
        !            79:        // object data
        !            80: /*21*/ new classA(),
        !            81: 
        !            82:        // undefined data
        !            83: /*22*/ @$undefined_var,
        !            84: 
        !            85:        // unset data
        !            86: /*23*/ @$unset_var,
        !            87: 
        !            88:        // resource variable
        !            89: /*24*/ $fp
        !            90: );
        !            91: 
        !            92: // loop through each element of $inputs to check the behavior of mb_substr_count()
        !            93: $iterator = 1;
        !            94: foreach($inputs as $input) {
        !            95:   echo "\n-- Iteration $iterator --\n";
        !            96:   var_dump( mb_substr_count($haystack, $input) );
        !            97:   $iterator++;
        !            98: };
        !            99: 
        !           100: fclose($fp);
        !           101: 
        !           102: echo "Done";
        !           103: ?>
        !           104: --EXPECTF--
        !           105: *** Testing mb_substr_count() : usage variations ***
        !           106: 
        !           107: -- Iteration 1 --
        !           108: int(0)
        !           109: 
        !           110: -- Iteration 2 --
        !           111: int(0)
        !           112: 
        !           113: -- Iteration 3 --
        !           114: int(0)
        !           115: 
        !           116: -- Iteration 4 --
        !           117: int(0)
        !           118: 
        !           119: -- Iteration 5 --
        !           120: int(0)
        !           121: 
        !           122: -- Iteration 6 --
        !           123: int(0)
        !           124: 
        !           125: -- Iteration 7 --
        !           126: int(0)
        !           127: 
        !           128: -- Iteration 8 --
        !           129: int(0)
        !           130: 
        !           131: -- Iteration 9 --
        !           132: int(0)
        !           133: 
        !           134: -- Iteration 10 --
        !           135: 
        !           136: Warning: mb_substr_count(): Empty substring in %s on line %d
        !           137: bool(false)
        !           138: 
        !           139: -- Iteration 11 --
        !           140: 
        !           141: Warning: mb_substr_count(): Empty substring in %s on line %d
        !           142: bool(false)
        !           143: 
        !           144: -- Iteration 12 --
        !           145: int(0)
        !           146: 
        !           147: -- Iteration 13 --
        !           148: 
        !           149: Warning: mb_substr_count(): Empty substring in %s on line %d
        !           150: bool(false)
        !           151: 
        !           152: -- Iteration 14 --
        !           153: int(0)
        !           154: 
        !           155: -- Iteration 15 --
        !           156: 
        !           157: Warning: mb_substr_count(): Empty substring in %s on line %d
        !           158: bool(false)
        !           159: 
        !           160: -- Iteration 16 --
        !           161: 
        !           162: Warning: mb_substr_count(): Empty substring in %s on line %d
        !           163: bool(false)
        !           164: 
        !           165: -- Iteration 17 --
        !           166: 
        !           167: Warning: mb_substr_count(): Empty substring in %s on line %d
        !           168: bool(false)
        !           169: 
        !           170: -- Iteration 18 --
        !           171: int(1)
        !           172: 
        !           173: -- Iteration 19 --
        !           174: int(1)
        !           175: 
        !           176: -- Iteration 20 --
        !           177: int(1)
        !           178: 
        !           179: -- Iteration 21 --
        !           180: int(1)
        !           181: 
        !           182: -- Iteration 22 --
        !           183: 
        !           184: Warning: mb_substr_count(): Empty substring in %s on line %d
        !           185: bool(false)
        !           186: 
        !           187: -- Iteration 23 --
        !           188: 
        !           189: Warning: mb_substr_count(): Empty substring in %s on line %d
        !           190: bool(false)
        !           191: 
        !           192: -- Iteration 24 --
        !           193: 
        !           194: Warning: mb_substr_count() expects parameter 2 to be string, resource given in %s on line %d
        !           195: NULL
        !           196: Done

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