2017-08-16 21:29:05 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use App\Facades\Utils;
|
|
|
|
|
|
|
|
class UtilsTest extends TestCase
|
|
|
|
{
|
|
|
|
public function setUp() {
|
|
|
|
}
|
|
|
|
|
2017-12-04 04:34:32 +08:00
|
|
|
public function testSecondsToTimeParts()
|
|
|
|
{
|
|
|
|
$t = Utils::secondsToTimeParts(3600);
|
|
|
|
$this->assertEquals(['h' => 1, 'm' => 0, 's' => 0], $t);
|
|
|
|
|
|
|
|
$t = Utils::secondsToTimeParts(3720);
|
|
|
|
$this->assertEquals(['h' => 1, 'm' => 2, 's' => 0], $t);
|
|
|
|
|
|
|
|
$t = Utils::secondsToTimeParts(3722);
|
|
|
|
$this->assertEquals(['h' => 1, 'm' => 2, 's' => 2], $t);
|
|
|
|
|
|
|
|
$t = Utils::secondsToTimeParts(60);
|
|
|
|
$this->assertEquals(['h' => 0, 'm' => 1, 's' => 0], $t);
|
|
|
|
|
|
|
|
$t = Utils::secondsToTimeParts(62);
|
|
|
|
$this->assertEquals(['h' => 0, 'm' => 1, 's' => 2], $t);
|
|
|
|
}
|
|
|
|
|
2017-08-16 21:29:05 +08:00
|
|
|
public function testSecondsToTime() {
|
2017-12-04 04:34:32 +08:00
|
|
|
$t = Utils::secondsToTime(3600);
|
|
|
|
$this->assertEquals('1h 0m', $t);
|
|
|
|
|
|
|
|
$t = Utils::secondsToTime(3720);
|
|
|
|
$this->assertEquals('1h 2m', $t);
|
|
|
|
|
|
|
|
$t = Utils::secondsToTime(3722);
|
|
|
|
$this->assertEquals('1h 2m', $t);
|
|
|
|
|
|
|
|
$t = Utils::secondsToTime(3722, true);
|
|
|
|
$this->assertEquals('1h 2m 2s', $t);
|
2017-08-16 21:29:05 +08:00
|
|
|
}
|
|
|
|
}
|