1--TEST--
2Test imap_fetchheader() function : usage variations - $message_num argument
3--EXTENSIONS--
4imap
5--SKIPIF--
6<?php
7require_once(__DIR__.'/setup/skipif.inc');
8?>
9--FILE--
10<?php
11/*
12 * Pass different integers and strings as $message_num argument
13 * to test behaviour of imap_fetchheader()
14 */
15
16echo "*** Testing imap_fetchheader() : usage variations ***\n";
17
18require_once(__DIR__.'/setup/imap_include.inc');
19
20$stream_id = setup_test_mailbox('imapfetchheadervar5', 3, $mailbox, false); // set up temp mailbox with 3 msgs
21
22$sequences = [0, /* out of range */ 4, 1];
23
24foreach($sequences as $message_num) {
25    echo "\n-- \$message_num is $message_num --\n";
26    try {
27        var_dump(imap_fetchheader($stream_id, $message_num));
28    } catch (\ValueError $e) {
29        echo $e->getMessage() . \PHP_EOL;
30    }
31}
32
33// clear error stack
34imap_errors();
35?>
36--CLEAN--
37<?php
38$mailbox_suffix = 'imapfetchheadervar5';
39require_once(__DIR__.'/setup/clean.inc');
40?>
41--EXPECTF--
42*** Testing imap_fetchheader() : usage variations ***
43Create a temporary mailbox and add 3 msgs
44New mailbox created
45
46-- $message_num is 0 --
47imap_fetchheader(): Argument #2 ($message_num) must be greater than 0
48
49-- $message_num is 4 --
50
51Warning: imap_fetchheader(): Bad message number in %s on line %d
52bool(false)
53
54-- $message_num is 1 --
55string(%d) "From: foo@anywhere.com
56Subject: Test msg 1
57To: %s
58MIME-Version: 1.0
59Content-Type: MULTIPART/mixed; BOUNDARY="%s=:%d"
60
61"
62