1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace League\Tactician\Bundle\Tests\Security\Voter; |
4
|
|
|
|
5
|
|
|
use League\Tactician\Bundle\Security\Voter\HandleCommandVoter; |
6
|
|
|
use League\Tactician\Bundle\Tests\Fake\FakeCommand; |
7
|
|
|
use Mockery; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; |
10
|
|
|
use Symfony\Component\Security\Core\Authorization\AccessDecisionManager; |
11
|
|
|
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Unit test for the handle command voter |
15
|
|
|
* |
16
|
|
|
* @author Ron Rademaker |
17
|
|
|
*/ |
18
|
|
|
class HandleCommandVoterTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* The decision manager mock. |
22
|
|
|
*/ |
23
|
|
|
private $decisionManager; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Set up. |
27
|
|
|
*/ |
28
|
|
|
public function setUp() |
29
|
|
|
{ |
30
|
|
|
$this->decisionManager = Mockery::mock(AccessDecisionManager::class); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Tests the vote method. |
35
|
|
|
* |
36
|
|
|
* @param type $attribute |
37
|
|
|
* @param type $subject |
38
|
|
|
* @param type $decision |
39
|
|
|
* @param type $default |
|
|
|
|
40
|
|
|
* @param type $mapping |
41
|
|
|
* @param type $expected |
42
|
|
|
* |
43
|
|
|
* @dataProvider provideTestVoteData |
44
|
|
|
*/ |
45
|
|
|
public function testVote($attribute, $subject, $decision, $mapping, $expected) |
46
|
|
|
{ |
47
|
|
|
$this->decisionManager->shouldReceive('decide')->andReturn($decision); |
48
|
|
|
$voter = new HandleCommandVoter($this->decisionManager, $mapping); |
49
|
|
|
$tokenMock = Mockery::mock(TokenInterface::class); |
50
|
|
|
|
51
|
|
|
$this->assertEquals($expected, $voter->vote($tokenMock, $subject, [$attribute])); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Gets the testdata for the vote test. |
56
|
|
|
* |
57
|
|
|
* @return array |
58
|
|
|
*/ |
59
|
|
|
public function provideTestVoteData() |
60
|
|
|
{ |
61
|
|
|
return [ |
62
|
|
|
['handle', new FakeCommand, true, [], VoterInterface::ACCESS_DENIED], |
63
|
|
|
['handle', null, true, [], VoterInterface::ACCESS_ABSTAIN], |
64
|
|
|
['create', null, true, [], VoterInterface::ACCESS_ABSTAIN], |
65
|
|
|
['create', new FakeCommand, true, [], VoterInterface::ACCESS_ABSTAIN], |
66
|
|
|
['handle', new FakeCommand, false, [], VoterInterface::ACCESS_DENIED], |
67
|
|
|
['handle', new FakeCommand, false, [FakeCommand::class => ['ROLE_USER']], VoterInterface::ACCESS_DENIED], |
68
|
|
|
['handle', new FakeCommand, true, [FakeCommand::class => ['ROLE_USER']], VoterInterface::ACCESS_GRANTED], |
69
|
|
|
['handle', new FakeCommand, false, ['someOtherCommand' => ['ROLE_USER']], VoterInterface::ACCESS_DENIED], |
70
|
|
|
]; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.