testAddPolicyDoesNotThrowException()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Files\Authorization;
6
7
use AbterPhp\Files\Databases\Queries\FileCategoryAuthLoader as AuthLoader;
8
use Casbin\Exceptions\CasbinException;
9
use Casbin\Model\Model;
10
use PHPUnit\Framework\MockObject\MockObject;
11
use PHPUnit\Framework\TestCase;
12
13
class FileCategoryProviderTest extends TestCase
14
{
15
    /** @var FileCategoryProvider */
16
    protected $sut;
17
18
    /** @var AuthLoader|MockObject */
19
    protected $authLoaderMock;
20
21
    public function setUp(): void
22
    {
23
        $this->authLoaderMock = $this->createMock(AuthLoader::class);
24
25
        $this->sut = new FileCategoryProvider($this->authLoaderMock);
26
    }
27
28
    public function testSavePolicyReturnsTrue()
29
    {
30
        $modelStub = $this->createMock(Model::class);
31
32
        $actualResult = $this->sut->savePolicy($modelStub);
33
34
        $this->assertTrue($actualResult);
35
    }
36
37
    public function testAddPolicyDoesNotThrowException()
38
    {
39
        $actualResult = $this->sut->addPolicy('foo', 'bar', []);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $actualResult is correct as $this->sut->addPolicy('foo', 'bar', array()) targeting AbterPhp\Files\Authoriza...ryProvider::addPolicy() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
40
41
        $this->assertNull($actualResult);
42
    }
43
44
    public function testRemovePolicyReturnZero()
45
    {
46
        $actualResult = $this->sut->removePolicy('foo', 'bar', []);
47
48
        $this->assertSame(0, $actualResult);
49
    }
50
51
    public function testRemoveFilterPolicyThrowsCasbinException()
52
    {
53
        $this->expectException(CasbinException::class);
54
55
        $this->sut->removeFilteredPolicy('foo', 'bar', 'baz');
56
    }
57
}
58