mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-07 08:37:05 +00:00
684c677937
Intl is only a "suggested" extension. A lot of the NumberFormat Wizard code depends on it. That's insufficient reason to make it required, but the suggestion text now mentions this dependency explicitly. Also clean up the Wizard documentation to reflect some changes since PhpSpreadsheet 1.28.
46 lines
2.0 KiB
PHP
46 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Style\NumberFormat\Wizard;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard\Duration;
|
|
use PHPUnit\Framework\TestCase;
|
|
use ReflectionMethod;
|
|
|
|
class DurationTest extends TestCase
|
|
{
|
|
/**
|
|
* @param null|string|string[] $separators
|
|
* @param string[] $formatBlocks
|
|
*/
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('providerTime')]
|
|
public function testTime(string $expectedResult, string|array|null $separators = null, array $formatBlocks = []): void
|
|
{
|
|
$wizard = new Duration($separators, ...$formatBlocks);
|
|
self::assertSame($expectedResult, (string) $wizard);
|
|
}
|
|
|
|
public static function providerTime(): array
|
|
{
|
|
return [
|
|
['[h]:mm:ss', Duration::SEPARATOR_COLON, [Duration::HOURS_DURATION, Duration::MINUTES_LONG, Duration::SECONDS_LONG]],
|
|
['[h]:mm', Duration::SEPARATOR_COLON, [Duration::HOURS_DURATION, Duration::MINUTES_LONG]],
|
|
['[m]:ss', Duration::SEPARATOR_COLON, [Duration::MINUTES_DURATION, Duration::SECONDS_DURATION]],
|
|
['[h]:mm:ss', Duration::SEPARATOR_COLON, [Duration::HOURS_LONG, Duration::MINUTES_LONG, Duration::SECONDS_LONG]],
|
|
['[h]:mm', Duration::SEPARATOR_COLON, [Duration::HOURS_LONG, Duration::MINUTES_LONG]],
|
|
["d\u{a0}h:mm", [Duration::SEPARATOR_SPACE_NONBREAKING, Duration::SEPARATOR_COLON], [Duration::DAYS_DURATION, Duration::HOURS_DURATION, Duration::MINUTES_LONG]],
|
|
['[h]:mm:ss', null, [Duration::HOURS_DURATION, Duration::MINUTES_LONG, Duration::SECONDS_LONG]],
|
|
['[h]:mm:ss'],
|
|
];
|
|
}
|
|
|
|
public function testOddCase(): void
|
|
{
|
|
$wizard = new Duration(null, Duration::HOURS_DURATION, Duration::MINUTES_LONG, Duration::SECONDS_LONG);
|
|
$reflectionMethod = new ReflectionMethod($wizard, 'mapFormatBlocks');
|
|
$result = $reflectionMethod->invokeArgs($wizard, ['%%%']);
|
|
self::assertSame('"%%%"', $result);
|
|
}
|
|
}
|