xref: /PHP-8.3/ext/standard/tests/mail/gh7875.phpt (revision 4c35d644)
1--TEST--
2GH-7875 (mails are sent even if failure to log throws exception)
3--SKIPIF--
4<?php
5$filename = __DIR__ . "/gh7875.mail.log";
6touch($filename);
7chmod($filename, 0444);
8clearstatcache();
9$is_writable = is_writable($filename);
10chmod($filename, 0644);
11unlink($filename);
12if ($is_writable) die("skip cannot make file read-only");
13if (PHP_OS_FAMILY !== "Windows") {
14    if (!extension_loaded('posix')) die('skip POSIX extension not loaded');
15    if (posix_geteuid() == 0) die('skip Cannot run test as root.');
16}
17?>
18--INI--
19sendmail_path={MAIL:{PWD}/gh7875.mail.out}
20mail.log={PWD}/gh7875.mail.log
21--FILE--
22<?php
23function exception_error_handler($severity, $message, $file, $line) {
24    if (!(error_reporting() & $severity)) {
25        return;
26    }
27    throw new ErrorException($message, 0, $severity, $file, $line);
28}
29set_error_handler("exception_error_handler");
30
31touch(__DIR__ . "/gh7875.mail.log");
32chmod(__DIR__ . "/gh7875.mail.log", 0444);
33
34try {
35	mail('recipient@example.com', 'Subject', 'Body', []);
36	echo 'Not Reached';
37} catch (\Exception $e) {
38	echo $e->getMessage(), PHP_EOL;
39    var_dump(file_exists(__DIR__ . "/gh7875.mail.out"));
40}
41?>
42--CLEAN--
43<?php
44@chmod(__DIR__ . "/gh7875.mail.log", 0644);
45@unlink(__DIR__ . "/gh7875.mail.log");
46@unlink(__DIR__ . "/gh7875.mail.out");
47?>
48--EXPECTF--
49mail(%s): Failed to open stream: Permission denied
50bool(false)
51