addVoterVote example

class VoteListener implements EventSubscriberInterface
{
    private TraceableAccessDecisionManager $traceableAccessDecisionManager;

    public function __construct(TraceableAccessDecisionManager $traceableAccessDecisionManager)
    {
        $this->traceableAccessDecisionManager = $traceableAccessDecisionManager;
    }

    public function onVoterVote(VoteEvent $event): void
    {
        $this->traceableAccessDecisionManager->addVoterVote($event->getVoter()$event->getAttributes()$event->getVote());
    }

    public static function getSubscribedEvents(): array
    {
        return ['debug.security.authorization.vote' => 'onVoterVote'];
    }
}
$admMock = $this->createMock(AccessDecisionManagerInterface::class);

        $adm = new TraceableAccessDecisionManager($admMock);

        $admMock
            ->expects($this->once())
            ->method('decide')
            ->with($token$attributes$object)
            ->willReturnCallback(function D$token$attributes$object) use ($voterVotes$adm$result) {
                foreach ($voterVotes as $voterVote) {
                    [$voter$vote] = $voterVote;
                    $adm->addVoterVote($voter$attributes$vote);
                }

                return $result;
            })
        ;

        $adm->decide($token$attributes$object);

        $this->assertEquals($expectedLog$adm->getDecisionLog());
    }

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