mirror of
https://github.com/kevinpapst/kimai2.git
synced 2025-05-09 03:20:14 +00:00
73 lines
2.5 KiB
PHP
73 lines
2.5 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Kimai time-tracking app.
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace App\Tests\Export\Package\CellFormatter;
|
|
|
|
use App\Export\Package\CellFormatter\DurationFormatter;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* @covers \App\Export\Package\CellFormatter\DurationFormatter
|
|
*/
|
|
class DurationFormatterTest extends TestCase
|
|
{
|
|
public function testGetFormat(): void
|
|
{
|
|
$formatter = new DurationFormatter();
|
|
self::assertEquals('[hh]:mm:ss', $formatter->getFormat());
|
|
}
|
|
|
|
public function testFormatValueReturnsFormattedDurationQuiteLong(): void
|
|
{
|
|
$formatter = new DurationFormatter();
|
|
$result = $formatter->formatValue(701213);
|
|
self::assertInstanceOf(\DateInterval::class, $result);
|
|
self::assertEquals('194:46:53', $result->format('%r%H:%I:%S'));
|
|
}
|
|
|
|
public function testFormatValueReturnsFormattedDurationForNumericValue(): void
|
|
{
|
|
$formatter = new DurationFormatter();
|
|
$result = $formatter->formatValue(7213);
|
|
self::assertInstanceOf(\DateInterval::class, $result);
|
|
self::assertEquals('02:00:13', $result->format('%r%H:%I:%S'));
|
|
}
|
|
|
|
public function testFormatValueReturnsZeroForNonNumericValue(): void
|
|
{
|
|
$formatter = new DurationFormatter();
|
|
$result = $formatter->formatValue('not a number');
|
|
self::assertInstanceOf(\DateInterval::class, $result);
|
|
self::assertEquals('00:00:00', $result->format('%r%H:%I:%S'));
|
|
}
|
|
|
|
public function testFormatValueReturnsFormattedDurationForFloatValue(): void
|
|
{
|
|
$formatter = new DurationFormatter();
|
|
$result = $formatter->formatValue(4521.5);
|
|
self::assertInstanceOf(\DateInterval::class, $result);
|
|
self::assertEquals('01:15:21', $result->format('%r%H:%I:%S'));
|
|
}
|
|
|
|
public function testFormatValueReturnsZeroForNullValue(): void
|
|
{
|
|
$formatter = new DurationFormatter();
|
|
$result = $formatter->formatValue(null);
|
|
self::assertInstanceOf(\DateInterval::class, $result);
|
|
self::assertEquals('00:00:00', $result->format('%r%H:%I:%S'));
|
|
}
|
|
|
|
public function testFormatValueReturnsFormattedDurationForNegativeValue(): void
|
|
{
|
|
$formatter = new DurationFormatter();
|
|
$result = $formatter->formatValue(-3600);
|
|
self::assertInstanceOf(\DateInterval::class, $result);
|
|
self::assertEquals('-01:00:00', $result->format('%r%H:%I:%S'));
|
|
}
|
|
}
|