<?php

namespace App\Tests\Repository;

use App\Entity\MessengerLog;
use App\Repository\MessengerLogRepository;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

class MessengerLogRepositoryTest extends KernelTestCase
{
    public function testRepositoryIsRegistered(): void
    {
        self::bootKernel();
        $repository = static::getContainer()->get(MessengerLogRepository::class);

        self::assertInstanceOf(MessengerLogRepository::class, $repository);
    }

    public function testPersistAndFind(): void
    {
        self::bootKernel();
        $em = static::getContainer()->get('doctrine.orm.entity_manager');

        $log = new MessengerLog(
            messageClass: 'App\Message\TestMessage',
            messageBody: 'serialized',
            errorMessage: 'Test error',
            stackTrace: 'trace',
            transportName: 'async',
            retryCount: 1,
        );

        $em->persist($log);
        $em->flush();

        $found = $em->getRepository(MessengerLog::class)->find($log->getId());
        self::assertNotNull($found);
        self::assertSame('App\Message\TestMessage', $found->getMessageClass());
    }
}
