<?php

declare(strict_types=1);

namespace CpCreation\VitiCore\Tests\Commerce\Catalog\Outbox;

use CpCreation\VitiCore\Bridge\Doctrine\EventSubscriber\CatalogChangeSubscriber;
use CpCreation\VitiCore\Bridge\Doctrine\EventSubscriber\CatalogEnrollmentSubscriber;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
use Doctrine\ORM\Events;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

final class CatalogDoctrineListenerRegistrationTest extends TestCase
{
    /**
     * @param class-string $listenerClass
     */
    #[DataProvider('catalogListeners')]
    public function testCatalogListenerIsRegisteredForOnFlush(string $listenerClass): void
    {
        $attributes = new \ReflectionClass($listenerClass)->getAttributes(AsDoctrineListener::class);

        self::assertCount(1, $attributes);
        self::assertSame(Events::onFlush, $attributes[0]->newInstance()->event);
    }

    /**
     * @return iterable<string, array{class-string}>
     */
    public static function catalogListeners(): iterable
    {
        yield 'changements du catalogue' => [CatalogChangeSubscriber::class];
        yield 'enrôlement du catalogue' => [CatalogEnrollmentSubscriber::class];
    }
}
