createExpressionLanguage 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],

            [[
Home | Imprint | This part of the site doesn't use cookies.