ClockTest.php 634 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace Tools\Test\TestCase\Utility;
  3. use Shim\TestSuite\TestCase;
  4. use Tools\Utility\Clock;
  5. #[\PHPUnit\Framework\Attributes\CoversClass(Clock::class)]
  6. class ClockTest extends TestCase {
  7. /**
  8. * @return void
  9. */
  10. public function testTime() {
  11. Clock::startClock();
  12. time_nanosleep(0, 200000000);
  13. $res = Clock::returnElapsedTime();
  14. $this->assertTrue(round($res, 1) === 0.2);
  15. time_nanosleep(0, 100000000);
  16. $res = Clock::returnElapsedTime(8, true);
  17. $this->assertTrue(round($res, 1) === 0.3);
  18. time_nanosleep(0, 100000000);
  19. $res = Clock::returnElapsedTime();
  20. $this->assertTrue(round($res, 1) === 0.1);
  21. }
  22. }