1--TEST-- 2Test imap_close() function : usage variations - different ints as $flags arg 3--EXTENSIONS-- 4imap 5--SKIPIF-- 6<?php 7require_once(__DIR__.'/setup/skipif.inc'); 8?> 9--FILE-- 10<?php 11/* 12 * Pass different integers as $flags arg to imap_close() to test which are 13 * recognised as CL_EXPUNGE option 14 */ 15 16echo "*** Testing imap_close() : usage variations ***\n"; 17 18require_once(__DIR__.'/setup/imap_include.inc'); 19 20$inputs = array (0, 3.2768e4, -32768, PHP_INT_MAX, -PHP_INT_MAX); 21 22$stream_id = setup_test_mailbox('imapclosevar4', 3, $mailbox); // set up temp mailbox with 3 messages 23 24// loop through each element of $inputs to check the behavior of imap_close() 25$iterator = 1; 26foreach($inputs as $input) { 27 28 // mark added messages for deletion 29 for ($i = 1; $i < 4; $i++) { 30 imap_delete($stream_id, $i); 31 } 32 echo "\n-- Iteration $iterator --\n"; 33 try { 34 var_dump( $check = imap_close($stream_id, $input) ); 35 } catch (\ValueError $e) { 36 echo $e->getMessage() . \PHP_EOL; 37 $check = false; 38 } 39 40 // check that imap_close was successful, if not call imap_close and explicitly set CL_EXPUNGE 41 if(false === $check) { 42 imap_close($stream_id, CL_EXPUNGE); 43 } else { 44 // if imap_close was successful test whether CL_EXPUNGE was set by doing a message count 45 $imap_stream = imap_open($mailbox, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD); 46 $num_msg = imap_num_msg($imap_stream); 47 if ($num_msg != 0) { 48 echo "CL_EXPUNGE was not set, $num_msg msgs in mailbox\n"; 49 } else { 50 echo "CL_EXPUNGE was set\n"; 51 } 52 // call imap_close with CL_EXPUNGE explicitly set in case mailbox not empty 53 imap_close($imap_stream, CL_EXPUNGE); 54 } 55 $iterator++; 56 57 // get $stream_id for next iteration 58 $stream_id = imap_open($mailbox, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD); 59 populate_mailbox($stream_id, $mailbox, 3); 60 61}; 62?> 63--CLEAN-- 64<?php 65$mailbox_suffix = 'imapclosevar4'; 66require_once(__DIR__.'/setup/clean.inc'); 67?> 68--EXPECT-- 69*** Testing imap_close() : usage variations *** 70Create a temporary mailbox and add 3 msgs 71New mailbox created 72 73-- Iteration 1 -- 74bool(true) 75CL_EXPUNGE was not set, 3 msgs in mailbox 76 77-- Iteration 2 -- 78bool(true) 79CL_EXPUNGE was set 80 81-- Iteration 3 -- 82imap_close(): Argument #2 ($flags) must be CL_EXPUNGE or 0 83 84-- Iteration 4 -- 85imap_close(): Argument #2 ($flags) must be CL_EXPUNGE or 0 86 87-- Iteration 5 -- 88imap_close(): Argument #2 ($flags) must be CL_EXPUNGE or 0 89