imap_fetchheader_variation5.phpt 1.4 KB

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