<?php

declare(strict_types=1);

namespace Ferienpass\CoreBundle\Tests\Monolog;

use Doctrine\ORM\EntityManagerInterface;
use Ferienpass\CoreBundle\Monolog\MessengerLogHandler;
use Ferienpass\CoreBundle\Repository\MessengerLogRepository;
use Monolog\Level;
use Monolog\LogRecord;
use PHPUnit\Framework\TestCase;

final class MessengerLogHandlerTest extends TestCase
{
    public function testWriteDoesNothingWhenContextHasNoUuid(): void
    {
        $logs = $this->createMock(MessengerLogRepository::class);
        $logs->expects(self::never())->method('findOneBy');

        $em = $this->createMock(EntityManagerInterface::class);
        $em->expects(self::never())->method('persist');

        $handler = new MessengerLogHandler($logs, $em);

        $record = new LogRecord(
            new \DateTimeImmutable(),
            'test',
            Level::Info,
            'test',
            ['id' => 'not-a-id-object'],
        );

        $handler->handle($record);
    }

    public function testWriteDoesNothingWhenUuidIsMissing(): void
    {
        $logs = $this->createMock(MessengerLogRepository::class);
        $logs->expects(self::never())->method('findOneBy');

        $em = $this->createMock(EntityManagerInterface::class);
        $em->expects(self::never())->method('persist');

        $handler = new MessengerLogHandler($logs, $em);

        $record = new LogRecord(
            new \DateTimeImmutable(),
            'test',
            Level::Info,
            'test',
        );

        $handler->handle($record);
    }
}
