Skip to content

Commit 694f488

Browse files
Merge branch '6.2' into 6.3
* 6.2: [Tests] Migrate tests to static data providers [Cache] Only validate dbindex parameter when applicable
2 parents d0bbaa0 + 837f6c4 commit 694f488

File tree

6 files changed

+52
-22
lines changed

6 files changed

+52
-22
lines changed

Tests/Authentication/Token/AbstractTokenTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testGetUserIdentifier($user, string $username)
2828
$this->assertEquals($username, $token->getUserIdentifier());
2929
}
3030

31-
public function provideUsers()
31+
public static function provideUsers()
3232
{
3333
yield [new InMemoryUser('fabien', null), 'fabien'];
3434
}

Tests/Authorization/AccessDecisionManagerTest.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -227,30 +227,37 @@ public function testCacheableVotersWithMultipleAttributesAndNonString()
227227
$this->assertTrue($manager->decide($token, ['foo', 1337], 'bar', true));
228228
}
229229

230-
protected function getVoters($grants, $denies, $abstains)
230+
protected static function getVoters($grants, $denies, $abstains): array
231231
{
232232
$voters = [];
233233
for ($i = 0; $i < $grants; ++$i) {
234-
$voters[] = $this->getVoter(VoterInterface::ACCESS_GRANTED);
234+
$voters[] = self::getVoter(VoterInterface::ACCESS_GRANTED);
235235
}
236236
for ($i = 0; $i < $denies; ++$i) {
237-
$voters[] = $this->getVoter(VoterInterface::ACCESS_DENIED);
237+
$voters[] = self::getVoter(VoterInterface::ACCESS_DENIED);
238238
}
239239
for ($i = 0; $i < $abstains; ++$i) {
240-
$voters[] = $this->getVoter(VoterInterface::ACCESS_ABSTAIN);
240+
$voters[] = self::getVoter(VoterInterface::ACCESS_ABSTAIN);
241241
}
242242

243243
return $voters;
244244
}
245245

246-
protected function getVoter($vote)
246+
protected static function getVoter($vote)
247247
{
248-
$voter = $this->createMock(VoterInterface::class);
249-
$voter->expects($this->any())
250-
->method('vote')
251-
->willReturn($vote);
248+
return new class($vote) implements VoterInterface {
249+
private $vote;
252250

253-
return $voter;
251+
public function __construct(int $vote)
252+
{
253+
$this->vote = $vote;
254+
}
255+
256+
public function vote(TokenInterface $token, $subject, array $attributes)
257+
{
258+
return $this->vote;
259+
}
260+
};
254261
}
255262

256263
private function getExpectedVoter(int $vote): VoterInterface

Tests/Authorization/TraceableAccessDecisionManagerTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
1818
use Symfony\Component\Security\Core\Authorization\TraceableAccessDecisionManager;
1919
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
20+
use Symfony\Component\Security\Core\Tests\Fixtures\DummyVoter;
2021

2122
class TraceableAccessDecisionManagerTest extends TestCase
2223
{
@@ -49,10 +50,10 @@ public function testDecideLog(array $expectedLog, array $attributes, $object, ar
4950
$this->assertEquals($expectedLog, $adm->getDecisionLog());
5051
}
5152

52-
public function provideObjectsAndLogs(): \Generator
53+
public static function provideObjectsAndLogs(): \Generator
5354
{
54-
$voter1 = $this->getMockForAbstractClass(VoterInterface::class);
55-
$voter2 = $this->getMockForAbstractClass(VoterInterface::class);
55+
$voter1 = new DummyVoter();
56+
$voter2 = new DummyVoter();
5657

5758
yield [
5859
[[

Tests/Authorization/Voter/ExpressionVoterTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ public function testVoteWithTokenThatReturnsRoleNames($roles, $attributes, $expe
3232
$this->assertSame($expected, $voter->vote($this->getTokenWithRoleNames($roles, $tokenExpectsGetRoles), null, $attributes));
3333
}
3434

35-
public function getVoteTests()
35+
public static function getVoteTests()
3636
{
3737
return [
3838
[[], [], VoterInterface::ACCESS_ABSTAIN, false, false],
3939
[[], ['FOO'], VoterInterface::ACCESS_ABSTAIN, false, false],
4040

41-
[[], [$this->createExpression()], VoterInterface::ACCESS_DENIED, true, false],
41+
[[], [self::createExpression()], VoterInterface::ACCESS_DENIED, true, false],
4242

43-
[['ROLE_FOO'], [$this->createExpression(), $this->createExpression()], VoterInterface::ACCESS_GRANTED],
44-
[['ROLE_BAR', 'ROLE_FOO'], [$this->createExpression()], VoterInterface::ACCESS_GRANTED],
43+
[['ROLE_FOO'], [self::createExpression(), self::createExpression()], VoterInterface::ACCESS_GRANTED],
44+
[['ROLE_BAR', 'ROLE_FOO'], [self::createExpression()], VoterInterface::ACCESS_GRANTED],
4545
];
4646
}
4747

@@ -81,8 +81,8 @@ protected function createAuthorizationChecker()
8181
return $this->createMock(AuthorizationCheckerInterface::class);
8282
}
8383

84-
protected function createExpression()
84+
protected static function createExpression()
8585
{
86-
return $this->createMock(Expression::class);
86+
return new Expression('');
8787
}
8888
}

Tests/Authorization/Voter/VoterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected function setUp(): void
2525
$this->token = $this->createMock(TokenInterface::class);
2626
}
2727

28-
public function getTests()
28+
public static function getTests(): array
2929
{
3030
$voter = new VoterTest_Voter();
3131
$integerVoter = new IntegerVoterTest_Voter();
@@ -41,7 +41,7 @@ public function getTests()
4141

4242
[$voter, ['DELETE'], VoterInterface::ACCESS_ABSTAIN, new \stdClass(), 'ACCESS_ABSTAIN if no attribute is supported'],
4343

44-
[$voter, ['EDIT'], VoterInterface::ACCESS_ABSTAIN, $this, 'ACCESS_ABSTAIN if class is not supported'],
44+
[$voter, ['EDIT'], VoterInterface::ACCESS_ABSTAIN, new class() {}, 'ACCESS_ABSTAIN if class is not supported'],
4545

4646
[$voter, ['EDIT'], VoterInterface::ACCESS_ABSTAIN, null, 'ACCESS_ABSTAIN if object is null'],
4747

Tests/Fixtures/DummyVoter.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Security\Core\Tests\Fixtures;
13+
14+
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
15+
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
16+
17+
final class DummyVoter implements VoterInterface
18+
{
19+
public function vote(TokenInterface $token, $subject, array $attributes): int
20+
{
21+
}
22+
}

0 commit comments

Comments
 (0)