<?php

declare(strict_types=1);

namespace Ferienpass\AdminBundle\Tests\Controller\Page;

use Ferienpass\AdminBundle\Controller\Page\SecurityController;
use PHPUnit\Framework\TestCase;

final class SecurityControllerTest extends TestCase
{
    public function testTmpSessionKeyConstant(): void
    {
        $ref = new \ReflectionClass(SecurityController::class);
        $constant = $ref->getConstant('TMP_SESSION_KEY');

        self::assertSame('admin_security_api_token:value', $constant);
    }

    public function testControllerHasExpectedRoutes(): void
    {
        $ref = new \ReflectionClass(SecurityController::class);

        // Class-level route
        $classAttributes = $ref->getAttributes(\Symfony\Component\Routing\Attribute\Route::class);
        self::assertCount(1, $classAttributes);
        self::assertSame('/sicherheit', $classAttributes[0]->newInstance()->getPath());

        // __invoke route
        $invokeMethod = $ref->getMethod('__invoke');
        $invokeAttributes = $invokeMethod->getAttributes(\Symfony\Component\Routing\Attribute\Route::class);
        self::assertCount(1, $invokeAttributes);
        self::assertSame('admin_security', $invokeAttributes[0]->newInstance()->getName());

        // apiToken route
        $apiMethod = $ref->getMethod('apiToken');
        $apiAttributes = $apiMethod->getAttributes(\Symfony\Component\Routing\Attribute\Route::class);
        self::assertCount(1, $apiAttributes);
        self::assertSame('admin_security_api_token', $apiAttributes[0]->newInstance()->getName());
    }
}
