<?php

declare(strict_types=1);

namespace Ferienpass\AdminBundle\Tests\Components\Offer;

use Doctrine\ORM\EntityManagerInterface;
use Ferienpass\AdminBundle\Components\Offer\OfferDates;
use Ferienpass\CoreBundle\Entity\PageConfig;
use Ferienpass\CoreBundle\Settings\PageConfigManager;
use PHPUnit\Framework\TestCase;

final class OfferDatesTest extends TestCase
{
    public function testHydrateDateTimeWithInvalidStringReturnsNull(): void
    {
        $entityManager = $this->createMock(EntityManagerInterface::class);
        $pageConfigManager = $this->createMock(PageConfigManager::class);
        $pageConfig = $this->createMock(PageConfig::class);

        $pageConfigManager->method('getPageConfig')->willReturn($pageConfig);
        $pageConfig->method('getTimezone')->willReturn('Europe/Berlin');

        $component = new OfferDates($entityManager, $pageConfigManager);

        self::assertNull($component->hydrateDateTime('202620-03-30T00:00'));
    }

    public function testHydrateDateTimeWithValidString(): void
    {
        $entityManager = $this->createMock(EntityManagerInterface::class);
        $pageConfigManager = $this->createMock(PageConfigManager::class);
        $pageConfig = $this->createMock(PageConfig::class);

        $pageConfigManager->method('getPageConfig')->willReturn($pageConfig);
        $pageConfig->method('getTimezone')->willReturn('Europe/Berlin');

        $component = new OfferDates($entityManager, $pageConfigManager);

        $result = $component->hydrateDateTime('2026-03-30T00:00');
        self::assertInstanceOf(\DateTimeInterface::class, $result);
        self::assertSame('2026-03-30 00:00:00', $result->format('Y-m-d H:i:s'));
    }
}
