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

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

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