Passed
Push — master ( 7f699f...e24ab0 )
by Kirill
03:06
created

CallableRuleTest::testAllow()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 20
rs 9.9
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Tests\Security\Rules;
13
14
use PHPUnit\Framework\TestCase;
15
use Spiral\Security\ActorInterface;
16
use Spiral\Security\RuleInterface;
17
use Spiral\Security\Rule\CallableRule;
18
19
class CallableRuleTest extends TestCase
20
{
21
    public const OPERATION = 'test';
22
    public const CONTEXT = [];
23
24
    public function testAllow(): void
25
    {
26
        /** @var ActorInterface $actor */
27
        $actor = $this->createMock(ActorInterface::class);
28
        $context = [];
29
30
        /** @var \PHPUnit_Framework_MockObject_MockObject|callable $callable */
31
        $callable = $this->getMockBuilder(\stdClass::class)
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\MockOb...ckBuilder::setMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/pull/3687 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

31
        $callable = /** @scrutinizer ignore-deprecated */ $this->getMockBuilder(\stdClass::class)

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
32
            ->setMethods(['__invoke'])
33
            ->getMock();
34
35
        $callable->method('__invoke')
36
            ->with($actor, static::OPERATION, $context)
37
            ->willReturn(true, false);
38
39
        /** @var RuleInterface $rule */
40
        $rule = new CallableRule($callable);
41
42
        $this->assertTrue($rule->allows($actor, static::OPERATION, $context));
43
        $this->assertFalse($rule->allows($actor, static::OPERATION, $context));
44
    }
45
}
46