2017-08-16 21:29:05 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use App\Facades\Utils;
|
|
|
|
|
|
|
|
class UtilsTest extends TestCase
|
|
|
|
{
|
2018-08-27 00:40:04 +08:00
|
|
|
public function setUp()
|
|
|
|
{
|
2017-08-16 21:29:05 +08:00
|
|
|
}
|
|
|
|
|
2018-03-18 11:20:08 +08:00
|
|
|
public function testDates()
|
|
|
|
{
|
2018-05-02 09:58:05 +08:00
|
|
|
$carbon = new \Carbon\Carbon('2018-04-28T12:55:40Z');
|
|
|
|
$this->assertNotNull($carbon);
|
2018-03-18 11:20:08 +08:00
|
|
|
}
|
|
|
|
|
2018-08-27 02:50:08 +08:00
|
|
|
/**
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
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-12-24 01:17:16 +08:00
|
|
|
public function testSecondsToTime()
|
|
|
|
{
|
2017-12-14 00:56:26 +08:00
|
|
|
$t = Utils::secondsToTimeString(3600);
|
2017-12-04 04:34:32 +08:00
|
|
|
$this->assertEquals('1h 0m', $t);
|
|
|
|
|
2017-12-14 00:56:26 +08:00
|
|
|
$t = Utils::secondsToTimeString(3720);
|
2017-12-04 04:34:32 +08:00
|
|
|
$this->assertEquals('1h 2m', $t);
|
|
|
|
|
2017-12-14 00:56:26 +08:00
|
|
|
$t = Utils::secondsToTimeString(3722);
|
2017-12-04 04:34:32 +08:00
|
|
|
$this->assertEquals('1h 2m', $t);
|
|
|
|
|
2017-12-14 00:56:26 +08:00
|
|
|
$t = Utils::secondsToTimeString(3722, true);
|
2017-12-04 04:34:32 +08:00
|
|
|
$this->assertEquals('1h 2m 2s', $t);
|
2017-08-16 21:29:05 +08:00
|
|
|
}
|
2017-12-24 01:17:16 +08:00
|
|
|
|
|
|
|
public function testMinutesToTime()
|
|
|
|
{
|
|
|
|
$t = Utils::minutesToTimeParts(65);
|
|
|
|
$this->assertEquals(['h' => 1, 'm' => 5], $t);
|
|
|
|
|
|
|
|
$t = Utils::minutesToTimeString(65);
|
|
|
|
$this->assertEquals('1h 5m', $t);
|
|
|
|
|
|
|
|
$t = Utils::minutesToTimeString(43200);
|
|
|
|
$this->assertEquals('720h 0m', $t);
|
|
|
|
}
|
2017-12-31 03:41:34 +08:00
|
|
|
|
|
|
|
public function testApiKey()
|
|
|
|
{
|
|
|
|
$api_key = Utils::generateApiKey();
|
|
|
|
$this->assertNotNull($api_key);
|
|
|
|
}
|
2018-02-13 10:58:23 +08:00
|
|
|
|
|
|
|
public function testHexCode()
|
|
|
|
{
|
|
|
|
$hex_code = \App\Support\ICAO::createHexCode();
|
|
|
|
$this->assertNotNull($hex_code);
|
|
|
|
}
|
2017-08-16 21:29:05 +08:00
|
|
|
}
|