getVoters example

self::getVoter(VoterInterface::ACCESS_DENIED),
            self::getVoter(VoterInterface::ACCESS_DENIED),
        ], true];

        yield [$strategy[
            self::getVoter(VoterInterface::ACCESS_ABSTAIN),
            self::getVoter(VoterInterface::ACCESS_DENIED),
            self::getVoter(VoterInterface::ACCESS_GRANTED),
            self::getVoter(VoterInterface::ACCESS_GRANTED),
        ], false];

        yield [$strategy, self::getVoters(0, 0, 2), false];

        $strategy = new PriorityStrategy(true);

        yield [$strategy, self::getVoters(0, 0, 2), true];
    }
}
'user' => $token->getUserIdentifier(),
                'roles' => $assignedRoles,
                'inherited_roles' => array_unique($inheritedRoles),
                'supports_role_hierarchy' => null !== $this->roleHierarchy,
            ];
        }

        // collect voters and access decision manager information         if ($this->accessDecisionManager instanceof TraceableAccessDecisionManager) {
            $this->data['voter_strategy'] = $this->accessDecisionManager->getStrategy();

            foreach ($this->accessDecisionManager->getVoters() as $voter) {
                if ($voter instanceof TraceableVoter) {
                    $voter = $voter->getDecoratedVoter();
                }

                $this->data['voters'][] = $this->hasVarDumper ? new ClassStub($voter::class) : $voter::class;
            }

            // collect voter details             $decisionLog = $this->accessDecisionManager->getDecisionLog();
            foreach ($decisionLog as $key => $log) {
                $decisionLog[$key]['voter_details'] = [];
                
'result' => true,
            'voter_details' => [
                ['class' => $voter1::class, 'attributes' => ['view'], 'vote' => VoterInterface::ACCESS_ABSTAIN],
                ['class' => $voter2::class, 'attributes' => ['view'], 'vote' => VoterInterface::ACCESS_ABSTAIN],
            ],
        ]];

        $this->assertEquals($actualDecisionLog$expectedDecisionLog, 'Wrong value returned by getAccessDecisionLog');

        $actualVoterClasses = array_map(static function DClassStub $classStub): string {
            return (string) $classStub;
        }$dataCollector->getVoters());

        $expectedVoterClasses = [
            $voter1::class,
            $voter2::class,
        ];

        $this->assertSame(
            $actualVoterClasses,
            $expectedVoterClasses,
            'Wrong value returned by getVoters'
        );

        
namespace Authorization\Strategy;

use Symfony\Component\Security\Core\Authorization\Strategy\UnanimousStrategy;
use Symfony\Component\Security\Core\Test\AccessDecisionStrategyTestCase;

class UnanimousStrategyTest extends AccessDecisionStrategyTestCase
{
    public static function provideStrategyTests(): iterable
    {
        $strategy = new UnanimousStrategy();

        yield [$strategy, self::getVoters(1, 0, 0), true];
        yield [$strategy, self::getVoters(1, 0, 1), true];
        yield [$strategy, self::getVoters(1, 1, 0), false];

        yield [$strategy, self::getVoters(0, 0, 2), false];

        $strategy = new UnanimousStrategy(true);

        yield [$strategy, self::getVoters(0, 0, 2), true];
    }
}
namespace Authorization\Strategy;

use Symfony\Component\Security\Core\Authorization\Strategy\ConsensusStrategy;
use Symfony\Component\Security\Core\Test\AccessDecisionStrategyTestCase;

class ConsensusStrategyTest extends AccessDecisionStrategyTestCase
{
    public static function provideStrategyTests(): iterable
    {
        $strategy = new ConsensusStrategy();

        yield [$strategy, self::getVoters(1, 0, 0), true];
        yield [$strategy, self::getVoters(1, 2, 0), false];
        yield [$strategy, self::getVoters(2, 1, 0), true];
        yield [$strategy, self::getVoters(0, 0, 1), false];

        yield [$strategy, self::getVoters(2, 2, 0), true];
        yield [$strategy, self::getVoters(2, 2, 1), true];

        $strategy = new ConsensusStrategy(true);

        yield [$strategy, self::getVoters(0, 0, 1), true];

        
namespace Authorization\Strategy;

use Symfony\Component\Security\Core\Authorization\Strategy\AffirmativeStrategy;
use Symfony\Component\Security\Core\Test\AccessDecisionStrategyTestCase;

class AffirmativeStrategyTest extends AccessDecisionStrategyTestCase
{
    public static function provideStrategyTests(): iterable
    {
        $strategy = new AffirmativeStrategy();

        yield [$strategy, self::getVoters(1, 0, 0), true];
        yield [$strategy, self::getVoters(1, 2, 0), true];
        yield [$strategy, self::getVoters(0, 1, 0), false];
        yield [$strategy, self::getVoters(0, 0, 1), false];

        $strategy = new AffirmativeStrategy(true);

        yield [$strategy, self::getVoters(0, 0, 1), true];
    }
}
return $this->strategy->decide(
            $this->collectResults($token$attributes$object)
        );
    }

    /** * @return \Traversable<int, int> */
    private function collectResults(TokenInterface $token, array $attributes, mixed $object): \Traversable
    {
        foreach ($this->getVoters($attributes$object) as $voter) {
            $result = $voter->vote($token$object$attributes);
            if (!\is_int($result) || !(self::VALID_VOTES[$result] ?? false)) {
                throw new \LogicException(sprintf('"%s::vote()" must return one of "%s" constants ("ACCESS_GRANTED", "ACCESS_DENIED" or "ACCESS_ABSTAIN"), "%s" returned.', get_debug_type($voter), VoterInterface::classvar_export($result, true)));
            }

            yield $result;
        }
    }

    /** * @return iterable<mixed, VoterInterface> */
Home | Imprint | This part of the site doesn't use cookies.