Skip to content

Commit 41adf7d

Browse files
committed
Refactor the new human formatter to a new test class for better test organization
1 parent 4041f97 commit 41adf7d

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

src/Timer.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ private static function formatTime(float $value, $format): string {
9090
}
9191
}
9292

93-
private static function secondsToTimeString(float $time): string
94-
{
93+
private static function secondsToTimeString(float $time): string {
9594
$ms = \round($time * 1000);
9695

9796
foreach (self::TIMES as $unit => $value) {

tests/TimerFormatterTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Ayesh\PHP_Timer\Tests;
4+
5+
use Ayesh\PHP_Timer\Timer;
6+
use PHPUnit\Framework\TestCase;
7+
8+
/**
9+
* @package Ayesh\PHP_Timer\Tests
10+
* @group time-sensitive
11+
*/
12+
class TimerFormatterTest extends TestCase {
13+
public function testTimerFormat_Human(): void {
14+
Timer::start(__FUNCTION__);
15+
16+
usleep(1000);
17+
$read = Timer::read(__FUNCTION__, Timer::FORMAT_HUMAN);
18+
$this->assertSame('1 ms', $read);
19+
20+
sleep(1);
21+
$read = Timer::read(__FUNCTION__, Timer::FORMAT_HUMAN);
22+
$this->assertSame('1 second', $read);
23+
}
24+
}

tests/TimerTest.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,6 @@ public function testTimerFormat_Seconds() {
120120
$this->assertGreaterThanOrEqual('0.002', $read);
121121
}
122122

123-
public function testTimerFormat_Human() {
124-
Timer::start(__FUNCTION__);
125-
126-
usleep(1000);
127-
$read = Timer::read(__FUNCTION__, Timer::FORMAT_HUMAN);
128-
$this->assertSame('1 ms', $read);
129-
130-
sleep(1);
131-
$read = Timer::read(__FUNCTION__, Timer::FORMAT_HUMAN);
132-
$this->assertSame('1 second', $read);
133-
}
134-
135123
public function testTimerFormat_Unspecified() {
136124
Timer::start(__FUNCTION__);
137125
usleep(1500);

0 commit comments

Comments
 (0)