2 Test imap_close() function : usage variations - different ints as $options arg
5 require_once(dirname(__FILE__).'/skipif.inc');
9 /* Prototype : bool imap_close(resource $stream_id [, int $options])
10 * Description: Close an IMAP stream
11 * Source code: ext/imap/php_imap.c
15 * Pass different integers as $options arg to imap_close() to test which are
16 * recognised as CL_EXPUNGE option
19 echo "*** Testing imap_close() : usage variations ***\n";
21 require_once(dirname(__FILE__).'/imap_include.inc');
23 $inputs = array (0, 3.2768e4, -32768, PHP_INT_MAX, -PHP_INT_MAX);
25 $stream_id = setup_test_mailbox('', 3, $mailbox); // set up temp mailbox with 3 messages
27 // loop through each element of $inputs to check the behavior of imap_close()
29 foreach($inputs as $input) {
31 // mark added messages for deletion
32 for ($i = 1; $i < 4; $i++) {
33 imap_delete($stream_id, $i);
35 echo "\n-- Iteration $iterator --\n";
36 var_dump( $check = imap_close($stream_id, $input) );
38 // check that imap_close was successful, if not call imap_close and explicitly set CL_EXPUNGE
39 if(false === $check) {
40 imap_close($stream_id, CL_EXPUNGE);
42 // if imap_close was successful test whether CL_EXPUNGE was set by doing a message count
43 $imap_stream = imap_open($mailbox, $username, $password);
44 $num_msg = imap_num_msg($imap_stream);
46 echo "CL_EXPUNGE was not set, $num_msg msgs in mailbox\n";
48 echo "CL_EXPUNGE was set\n";
50 // call imap_close with CL_EXPUNGE explicitly set in case mailbox not empty
51 imap_close($imap_stream, CL_EXPUNGE);
55 // get $stream_id for next iteration
56 $stream_id = imap_open($mailbox, $username, $password);
57 populate_mailbox($stream_id, $mailbox, 3);
64 require_once(dirname(__FILE__).'/clean.inc');
67 *** Testing imap_close() : usage variations ***
68 Create a temporary mailbox and add 3 msgs
69 .. mailbox '{%s}%s' created
73 CL_EXPUNGE was not set, 3 msgs in mailbox
81 Warning: imap_close(): invalid value for the flags parameter in %s on line %d
86 Warning: imap_close(): invalid value for the flags parameter in %s on line %d
91 Warning: imap_close(): invalid value for the flags parameter in %s on line %d