<?php

declare(strict_types=1);

namespace Ferienpass\AdminBundle\Tests\Controller\Page;

use Ferienpass\AdminBundle\Controller\Page\EditionsController;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Routing\Attribute\Route;

final class EditionsControllerTest extends TestCase
{
    public function testClassRoutePrefix(): void
    {
        $ref = new \ReflectionClass(EditionsController::class);
        $attrs = $ref->getAttributes(Route::class);

        self::assertCount(1, $attrs);
        self::assertSame('/saisons', $attrs[0]->newInstance()->getPath());
    }

    
    #[DataProvider('expectedRouteNamesProvider')]
    
    public function testRouteNameExists(string $routeName): void
    {
        $ref = new \ReflectionClass(EditionsController::class);
        $routeNames = [];

        foreach ($ref->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
            foreach ($method->getAttributes(Route::class) as $attr) {
                $route = $attr->newInstance();
                if (null !== $route->getName()) {
                    $routeNames[] = $route->getName();
                }
            }
        }

        self::assertContains($routeName, $routeNames);
    }

    public static function expectedRouteNamesProvider(): iterable
    {
        yield 'editions index' => ['admin_editions_index'];
        yield 'editions show' => ['admin_editions_show'];
        yield 'editions stats' => ['admin_editions_stats'];
        yield 'editions mailing' => ['admin_editions_mailing'];
        yield 'editions export' => ['admin_editions_export'];
        yield 'editions notifications' => ['admin_editions_notifications'];
        yield 'editions delete' => ['admin_editions_delete'];
        yield 'editions assign' => ['admin_editions_assign'];
        yield 'editions lotting' => ['admin_editions_lotting'];
        yield 'offers review' => ['admin_offers_review'];
    }
}
