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