Annotation of embedaddon/php/ext/standard/tests/math/abs_variation.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test abs() function : usage variations - different data types as $number arg
3: --FILE--
4: <?php
5: /* Prototype : number abs ( mixed $number )
6: * Description: Returns the absolute value of number.
7: * Source code: ext/standard/math.c
8: */
9:
10: /*
11: * Pass different data types as $number argument to abs() to test behaviour
12: */
13:
14: echo "*** Testing abs() : usage variations ***\n";
15:
16: //get an unset variable
17: $unset_var = 10;
18: unset ($unset_var);
19:
20: // get a class
21: class classA
22: {
23: public function __toString() {
24: return "abs";
25: }
26: }
27:
28: // heredoc string
29: $heredoc = <<<EOT
30: abs
31: EOT;
32:
33: // get a resource variable
34: $fp = fopen(__FILE__, "r");
35:
36: // unexpected values to be passed to $number argument
37: $inputs = array(
38:
39: // null data
40: /*10*/ NULL,
41: null,
42:
43: // boolean data
44: /*12*/ true,
45: false,
46: TRUE,
47: FALSE,
48:
49: // empty data
50: /*16*/ "",
51: '',
52: array(),
53:
54: // string data
55: /*19*/ "abs",
56: 'abs',
57: $heredoc,
58:
59: // object data
60: /*22*/ new classA(),
61:
62: // undefined data
63: /*23*/ @$undefined_var,
64:
65: // unset data
66: /*24*/ @$unset_var,
67:
68: // resource variable
69: /*25*/ $fp
70: );
71:
72: // loop through each element of $inputs to check the behavior of abs()
73: $iterator = 1;
74: foreach($inputs as $input) {
75: echo "\n-- Iteration $iterator --\n";
76: var_dump(abs($input) );
77: $iterator++;
78: };
79:
80: fclose($fp);
81: ?>
82: ===Done===
83: --EXPECTF--
84: *** Testing abs() : usage variations ***
85:
86: -- Iteration 1 --
87: int(0)
88:
89: -- Iteration 2 --
90: int(0)
91:
92: -- Iteration 3 --
93: int(1)
94:
95: -- Iteration 4 --
96: int(0)
97:
98: -- Iteration 5 --
99: int(1)
100:
101: -- Iteration 6 --
102: int(0)
103:
104: -- Iteration 7 --
105: int(0)
106:
107: -- Iteration 8 --
108: int(0)
109:
110: -- Iteration 9 --
111: bool(false)
112:
113: -- Iteration 10 --
114: int(0)
115:
116: -- Iteration 11 --
117: int(0)
118:
119: -- Iteration 12 --
120: int(0)
121:
122: -- Iteration 13 --
123:
124: Notice: Object of class classA could not be converted to int in %s on line %d
125: int(1)
126:
127: -- Iteration 14 --
128: int(0)
129:
130: -- Iteration 15 --
131: int(0)
132:
133: -- Iteration 16 --
134: int(%d)
135: ===Done===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>