8000 minor #48988 [Tests] New iteration of removing `$this` occurrences in… · symfony/security-core@dd5972d · GitHub
[go: up one dir, main page]

Skip to content

Commit dd5972d

Browse files
minor #48988 [Tests] New iteration of removing $this occurrences in future static data providers (alexandre-daubois)
This PR was merged into the 5.4 branch. Discussion ---------- [Tests] New iteration of removing `$this` occurrences in future static data providers | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes-ish | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Easing symfony/symfony#48668 (comment) | License | MIT | Doc PR | _NA_ Follow-up of #48980 Commits ------- 1386ac2e81 [Tests] New iteration of removing `$this` occurrences in future static data providers
2 parents 76fe5a7 + 0358f5e commit dd5972d

5 files changed

+46
-37
lines changed

Test/AccessDecisionStrategyTestCase.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,36 @@ abstract public function provideStrategyTests(): iterable;
4545
/**
4646
* @return VoterInterface[]
4747
*/
48-
final protected function getVoters(int $grants, int $denies, int $abstains): array
48+
final protected static function getVoters(int $grants, int $denies, int $abstains): array
4949
{
5050
$voters = [];
5151
for ($i = 0; $i < $grants; ++$i) {
52-
$voters[] = $this->getVoter(VoterInterface::ACCESS_GRANTED);
52+
$voters[] = static::getVoter(VoterInterface::ACCESS_GRANTED);
5353
}
5454
for ($i = 0; $i < $denies; ++$i) {
55-
$voters[] = $this->getVoter(VoterInterface::ACCESS_DENIED);
55+
$voters[] = static::getVoter(VoterInterface::ACCESS_DENIED);
5656
}
5757
for ($i = 0; $i < $abstains; ++$i) {
58-
$voters[] = $this->getVoter(VoterInterface::ACCESS_ABSTAIN);
58+
$voters[] = static::getVoter(VoterInterface::ACCESS_ABSTAIN);
5959
}
6060

6161
return $voters;
6262
}
6363

64-
final protected function getVoter(int $vote): VoterInterface
64+
final protected static function getVoter(int $vote): VoterInterface
6565
{
66-
$voter = $this->createMock(VoterInterface::class);
67-
$voter->method('vote')->willReturn($vote);
66+
return new class($vote) implements VoterInterface {
67+
private $vote;
6868

69-
return $voter;
69+
public function __construct(int $vote)
70+
{
71+
$this->vote = $vote;
72+
}
73+
74+
public function vote(TokenInterface $token, $subject, array $attributes): int
75+
{
76+
return $this->vote;
77+
}
78+
};
7079
}
7180
}

Tests/Authorization/Strategy/AffirmativeStrategyTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ public function provideStrategyTests(): iterable
2020
{
2121
$strategy = new AffirmativeStrategy();
2222

23-
yield [$strategy, $this->getVoters(1, 0, 0), true];
24-
yield [$strategy, $this->getVoters(1, 2, 0), true];
25-
yield [$strategy, $this->getVoters(0, 1, 0), false];
26-
yield [$strategy, $this->getVoters(0, 0, 1), false];
23+
yield [$strategy, static::getVoters(1, 0, 0), true];
24+
yield [$strategy, static::getVoters(1, 2, 0), true];
25+
yield [$strategy, static::getVoters(0, 1, 0), false];
26+
yield [$strategy, static::getVoters(0, 0, 1), false];
2727

2828
$strategy = new AffirmativeStrategy(true);
2929

30-
yield [$strategy, $this->getVoters(0, 0, 1), true];
30+
yield [$strategy, static::getVoters(0, 0, 1), true];
3131
}
3232
}

Tests/Authorization/Strategy/ConsensusStrategyTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ public function provideStrategyTests(): iterable
2020
{
2121
$strategy = new ConsensusStrategy();
2222

23-
yield [$strategy, $this->getVoters(1, 0, 0), true];
24-
yield [$strategy, $this->getVoters(1, 2, 0), false];
25-
yield [$strategy, $this->getVoters(2, 1, 0), true];
26-
yield [$strategy, $this->getVoters(0, 0, 1), false];
23+
yield [$strategy, static::getVoters(1, 0, 0), true];
24+
yield [$strategy, static::getVoters(1, 2, 0), false];
25+
yield [$strategy, static::getVoters(2, 1, 0), true];
26+
yield [$strategy, static::getVoters(0, 0, 1), false];
2727

28-
yield [$strategy, $this->getVoters(2, 2, 0), true];
29-
yield [$strategy, $this->getVoters(2, 2, 1), true];
28+
yield [$strategy, static::getVoters(2, 2, 0), true];
29+
yield [$strategy, static::getVoters(2, 2, 1), true];
3030

3131
$strategy = new ConsensusStrategy(true);
3232

33-
yield [ B41A $strategy, $this->getVoters(0, 0, 1), true];
33+
yield [$strategy, static::getVoters(0, 0, 1), true];
3434

3535
$strategy = new ConsensusStrategy(false, false);
3636

37-
yield [$strategy, $this->getVoters(2, 2, 0), false];
38-
yield [$strategy, $this->getVoters(2, 2, 1), false];
37+
yield [$strategy, static::getVoters(2, 2, 0), false];
38+
yield [$strategy, static::getVoters(2, 2, 1), false];
3939
}
4040
}

Tests/Authorization/Strategy/PriorityStrategyTest.php

Lines changed: 10 additions & 10 deletions
-
$this->getVoter(VoterInterface::ACCESS_DENIED),
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ public function provideStrategyTests(): iterable
2222
$strategy = new PriorityStrategy();
2323

2424
yield [$strategy, [
25-
$this->getVoter(VoterInterface::ACCESS_ABSTAIN),
26-
$this->getVoter(VoterInterface::ACCESS_GRANTED),
27-
$this->getVoter(VoterInterface::ACCESS_DENIED),
28-
$this->getVoter(VoterInterface::ACCESS_DENIED),
25+
static::getVoter(VoterInterface::ACCESS_ABSTAIN),
26+
static::getVoter(VoterInterface::ACCESS_GRANTED),
27+
static::getVoter(VoterInterface::ACCESS_DENIED),
28+
static::getVoter(VoterInterface::ACCESS_DENIED),
2929
], true];
3030

3131
yield [$strategy, [
32-
$this->getVoter(VoterInterface::ACCESS_ABSTAIN),
33
34-
$this->getVoter(VoterInterface::ACCESS_GRANTED),
35-
$this->getVoter(VoterInterface::ACCESS_GRANTED),
32+
static::getVoter(VoterInterface::ACCESS_ABSTAIN),
33+
static::getVoter(VoterInterface::ACCESS_DENIED),
34+
static::getVoter(VoterInterface::ACCESS_GRANTED),
35+
static::getVoter(VoterInterface::ACCESS_GRANTED),
3636
], false];
3737

38-
yield [$strategy, $this->getVoters(0, 0, 2), false];
38+
yield [$strategy, static::getVoters(0, 0, 2), false];
3939

4040
$strategy = new PriorityStrategy(true);
4141

42-
yield [$strategy, $this->getVoters(0, 0, 2), true];
42+
yield [$strategy, static::getVoters(0, 0, 2), true];
4343
}
4444
}

Tests/Authorization/Strategy/UnanimousStrategyTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ public function provideStrategyTests(): iterable
2020
{
2121
$strategy = new UnanimousStrategy();
2222

23-
yield [$strategy, $this->getVoters(1, 0, 0), true];
24-
yield [$strategy, $this->getVoters(1, 0, 1), true];
25-
yield [$strategy, $this->getVoters(1, 1, 0), false];
23+
yield [$strategy, static::getVoters(1, 0, 0), true];
24+
yield [$strategy, static::getVoters(1, 0, 1), true];
25+
yield [$strategy, static::getVoters(1, 1, 0), false];
2626

27-
yield [$strategy, $this->getVoters(0, 0, 2), false];
27+
yield [$strategy, static::getVoters(0, 0, 2), false];
2828

2929
$strategy = new UnanimousStrategy(true);
3030

31-
yield [$strategy, $this->getVoters(0, 0, 2), true];
31+
yield [$strategy, static::getVoters(0, 0, 2), true];
3232
}
3333
}

0 commit comments

Comments
 (0)
0