@@ -116,62 +116,62 @@ public function decide(\Traversable $results): bool
116116 $ this ->assertTrue ($ manager ->decide ($ token , ['ROLE_FOO ' ]));
117117 }
118118
119- public function getStrategyTests ()
119+ public static function getStrategyTests (): array
120120 {
121121 return [
122122 // affirmative
123- [AccessDecisionManager::STRATEGY_AFFIRMATIVE , $ this -> getVoters (1 , 0 , 0 ), false , true , true ],
124- [AccessDecisionManager::STRATEGY_AFFIRMATIVE , $ this -> getVoters (1 , 2 , 0 ), false , true , true ],
125- [AccessDecisionManager::STRATEGY_AFFIRMATIVE , $ this -> getVoters (0 , 1 , 0 ), false , true , false ],
126- [AccessDecisionManager::STRATEGY_AFFIRMATIVE , $ this -> getVoters (0 , 0 , 1 ), false , true , false ],
127- [AccessDecisionManager::STRATEGY_AFFIRMATIVE , $ this -> getVoters (0 , 0 , 1 ), true , true , true ],
123+ [AccessDecisionManager::STRATEGY_AFFIRMATIVE , self :: getVoters (1 , 0 , 0 ), false , true , true ],
124+ [AccessDecisionManager::STRATEGY_AFFIRMATIVE , self :: getVoters (1 , 2 , 0 ), false , true , true ],
125+ [AccessDecisionManager::STRATEGY_AFFIRMATIVE , self :: getVoters (0 , 1 , 0 ), false , true , false ],
126+ [AccessDecisionManager::STRATEGY_AFFIRMATIVE , self :: getVoters (0 , 0 , 1 ), false , true , false ],
127+ [AccessDecisionManager::STRATEGY_AFFIRMATIVE , self :: getVoters (0 , 0 , 1 ), true , true , true ],
128128
129129 // consensus
130- [AccessDecisionManager::STRATEGY_CONSENSUS , $ this -> getVoters (1 , 0 , 0 ), false , true , true ],
131- [AccessDecisionManager::STRATEGY_CONSENSUS , $ this -> getVoters (1 , 2 , 0 ), false , true , false ],
132- [AccessDecisionManager::STRATEGY_CONSENSUS , $ this -> getVoters (2 , 1 , 0 ), false , true , true ],
130+ [AccessDecisionManager::STRATEGY_CONSENSUS , self :: getVoters (1 , 0 , 0 ), false , true , true ],
131+ [AccessDecisionManager::STRATEGY_CONSENSUS , self :: getVoters (1 , 2 , 0 ), false , true , false ],
132+ [AccessDecisionManager::STRATEGY_CONSENSUS , self :: getVoters (2 , 1 , 0 ), false , true , true ],
133133
134- [AccessDecisionManager::STRATEGY_CONSENSUS , $ this -> getVoters (0 , 0 , 1 ), false , true , false ],
134+ [AccessDecisionManager::STRATEGY_CONSENSUS , self :: getVoters (0 , 0 , 1 ), false , true , false ],
135135
136- [AccessDecisionManager::STRATEGY_CONSENSUS , $ this -> getVoters (0 , 0 , 1 ), true , true , true ],
136+ [AccessDecisionManager::STRATEGY_CONSENSUS , self :: getVoters (0 , 0 , 1 ), true , true , true ],
137137
138- [AccessDecisionManager::STRATEGY_CONSENSUS , $ this -> getVoters (2 , 2 , 0 ), false , true , true ],
139- [AccessDecisionManager::STRATEGY_CONSENSUS , $ this -> getVoters (2 , 2 , 1 ), false , true , true ],
138+ [AccessDecisionManager::STRATEGY_CONSENSUS , self :: getVoters (2 , 2 , 0 ), false , true , true ],
139+ [AccessDecisionManager::STRATEGY_CONSENSUS , self :: getVoters (2 , 2 , 1 ), false , true , true ],
140140
141- [AccessDecisionManager::STRATEGY_CONSENSUS , $ this -> getVoters (2 , 2 , 0 ), false , false , false ],
142- [AccessDecisionManager::STRATEGY_CONSENSUS , $ this -> getVoters (2 , 2 , 1 ), false , false , false ],
141+ [AccessDecisionManager::STRATEGY_CONSENSUS , self :: getVoters (2 , 2 , 0 ), false , false , false ],
142+ [AccessDecisionManager::STRATEGY_CONSENSUS , self :: getVoters (2 , 2 , 1 ), false , false , false ],
143143
144144 // unanimous
145- [AccessDecisionManager::STRATEGY_UNANIMOUS , $ this -> getVoters (1 , 0 , 0 ), false , true , true ],
146- [AccessDecisionManager::STRATEGY_UNANIMOUS , $ this -> getVoters (1 , 0 , 1 ), false , true , true ],
147- [AccessDecisionManager::STRATEGY_UNANIMOUS , $ this -> getVoters (1 , 1 , 0 ), false , true , false ],
145+ [AccessDecisionManager::STRATEGY_UNANIMOUS , self :: getVoters (1 , 0 , 0 ), false , true , true ],
146+ [AccessDecisionManager::STRATEGY_UNANIMOUS , self :: getVoters (1 , 0 , 1 ), false , true , true ],
147+ [AccessDecisionManager::STRATEGY_UNANIMOUS , self :: getVoters (1 , 1 , 0 ), false , true , false ],
148148
149- [AccessDecisionManager::STRATEGY_UNANIMOUS , $ this -> getVoters (0 , 0 , 2 ), false , true , false ],
150- [AccessDecisionManager::STRATEGY_UNANIMOUS , $ this -> getVoters (0 , 0 , 2 ), true , true , true ],
149+ [AccessDecisionManager::STRATEGY_UNANIMOUS , self :: getVoters (0 , 0 , 2 ), false , true , false ],
150+ [AccessDecisionManager::STRATEGY_UNANIMOUS , self :: getVoters (0 , 0 , 2 ), true , true , true ],
151151
152152 // priority
153153 [AccessDecisionManager::STRATEGY_PRIORITY , [
154- $ this -> getVoter (VoterInterface::ACCESS_ABSTAIN ),
155- $ this -> getVoter (VoterInterface::ACCESS_GRANTED ),
156- $ this -> getVoter (VoterInterface::ACCESS_DENIED ),
157- $ this -> getVoter (VoterInterface::ACCESS_DENIED ),
154+ self :: getVoter (VoterInterface::ACCESS_ABSTAIN ),
155+ self :: getVoter (VoterInterface::ACCESS_GRANTED ),
156+ self :: getVoter (VoterInterface::ACCESS_DENIED ),
157+ self :: getVoter (VoterInterface::ACCESS_DENIED ),
158158 ], true , true , true ],
159159
160160 [AccessDecisionManager::STRATEGY_PRIORITY , [
161- $ this -> getVoter (VoterInterface::ACCESS_ABSTAIN ),
162- $ this -> getVoter (VoterInterface::ACCESS_DENIED ),
163- $ this -> getVoter (VoterInterface::ACCESS_GRANTED ),
164- $ this -> getVoter (VoterInterface::ACCESS_GRANTED ),
161+ self :: getVoter (VoterInterface::ACCESS_ABSTAIN ),
162+ self :: getVoter (VoterInterface::ACCESS_DENIED ),
163+ self :: getVoter (VoterInterface::ACCESS_GRANTED ),
164+ self :: getVoter (VoterInterface::ACCESS_GRANTED ),
165165 ], true , true , false ],
166166
167167 [AccessDecisionManager::STRATEGY_PRIORITY , [
168- $ this -> getVoter (VoterInterface::ACCESS_ABSTAIN ),
169- $ this -> getVoter (VoterInterface::ACCESS_ABSTAIN ),
168+ self :: getVoter (VoterInterface::ACCESS_ABSTAIN ),
169+ self :: getVoter (VoterInterface::ACCESS_ABSTAIN ),
170170 ], false , true , false ],
171171
172172 [AccessDecisionManager::STRATEGY_PRIORITY , [
173- $ this -> getVoter (VoterInterface::ACCESS_ABSTAIN ),
174- $ this -> getVoter (VoterInterface::ACCESS_ABSTAIN ),
173+ self :: getVoter (VoterInterface::ACCESS_ABSTAIN ),
174+ self :: getVoter (VoterInterface::ACCESS_ABSTAIN ),
175175 ], true , true , true ],
176176 ];
177177 }
@@ -338,30 +338,37 @@ public function testCacheableVotersWithMultipleAttributesAndNonString()
338338 $ this ->assertTrue ($ manager ->decide ($ token , ['foo ' , 1337 ], 'bar ' , true ));
339339 }
340340
341- protected function getVoters ($ grants , $ denies , $ abstains )
341+ protected static function getVoters ($ grants , $ denies , $ abstains ): array
342342 {
343343 $ voters = [];
344344 for ($ i = 0 ; $ i < $ grants ; ++$ i ) {
345- $ voters [] = $ this -> getVoter (VoterInterface::ACCESS_GRANTED );
345+ $ voters [] = self :: getVoter (VoterInterface::ACCESS_GRANTED );
346346 }
347347 for ($ i = 0 ; $ i < $ denies ; ++$ i ) {
348- $ voters [] = $ this -> getVoter (VoterInterface::ACCESS_DENIED );
348+ $ voters [] = self :: getVoter (VoterInterface::ACCESS_DENIED );
349349 }
350350 for ($ i = 0 ; $ i < $ abstains ; ++$ i ) {
351- $ voters [] = $ this -> getVoter (VoterInterface::ACCESS_ABSTAIN );
351+ $ voters [] = self :: getVoter (VoterInterface::ACCESS_ABSTAIN );
352352 }
353353
354354 return $ voters ;
355355 }
356356
357- protected function getVoter ($ vote )
357+ protected static function getVoter ($ vote )
358358 {
359- $ voter = $ this ->createMock (VoterInterface::class);
360- $ voter ->expects ($ this ->any ())
361- ->method ('vote ' )
362- ->willReturn ($ vote );
359+ return new class ($ vote ) implements VoterInterface {
360+ private $ vote ;
363361
364- return $ voter ;
362+ public function __construct (int $ vote )
363+ {
364+ $ this ->vote = $ vote ;
365+ }
366+
367+ public function vote (TokenInterface $ token , $ subject , array $ attributes )
368+ {
369+ return $ this ->vote ;
370+ }
371+ };
365372 }
366373
367374 private function getExpectedVoter (int $ vote ): VoterInterface
0 commit comments