Example #1
0
 public function testTimerFunctionReceivesTimer()
 {
     $clock = new Clock(new Pulse());
     $clock->addPeriodicTimer(1, function ($timer) {
         $timer->cancel();
     });
     $start = microtime(true);
     $clock->block();
     $duration = microtime(true) - $start;
     $this->assertGreaterThan(0.999, $duration);
     $this->assertLessThan(1.001, $duration);
 }
Example #2
0
 public function testAddPeriodicTimerWithPeriods()
 {
     $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->addPeriodicTimer(1, $callback, 4);
     $this->assertSame($caught, $timer);
     $this->assertTrue($timer->isPeriodic());
     $this->assertSame($callback, $timer->getCallback());
     $this->assertEquals(4, $timer->getIterations());
 }