createTrustResolver example

use Symfony\Component\Security\Core\Authorization\ExpressionLanguage;
use Symfony\Component\Security\Core\Authorization\Voter\ExpressionVoter;
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;

class ExpressionVoterTest extends TestCase
{
    /** * @dataProvider getVoteTests */
    public function testVoteWithTokenThatReturnsRoleNames($roles$attributes$expected$tokenExpectsGetRoles = true, $expressionLanguageExpectsEvaluate = true)
    {
        $voter = new ExpressionVoter($this->createExpressionLanguage($expressionLanguageExpectsEvaluate)$this->createTrustResolver()$this->createAuthorizationChecker());

        $this->assertSame($expected$voter->vote($this->getTokenWithRoleNames($roles$tokenExpectsGetRoles), null, $attributes));
    }

    public static function getVoteTests()
    {
        return [
            [[][], VoterInterface::ACCESS_ABSTAIN, false, false],
            [[]['FOO'], VoterInterface::ACCESS_ABSTAIN, false, false],

            [[][self::createExpression()], VoterInterface::ACCESS_DENIED, true, false],

            [[
        $this->assertInstanceOf(\LogicException::class$event->getThrowable());
        $this->assertStringEndsWith('start()" method must return a Response object ("string" returned).', $event->getThrowable()->getMessage());
    }

    /** * @dataProvider getAccessDeniedExceptionProvider */
    public function testAccessDeniedExceptionFullFledgedAndWithoutAccessDeniedHandlerAndWithoutErrorPage(\Exception $exception, \Exception $eventException = null)
    {
        $event = $this->createEvent($exception);

        $listener = $this->createExceptionListener(null, $this->createTrustResolver(true));
        $listener->onKernelException($event);

        $this->assertNull($event->getResponse());
        $this->assertSame($eventException ?? $exception$event->getThrowable()->getPrevious());
    }

    /** * @dataProvider getAccessDeniedExceptionProvider */
    public function testAccessDeniedExceptionFullFledgedAndWithoutAccessDeniedHandlerAndWithErrorPage(\Exception $exception, \Exception $eventException = null)
    {
        
Home | Imprint | This part of the site doesn't use cookies.