Logger to syslog with error_log fallback
You need a SysLog interface and a SysLogImpl implementation class.

public interface SysLog {
    public bool openlog(string $ident, int $option ,int $facility);
    public bool syslog (int $priority, string $message);
    public bool closelog (void);
}


SysLogImpl just delegate the calls to the openlog, syslog and closelog PHP functions.

public class SysLogImpl implements SysLog {
    public bool openlog(string $ident, int $option, int $facility) {
        return openlog($ident, $option, $facility);
    }

    public bool syslog(int $priority, string $message) {
        return syslog($priority, $message);
    }

    public bool closelog (void) {
        return closelog();
    }
} 


It's important that this class should be just a thin facade without any logic since this class usually doesn't have any test or just has a few integration tests.

In production code pass a SysLogImpl instance to the constructor of your SystemLogger class and use this SysLogImpl instance instead of direct PHP calls.

In test code pass a mocked or a custom object which implements the SysLog interface to the SystemLogger class. The passed object should be able to store function calls and emulate responses (as mock objects do).

Maybe you'll need an ErrorLog interface and an ErrorLogImpl implementation class which logs with error_log PHP calls.



Another solution is a Test-Specific Subclass. You can extract out the openlog call from the constructor to a separate function and create a subclass of the SystemLogger which overrides this method and returns false.



A better and generic design would be creating a common Logger interface and a SyslogLogger and an ErrorLogLogger implementation classes. Both implements Logger. Then the SystemLogger class get one or more Logger instances and try calling their open functions and use that implementation whose open function returns true first.

If you use this the SystemLogger has only one responsibility: managing loggers, while SyslogLogger cares only about syslog and ErrorLogLogger cares only about error_log logging.