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