nur-sery/tests/php/time/DateTimeTest.php

34 lines
993 B
PHP

<?php
namespace nur\sery\php\time;
use DateTimeZone;
use nur\sery\php\time\Date;
use nur\sery\php\time\DateTime;
use PHPUnit\Framework\TestCase;
class DateTimeTest extends TestCase {
protected static function dt(string $datetime): DateTime {
return new DateTime($datetime, new DateTimeZone("Indian/Reunion"));
}
function testDateTime() {
$date = self::dt("2024-04-05 09:15:23");
self::assertEquals("05/04/2024 09:15:23", $date->format());
self::assertEquals("05/04/2024 09:15:23", strval($date));
self::assertEquals("2024", $date->year);
self::assertEquals("04", $date->month);
self::assertEquals("05", $date->day);
self::assertEquals("09", $date->hour);
self::assertEquals("15", $date->minute);
self::assertEquals("23", $date->second);
self::assertEquals("+04:00", $date->timezone);
}
function testClone() {
$date = self::dt("now");
$clone = DateTime::clone($date);
self::assertInstanceOf(DateTime::class, $clone);
}
}