コード例 #1
0
ファイル: ClockTest.php プロジェクト: romainneutron/Tip-Top
 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);
 }
コード例 #2
0
ファイル: ClockTest.php プロジェクト: romainneutron/Tip-Top
 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());
 }