<?php

declare(strict_types=1);

namespace App\Tests\Unit\Doctrine;

use App\Entity\Access\Access;
use App\Entity\Organization\Organization;
use Doctrine\ORM\QueryBuilder;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;

class ExtensionTestCase extends TestCase
{
    protected Security|MockObject $security;
    protected RequestStack|MockObject $requestStack;
    protected Request|MockObject $request;
    protected QueryBuilder|MockObject $queryBuilder;
    protected Access|MockObject $user;
    protected TokenInterface|MockObject $token;
    protected Organization|MockObject $organization;

    protected function setUp(): void
    {
        $this->security = $this->createMock(Security::class);
        $this->requestStack = $this->createMock(RequestStack::class);
        $this->request = $this->createMock(Request::class);
        $this->queryBuilder = $this->createMock(QueryBuilder::class);
        $this->user = $this->createMock(Access::class);
        $this->token = $this->createMock(TokenInterface::class);
        $this->organization = $this->createMock(Organization::class);
    }

    /**
     * Utilise la réflexion pour invoquer la méthode protégée 'addWhere' sur l'extension donnée.
     *
     * @param object       $extension    l'instance de l'extension sur laquelle invoquer la méthode 'addWhere'
     * @param QueryBuilder $queryBuilder l'objet QueryBuilder à passer à la méthode 'addWhere'
     * @param mixed        ...$params    les autres paramètres à passer à la méthode 'addWhere'.
     *
     * @throws \ReflectionException
     */
    protected function invokeAddWhere($extension, $queryBuilder, ...$params): void
    {
        $reflection = new \ReflectionClass($extension);
        $method = $reflection->getMethod('addWhere');
        $method->setAccessible(true);
        $method->invoke($extension, $queryBuilder, ...$params);
    }
}
