Skip to content

Instantly share code, notes, and snippets.

@pelshoff
Created August 13, 2012 13:27
Show Gist options
  • Save pelshoff/3340754 to your computer and use it in GitHub Desktop.
Save pelshoff/3340754 to your computer and use it in GitHub Desktop.
/**
* Listen to the given stream and register incoming log hits
* @param resource $stream A stream with log lines
*/
public function listenTo($stream)
{
$lastFlushTime = time();
$stopConditionCallback = $this->stopConditionCallback;
while ($stopConditionCallback($stream)) {
$this->receiveLine($stream);
$lastFlushTime = $this->flushIfNeeded($lastFlushTime);
}
}
@chartjes
Copy link

Yeah, this is somewhat complicated to test. Here are my thoughts:

  • mock of the stream
  • mock of stopConditionCallback
  • mock of flushIfNeeded

Then your test would be making sure that whatever is happening inside receiveLine() is meeting your expectations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment