public function testResourceRegisteredWithTracker() { $resource = m::mock('JasonLewis\\ResourceWatcher\\Resource\\ResourceInterface'); $resource->shouldReceive('getKey')->twice()->andReturn('foo'); $listener = m::mock('JasonLewis\\ResourceWatcher\\Listener'); $tracker = new Tracker(); $tracker->register($resource, $listener); $this->assertTrue($tracker->isTracked($resource)); }
/** * Start watching for a given interval. The interval and timeout and measured * in microseconds, so 1,000,000 microseconds is equal to 1 second. * * @param int $interval * @param int $timeout * @param \Closure $callback * @return void */ public function startWatch($interval = 1000000, $timeout = null, Closure $callback = null) { $this->watching = true; $timeWatching = 0; while ($this->watching) { if (is_callable($callback)) { call_user_func($callback, $this); } usleep($interval); $this->tracker->checkTrackings(); $timeWatching += $interval; if (!is_null($timeout) and $timeWatching >= $timeout) { $this->stopWatch(); } } }