<?php

namespace App\Tests\Entity;

use App\Entity\AnalyticsEvent;
use App\Entity\AnalyticsUniqId;
use PHPUnit\Framework\TestCase;

class AnalyticsEventTest extends TestCase
{
    public function testConstructor(): void
    {
        $event = new AnalyticsEvent();

        self::assertNull($event->getId());
        self::assertSame('page_view', $event->getEventName());
        self::assertNull($event->getTitle());
        self::assertNull($event->getReferrer());
        self::assertInstanceOf(\DateTimeImmutable::class, $event->getCreatedAt());
    }

    public function testSetEventName(): void
    {
        $event = new AnalyticsEvent();
        $result = $event->setEventName('click');

        self::assertSame('click', $event->getEventName());
        self::assertSame($event, $result);
    }

    public function testSetUrl(): void
    {
        $event = new AnalyticsEvent();
        $result = $event->setUrl('https://example.com/page');

        self::assertSame('https://example.com/page', $event->getUrl());
        self::assertSame($event, $result);
    }

    public function testSetTitle(): void
    {
        $event = new AnalyticsEvent();
        $result = $event->setTitle('My Page');

        self::assertSame('My Page', $event->getTitle());
        self::assertSame($event, $result);
    }

    public function testSetTitleNull(): void
    {
        $event = new AnalyticsEvent();
        $event->setTitle('My Page');
        $result = $event->setTitle(null);

        self::assertNull($event->getTitle());
        self::assertSame($event, $result);
    }

    public function testSetReferrer(): void
    {
        $event = new AnalyticsEvent();
        $result = $event->setReferrer('https://google.com');

        self::assertSame('https://google.com', $event->getReferrer());
        self::assertSame($event, $result);
    }

    public function testSetReferrerNull(): void
    {
        $event = new AnalyticsEvent();
        $event->setReferrer('https://google.com');
        $result = $event->setReferrer(null);

        self::assertNull($event->getReferrer());
        self::assertSame($event, $result);
    }

    public function testSetVisitor(): void
    {
        $visitor = $this->createMock(AnalyticsUniqId::class);

        $event = new AnalyticsEvent();
        $result = $event->setVisitor($visitor);

        self::assertSame($visitor, $event->getVisitor());
        self::assertSame($event, $result);
    }
}
