Completed
Push — master ( 1c5373...ea381d )
by Ross
9s
created

HandleCommandVoterTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 0
loc 55
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testVote() 0 8 1
A provideTestVoteData() 0 13 1
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
0 ignored issues
show
Bug introduced by
There is no parameter named $default. Was it maybe removed?

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 method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
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