Annotation of embedaddon/php/ext/standard/tests/strings/money_format_variation2.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test money_format() function : usage variations - test values for $number argument
! 3: --SKIPIF--
! 4: <?php
! 5: if (!function_exists('money_format')) {
! 6: die("SKIP money_format - not supported\n");
! 7: }
! 8: ?>
! 9: --FILE--
! 10: <?php
! 11: /* Prototype : string money_format ( string $format , float $number )
! 12: * Description: Formats a number as a currency string
! 13: * Source code: ext/standard/string.c
! 14: */
! 15:
! 16: // ===========================================================================================
! 17: // = We do not test for exact return-values, as those might be different between OS-versions =
! 18: // ===========================================================================================
! 19:
! 20: echo "*** Testing money_format() function: with unexpected inputs for 'number' argument ***\n";
! 21:
! 22: //get an unset variable
! 23: $unset_var = ' string_val ';
! 24: unset($unset_var);
! 25:
! 26: //defining a couple of sample classes
! 27: class class_no_tostring {
! 28: }
! 29:
! 30: class class_with_tostring {
! 31: public function __toString() {
! 32: return " sample object ";
! 33: }
! 34: }
! 35:
! 36:
! 37: //getting the resource
! 38: $file_handle = fopen(__FILE__, "r");
! 39:
! 40: // array with different values for $number
! 41: $numbers = array (
! 42:
! 43: // integer values
! 44: /*1*/ 0,
! 45: 1,
! 46: 255,
! 47: 256,
! 48: 2147483647,
! 49: -2147483648,
! 50:
! 51: // float values
! 52: /*7*/ 10.5,
! 53: -20.5,
! 54: 10.1234567e10,
! 55:
! 56: // array values
! 57: /*10*/ array(),
! 58: array(0),
! 59: array(1, 2),
! 60:
! 61: // boolean values
! 62: /*13*/ true,
! 63: false,
! 64: TRUE,
! 65: FALSE,
! 66:
! 67: // null values
! 68: /*17*/ NULL,
! 69: null,
! 70:
! 71: // string values
! 72: /*19*/ "abcd",
! 73: 'abcd',
! 74: "0x12f",
! 75: "%=*!14#8.2nabcd",
! 76:
! 77: // objects
! 78: /*23*/ new class_no_tostring(),
! 79: new class_with_tostring(),
! 80:
! 81: // resource
! 82: /*25*/ $file_handle,
! 83:
! 84: // undefined variable
! 85: /*26*/ @$undefined_var,
! 86:
! 87: // unset variable
! 88: /*27*/ @$unset_var
! 89: );
! 90:
! 91: // loop through with each element of the $numbers array to test money_format() function
! 92: $count = 1;
! 93: $format = '%14#8.2i';
! 94:
! 95: foreach($numbers as $number) {
! 96: echo "-- Iteration $count --\n";
! 97: echo gettype(money_format($format, $number))."\n";
! 98: $count ++;
! 99: }
! 100:
! 101: // close the file handle
! 102: fclose($file_handle);
! 103:
! 104: ?>
! 105: ===Done===
! 106: --EXPECTF--
! 107: *** Testing money_format() function: with unexpected inputs for 'number' argument ***
! 108: -- Iteration 1 --
! 109: string
! 110: -- Iteration 2 --
! 111: string
! 112: -- Iteration 3 --
! 113: string
! 114: -- Iteration 4 --
! 115: string
! 116: -- Iteration 5 --
! 117: string
! 118: -- Iteration 6 --
! 119: string
! 120: -- Iteration 7 --
! 121: string
! 122: -- Iteration 8 --
! 123: string
! 124: -- Iteration 9 --
! 125: string
! 126: -- Iteration 10 --
! 127:
! 128: Warning: money_format() expects parameter 2 to be double, array given in %s on line %d
! 129: NULL
! 130: -- Iteration 11 --
! 131:
! 132: Warning: money_format() expects parameter 2 to be double, array given in %s on line %d
! 133: NULL
! 134: -- Iteration 12 --
! 135:
! 136: Warning: money_format() expects parameter 2 to be double, array given in %s on line %d
! 137: NULL
! 138: -- Iteration 13 --
! 139: string
! 140: -- Iteration 14 --
! 141: string
! 142: -- Iteration 15 --
! 143: string
! 144: -- Iteration 16 --
! 145: string
! 146: -- Iteration 17 --
! 147: string
! 148: -- Iteration 18 --
! 149: string
! 150: -- Iteration 19 --
! 151:
! 152: Warning: money_format() expects parameter 2 to be double, string given in %s on line %d
! 153: NULL
! 154: -- Iteration 20 --
! 155:
! 156: Warning: money_format() expects parameter 2 to be double, string given in %s on line %d
! 157: NULL
! 158: -- Iteration 21 --
! 159: string
! 160: -- Iteration 22 --
! 161:
! 162: Warning: money_format() expects parameter 2 to be double, string given in %s on line %d
! 163: NULL
! 164: -- Iteration 23 --
! 165:
! 166: Warning: money_format() expects parameter 2 to be double, object given in %s on line %d
! 167: NULL
! 168: -- Iteration 24 --
! 169:
! 170: Warning: money_format() expects parameter 2 to be double, object given in %s on line %d
! 171: NULL
! 172: -- Iteration 25 --
! 173:
! 174: Warning: money_format() expects parameter 2 to be double, resource given in %s on line %d
! 175: NULL
! 176: -- Iteration 26 --
! 177: string
! 178: -- Iteration 27 --
! 179: string
! 180: ===Done===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>