public function testAddTimer() { $clock = new Clock($this->getPulseMock()); $caught = null; $timers = $this->getTimersMock(); $timers->expects($this->once())->method('add')->with($this->isInstanceOf('Neutron\\TipTop\\Timer\\TimerInterface'))->will($this->returnCallback(function ($timer) use(&$caught) { $caught = $timer; return $timer; })); $clock->setTimers($timers); $callback = function () { }; $timer = $clock->addTimer(1, $callback); $this->assertSame($caught, $timer); $this->assertFalse($timer->isPeriodic()); $this->assertSame($callback, $timer->getCallback()); }
public function testBlockIsBlocking() { $clock = new Clock(new Pulse()); $clock->addTimer(1, function () { }); $start = microtime(true); $clock->block(); $duration = microtime(true) - $start; $this->assertGreaterThan(0.999, $duration); $this->assertLessThan(1.001, $duration); }