TimerTest.php 1014 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php declare(strict_types=1);
  2. /*
  3. * This file is part of phpunit/php-timer.
  4. *
  5. * (c) Sebastian Bergmann <sebastian@phpunit.de>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace SebastianBergmann\Timer;
  11. use PHPUnit\Framework\TestCase;
  12. /**
  13. * @covers \SebastianBergmann\Timer\Timer
  14. *
  15. * @uses \SebastianBergmann\Timer\Duration
  16. */
  17. final class TimerTest extends TestCase
  18. {
  19. /**
  20. * @var Timer
  21. */
  22. private $timer;
  23. protected function setUp(): void
  24. {
  25. $this->timer = new Timer;
  26. }
  27. public function testCanBeStartedAndStopped(): void
  28. {
  29. $this->timer->start();
  30. /* @noinspection UnnecessaryAssertionInspection */
  31. $this->assertInstanceOf(Duration::class, $this->timer->stop());
  32. }
  33. public function testCannotBeStoppedWhenItWasNotStarted(): void
  34. {
  35. $this->expectException(NoActiveTimerException::class);
  36. $this->timer->stop();
  37. }
  38. }