Suppose there is a logging function

class Logger { public function log($message) { fwrite(STDERR, json_encode([time() => $message])); } } 

There is control over $message , of course, but not very much over time() .

How can I use PHPUnit to test that a string matches the pattern in STDERR? (and if you immediately check for the correct JSON, then it's generally great)

 {%i:"error"} 
  • are you talking about moki? if you need to know for sure that time () will return a value that should return when this function is called - Eugene Nagornichyh
  • @EugeneNagornichyh is now done via assertStringMatchesFormat by locking methods from fwrite to echo. But somehow it is ugly. I would like to do without mocks, somehow intercepting stderr - rjhdby

0