@@ -116,62 +116,62 @@ public function decide(\Traversable $results): bool
116
116
$ this ->assertTrue ($ manager ->decide ($ token , ['ROLE_FOO ' ]));
117
117
}
118
118
119
- public function getStrategyTests ()
119
+ public static function getStrategyTests (): array
120
120
{
121
121
return [
122
122
// 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 ],
128
128
129
129
// 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 ],
133
133
134
- [AccessDecisionManager::STRATEGY_CONSENSUS , $ this -> getVoters (0 , 0 , 1 ), false , true , false ],
134
+ [AccessDecisionManager::STRATEGY_CONSENSUS , self :: getVoters (0 , 0 , 1 ), false , true , false ],
135
135
136
- [AccessDecisionManager::STRATEGY_CONSENSUS , $ this -> getVoters (0 , 0 , 1 ), true , true , true ],
136
+ [AccessDecisionManager::STRATEGY_CONSENSUS , self :: getVoters (0 , 0 , 1 ), true , true , true ],
137
137
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 ],
140
140
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 ],
143
143
144
144
// 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 ],
148
148
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 ],
151
151
152
152
// priority
153
153
[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 ),
158
158
], true , true , true ],
159
159
160
160
[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 ),
165
165
], true , true , false ],
166
166
167
167
[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 ),
170
170
], false , true , false ],
171
171
172
172
[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 ),
175
175
], true , true , true ],
176
176
];
177
177
}
@@ -338,30 +338,37 @@ public function testCacheableVotersWithMultipleAttributesAndNonString()
338
338
$ this ->assertTrue ($ manager ->decide ($ token , ['foo ' , 1337 ], 'bar ' , true ));
339
339
}
340
340
341
- protected function getVoters ($ grants , $ denies , $ abstains )
341
+ protected static function getVoters ($ grants , $ denies , $ abstains ): array
342
342
{
343
343
$ voters = [];
344
344
for ($ i = 0 ; $ i < $ grants ; ++$ i ) {
345
- $ voters [] = $ this -> getVoter (VoterInterface::ACCESS_GRANTED );
345
+ $ voters [] = self :: getVoter (VoterInterface::ACCESS_GRANTED );
346
346
}
347
347
for ($ i = 0 ; $ i < $ denies ; ++$ i ) {
348
- $ voters [] = $ this -> getVoter (VoterInterface::ACCESS_DENIED );
348
+ $ voters [] = self :: getVoter (VoterInterface::ACCESS_DENIED );
349
349
}
350
350
for ($ i = 0 ; $ i < $ abstains ; ++$ i ) {
351
- $ voters [] = $ this -> getVoter (VoterInterface::ACCESS_ABSTAIN );
351
+ $ voters [] = self :: getVoter (VoterInterface::ACCESS_ABSTAIN );
352
352
}
353
353
354
354
return $ voters ;
355
355
}
356
356
357
- protected function getVoter ($ vote )
357
+ protected static function getVoter ($ vote )
358
358
{
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 ;
363
361
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
+ };
365
372
}
366
373
367
374
private function getExpectedVoter (int $ vote ): VoterInterface
0 commit comments