<?php
namespace App\Tests\Unit\Service\Utils;

use App\Service\Utils\DatesUtils;
use PHPUnit\Framework\TestCase;

class DatesUtilsTest extends TestCase
{
    /**
     * @see DatesUtils::isIntervalIsValidNow()
     * @noinspection PhpRedundantOptionalArgumentInspection
     */
    public function testIsIntervalIsValidNow():void
    {
        $this->assertTrue(DatesUtils::isIntervalIsValidNow(new \DateTime('2020-01-02'), new \DateTime('2025-01-02')));
        $this->assertTrue(DatesUtils::isIntervalIsValidNow(new \DateTime('2020-01-02'), null));
    }

    /**
     * @see DatesUtils::isIntervalIsValidNow()
     */
    public function testIsIntervalIsNotValidNow():void
    {
        $this->assertFalse(DatesUtils::isIntervalIsValidNow(new \DateTime('2019-01-02'), new \DateTime('2020-01-02')));
    }

    /**
     * @see DatesUtils::new()
     */
    public function testNew(): void {
        DatesUtils::clearFakeDatetime();

        self::assertEquals('2021-01-01', DatesUtils::new('2021-01-01')->format('Y-m-d'));

        $now = new \DateTime();

        self::assertEquals(
            $now->format('Y-m-d'),
            DatesUtils::new()->format('Y-m-d')
        );

        DatesUtils::setFakeDatetime('2021-01-01');

        /** @noinspection PhpRedundantOptionalArgumentInspection */
        self::assertEquals('2021-01-01', DatesUtils::new('now')->format('Y-m-d'));

        DatesUtils::clearFakeDatetime();

        $now = new \DateTime();

        self::assertEquals(
            $now->format('Y-m-d'),
            DatesUtils::new()->format('Y-m-d')
        );
    }
}
