1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
<?php
/**
* Tests for the \PHP_CodeSniffer\Util\Timing::getHumanReadableDuration() method.
*
* @author Juliette Reinders Folmer <phpcs_nospam@adviesenzo.nl>
* @copyright 2024 PHPCSStandards and contributors
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
*/
namespace PHP_CodeSniffer\Tests\Core\Util\Timing;
use PHP_CodeSniffer\Util\Timing;
use PHPUnit\Framework\TestCase;
/**
* Tests for the \PHP_CodeSniffer\Util\Timing::getHumanReadableDuration() method.
*
* @covers \PHP_CodeSniffer\Util\Timing::getHumanReadableDuration
*/
final class GetHumanReadableDurationTest extends TestCase
{
/**
* Test the method.
*
* @param int|float $duration A duration in milliseconds.
* @param string $expected The expected human readable string.
*
* @dataProvider dataGetHumanReadableDuration
*
* @return void
*/
public function testGetHumanReadableDuration($duration, $expected)
{
$this->assertSame($expected, Timing::getHumanReadableDuration($duration));
}//end testGetHumanReadableDuration()
/**
* Data provider.
*
* @return array<string, array<string, int|float|string>>
*/
public static function dataGetHumanReadableDuration()
{
return [
'Duration: 0' => [
'duration' => 0,
'expected' => '0ms',
],
'Duration: 13 milliseconds' => [
'duration' => 13.232101565,
'expected' => '13ms',
],
'Duration: 14 milliseconds' => [
'duration' => 13.916015625,
'expected' => '14ms',
],
'Duration: 999 milliseconds' => [
'duration' => 999.2236,
'expected' => '999ms',
],
'Duration: 999+ milliseconds' => [
'duration' => 999.89236,
'expected' => '1000ms',
],
'Duration: 1 second' => [
'duration' => 1000,
'expected' => '1 secs',
],
'Duration: slightly more than 1 second' => [
'duration' => 1001.178215,
'expected' => '1 secs',
],
'Duration: just under a 1 minute' => [
'duration' => 59999.3851,
'expected' => '60 secs',
],
'Duration: exactly 1 minute' => [
'duration' => 60000,
'expected' => '1 mins',
],
'Duration: slightly more than 1 minute' => [
'duration' => 60001.7581235,
'expected' => '1 mins',
],
'Duration: 1 minute, just under half a second' => [
'duration' => 60499.83639,
'expected' => '1 mins, 0.5 secs',
],
'Duration: 1 minute, just over half a second' => [
'duration' => 60501.961238,
'expected' => '1 mins, 0.5 secs',
],
'Duration: 1 minute, 1 second' => [
'duration' => 61000,
'expected' => '1 mins, 1 secs',
],
'Duration: exactly 1 hour' => [
'duration' => 3600000,
'expected' => '60 mins',
],
'Duration: 89.4 mins' => [
'duration' => 5364000,
'expected' => '89 mins, 24 secs',
],
];
}//end dataGetHumanReadableDuration()
}//end class
|