Is there any way to run a test on output created from a call to 'error_log("Message")' when doing unit tests with phpunit?
Example code, one of my functions tests a credit card with a luhn algorithm:
if($checkLuhn && ($this->_luhn_check($cardNumber) == false)) {
error_log(__METHOD__ . " cardNumber failed luhn algorithm check.");
return false;
}
$checkLuhn is a boolean passed in to tell it whether to do the check, the _luhn_check() returns true if the $cardNumber passes. Problem is, I have more than one test in this function that can return false. I can use assertEquals on the return value, but also want to check why the error was thrown.
Can you override error_log or otherwise grab syslog output in a unit test somehow?
$this->_luhn_check($cardNumber)
throw an exception there? If so, you can get that exception and log it in your test.error_log()
on a similar question, please see: stackoverflow.com/a/72208381/209859