These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 Mockery\MockInterface; |
||
9 | use PHPUnit\Framework\TestCase; |
||
10 | use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; |
||
11 | use Symfony\Component\Security\Core\Authorization\AccessDecisionManager; |
||
12 | use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface; |
||
13 | |||
14 | /** |
||
15 | * Unit test for the handle command voter |
||
16 | * |
||
17 | * @author Ron Rademaker |
||
18 | */ |
||
19 | class HandleCommandVoterTest extends TestCase |
||
20 | { |
||
21 | /** |
||
22 | * @var AccessDecisionManager|MockInterface |
||
23 | */ |
||
24 | private $decisionManager; |
||
25 | |||
26 | public function setUp(): void |
||
27 | { |
||
28 | $this->decisionManager = Mockery::mock(AccessDecisionManager::class); |
||
0 ignored issues
–
show
|
|||
29 | } |
||
30 | |||
31 | public function testAKnownCommandWillBeDelegatedToTheDecisionManager() |
||
32 | { |
||
33 | $tokenMock = Mockery::mock(TokenInterface::class); |
||
34 | |||
35 | $voter = new HandleCommandVoter($this->decisionManager, [FakeCommand::class => ['ROLE_USER']]); |
||
36 | |||
37 | $this->decisionManager |
||
0 ignored issues
–
show
The method
shouldReceive does only exist in Mockery\MockInterface , but not in Symfony\Component\Securi...n\AccessDecisionManager .
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
Loading history...
|
|||
38 | ->shouldReceive('decide') |
||
39 | ->with($tokenMock, ['ROLE_USER']) |
||
40 | ->andReturn(true) |
||
41 | ->once(); |
||
42 | |||
43 | $this->assertEquals(VoterInterface::ACCESS_GRANTED, $voter->vote($tokenMock, new FakeCommand(), ['handle'])); |
||
0 ignored issues
–
show
$tokenMock is of type object<Mockery\LegacyMockInterface> , but the function expects a object<Symfony\Component...n\Token\TokenInterface> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @dataProvider provideTestVoteData |
||
48 | */ |
||
49 | public function testAbstainOrDenyScenarios($attribute, $subject, $expected) |
||
50 | { |
||
51 | // In the test cases provided, we either abstain from voting or refuse |
||
52 | // to do it since there's no declared mapping. Therefore, it would be |
||
53 | // an error to ever call the decision manager. |
||
54 | $this->decisionManager->shouldReceive('decide')->never(); |
||
0 ignored issues
–
show
The method
shouldReceive does only exist in Mockery\MockInterface , but not in Symfony\Component\Securi...n\AccessDecisionManager .
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
Loading history...
|
|||
55 | |||
56 | $voter = new HandleCommandVoter($this->decisionManager, []); |
||
57 | $tokenMock = Mockery::mock(TokenInterface::class); |
||
58 | |||
59 | $this->assertEquals($expected, $voter->vote($tokenMock, $subject, [$attribute])); |
||
0 ignored issues
–
show
$tokenMock is of type object<Mockery\LegacyMockInterface> , but the function expects a object<Symfony\Component...n\Token\TokenInterface> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
60 | } |
||
61 | |||
62 | /** |
||
63 | * Gets the testdata for the vote test. |
||
64 | * |
||
65 | * @return array |
||
66 | */ |
||
67 | public function provideTestVoteData() |
||
68 | { |
||
69 | return [ |
||
70 | 'abstain when not handling a command, but using the handle attribute' => [ |
||
71 | 'handle', |
||
72 | null, |
||
73 | VoterInterface::ACCESS_ABSTAIN |
||
74 | ], |
||
75 | 'abstain when not handling a command and not using the handle attribute' => [ |
||
76 | 'create', |
||
77 | null, |
||
78 | VoterInterface::ACCESS_ABSTAIN |
||
79 | ], |
||
80 | 'abstain when handling a command and not using the handle attribute' => [ |
||
81 | 'create', |
||
82 | new FakeCommand, |
||
83 | VoterInterface::ACCESS_ABSTAIN |
||
84 | ], |
||
85 | 'default access is false' => [ |
||
86 | 'handle', |
||
87 | new FakeCommand, |
||
88 | VoterInterface::ACCESS_DENIED |
||
89 | ], |
||
90 | ]; |
||
91 | } |
||
92 | } |
||
93 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..