TimersTest.php 929 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace React\Tests\EventLoop\Timer;
  3. use React\Tests\EventLoop\TestCase;
  4. use React\EventLoop\Timer\Timer;
  5. use React\EventLoop\Timer\Timers;
  6. class TimersTest extends TestCase
  7. {
  8. public function testBlockedTimer()
  9. {
  10. $timers = new Timers();
  11. $timers->tick();
  12. // simulate a bunch of processing on stream events,
  13. // part of which schedules a future timer...
  14. sleep(1);
  15. $timers->add(new Timer(0.5, function () {
  16. $this->fail("Timer shouldn't be called");
  17. }));
  18. $timers->tick();
  19. $this->assertTrue(true);
  20. }
  21. public function testContains()
  22. {
  23. $timers = new Timers();
  24. $timer1 = new Timer(0.1, function () {});
  25. $timer2 = new Timer(0.1, function () {});
  26. $timers->add($timer1);
  27. self::assertTrue($timers->contains($timer1));
  28. self::assertFalse($timers->contains($timer2));
  29. }
  30. }