MD_STD/tests/MD_STD_Test.php

63 lines
1.4 KiB
PHP
Raw Normal View History

<?PHP
/**
* Tests for MD_STD.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
declare(strict_types = 1);
use PHPUnit\Framework\TestCase;
/**
* Tests for MD_STD.
*/
final class MD_STD_Test extends TestCase {
/**
* Returns sample dates and their equivalent integer values according
* to MD_STD::date_to_int().
*
* @return array<string, array{0: string, 1: integer}>
*/
public static function date_to_int_provider():array {
$values = [
["2022-01-01", 20220101],
["0022-01-01", 220101],
["-0022-01-01", -220101],
["-2022-01-01", -20220101],
["-0001-01-01", -10101],
["-0000-01-01", -101],
["0000-01-01", 101],
];
$output = [];
foreach ($values as $value) {
$output[$value[0]] = $value;
}
return $output;
}
/**
* Checks if dates can be translated to int and back.
*
* @dataProvider \MD_STD_Test::date_to_int_provider
*
* @param string $date Date to translate.
* @param integer $expectedInt Expected integer value for it.
*
* @return void
*/
public function test_date_to_int(string $date, int $expectedInt):void {
$toInt = MD_STD::date_to_int($date);
$toStr = MD_STD::int_to_date($toInt);
self::assertEquals($expectedInt, $toInt);
self::assertEquals($date, $toStr);
}
}