<?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\AdminBundle\Tests\Controller\Page;

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

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

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

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

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

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

    public static function expectedRouteNamesProvider(): iterable
    {
        yield 'hosts index' => ['admin_hosts_index'];
        yield 'hosts show' => ['admin_hosts_show'];
        yield 'hosts export' => ['admin_hosts_export'];
        yield 'hosts create' => ['admin_hosts_create'];
        yield 'hosts edit' => ['admin_hosts_edit'];
        yield 'hosts delete' => ['admin_hosts_delete'];
    }
}
