<?php

declare(strict_types=1);

/*
 * This file is part of the Ferienpass package.
 *
 * (c) Richard Henkenjohann <richard@ferienpass.online>
 *
 * For more information visit the project website <https://ferienpass.online>
 * or the documentation under <https://docs.ferienpass.online>.
 */

namespace Ferienpass\CoreBundle\Tests\Monolog;

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

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

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

        $handler = new NotificationLogHandler($logs, $users, $conversations, $em);

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

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