I'm quite new to PHPUnit, and need some advice on how to properly test this Daemon
class, start()
and runTask()
methods.
class Daemon {
public function start() {
// Start the loop
while (true) {
// This is the code you want to loop during the service...
$this->runTask();
// If signaled to stop
if ('stop' == $this->sig) {
// Break the loop
break;
}
// Now before we 'Task' again, we'll sleep for a bit...
usleep($this->delay);
}
}
}
I've tried to use a mock, but it doesn't seem to work.
$mock = $this->getMock('Daemon');
$mock->expects($this->once())->method('runTask');
$mock->start();